# Differences in these expressions?

**URL:** <https://discourse.julialang.org/t/differences-in-these-expressions/44115>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 2, 2020, 1:57am UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115 "2020-08-02T01:57:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [August 2, 2020, 1:57am UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115/1 "2020-08-02T01:57:38Z")

</div>

When learning metaprogramming in Julia, I am a little bit confusing about these behavior like below

```julia
julia> Meta.show_sexpr(:(:($(1+2))))
(:quote,(:$,(:call,:+,1,2)))

```

```julia
julia> Meta.show_sexpr(:($(1+2)))
3

```

```julia
Julia> Meta.show_sexpr(Expr(:$,:(1+2)))
(:$,(:call,:+,1,2))

```

As in the first case, part of

```julia
:(:($(1+2)))

```

is ( **which should be the same as in the third expression?** )

```julia
:($(1+2))

```

And I expect its behavior is the same as:

```julia
Expr(:$,:(1+2))

```

But it obviously doesn’t support my expectation.According to the manual, it says the construction using Expr() and :() should be the same, but why are they different in such a case?  
Just because the construction **using :() will be default interpolated**

```julia
:($(1+2))

```

But the construction **using Expr() will not be interpolated**?

```julia
Expr(:$,:(1+2))

```

Or any other reasons?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 2, 2020, 2:17am UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115/2 "2020-08-02T02:17:01Z")

</div>

> [@Hawk](#):
>
> According to the manual, it says the construction using Expr() and :() should be the same, but why are they different in such a case?

Which part of the manual? There’s no such guarantee. `:()` is **not** the syntax for creating expressions, it’s the syntax for quoting. There are many other cases where `:()` does not even create `Expr` objects so the two cannot possibly be equivalent.

There’s also no guarentee that there’s a quoting syntax to create all possibly valid expressions.

---

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [August 2, 2020, 2:28am UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115/3 "2020-08-02T02:28:01Z")

</div>

Just the manual said:(In the section [Quoting](https://docs.julialang.org/en/v1/manual/metaprogramming/#Quoting-1))

> The second syntactic purpose of the `:` character is to create expression objects without using the explicit [`Expr`](https://docs.julialang.org/en/v1/base/base/#Core.Expr) constructor. This is referred to as _quoting_ . The `:` character, followed by paired parentheses around a single statement of Julia code, produces an `Expr` object based on the enclosed code

He said that “The `:` character, followed by paired parentheses around a single statement of Julia code, produces an `Expr` object”.  
I don’t know whether the statement is saying :() is equivalent to Expr()?

Or the real problem is that

```julia
$(1+2)

```

isn’t a valid Julia code?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 2, 2020, 2:33am UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115/4 "2020-08-02T02:33:37Z")

</div>

I agree that doc can be confusing, and you are certainly not the first one confused by it. You are certainly welcome to improve it though bear in mind that it also needs to be understandable for people reading it the first time and doesn’t want to worry about all the details yet…

OTOH, I do believe it is correct, in that it more or less implies `:` can be used to create corresponding `Expr` but it doesn’t imply the mapping is complete. In that sense, yes, the reason your expectation break down is that `$(1 + 2)` isn’t a valid expression for you to quote.

---

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [August 2, 2020, 2:39am UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115/5 "2020-08-02T02:39:30Z")

</div>

Yes, especially in the section of metaprogramming which might be very confusing for me, when I first read the manual 😭

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 3, 2020, 12:21pm UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115/6 "2020-08-03T12:21:17Z")

</div>

> [@Hawk](#):
>
> is ( **which should be the same as in the third expression?** )
> 
> ```julia
> :($(1+2))
> 
> ```
> 
> And I expect its behavior is the same as:
> 
> ```julia
> Expr(:$,:(1+2))
> 
> ```

You asked the same question yesterday in

> [@Why they are not equivalent?](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078/):
>
> A try like below: Expr(:$,:(1+2)) == :($(1+2)) gives false. Why they are not equivalent? I suppose the righthand side has been evaluated to 3. Is this the real reason? Thanks!

Please don’t open new topics for the same question, especially if you got an answer (if the answer is not satisfactory, just say so and hopefully others will respond and clarify).

---

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [August 3, 2020, 12:40pm UTC](https://discourse.julialang.org/t/differences-in-these-expressions/44115/7 "2020-08-03T12:40:03Z")

</div>

OK.  
I am sorry to break the rules of community, and I will try my best to understand the manual as far as possible, when I have a confusing question about the explanation in the manual.  
Sorry again!
