# Why they are not equivalent?

**URL:** <https://discourse.julialang.org/t/why-they-are-not-equivalent/44078>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 1, 2020, 9:09am UTC](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078 "2020-08-01T09:09:44Z")\
**Posts on this page:** 6\
**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 1, 2020, 9:09am UTC](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078/1 "2020-08-01T09:09:44Z")

</div>

A try like below:

```julia
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!

---

<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 1, 2020, 9:23am UTC](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078/2 "2020-08-01T09:23:22Z")

</div>

The `$` is special syntax for interpolation:

[https://docs.julialang.org/en/v1/manual/metaprogramming/#man-expression-interpolation-1](https://docs.julialang.org/en/v1/manual/metaprogramming/#man-expression-interpolation-1)

so the RHS is essentially `3`, ie

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

```

---

<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 1, 2020, 9:27am UTC](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078/3 "2020-08-01T09:27:55Z")

</div>

Yes, I suppose it should be the reason. But the lefthand expression’s head is also $, are they different?  
Or what’s **real form of the lefthand expression** like the righthandside **using :() forms**?

---

<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 1, 2020, 9:35am UTC](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078/4 "2020-08-01T09:35:52Z")

</div>

> [@Hawk](#):
>
> But the lefthand expression’s head is also $, are they different?

In that case, you are constructing this and don’t evaluate it. Of course they are different, you can check this by printing:

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

julia> dump(ans)
Expr
  head: Symbol $
  args: Array{Any}((1,))
    1: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol +
        2: Int64 1
        3: Int64 2

```

> [@Hawk](#):
>
> what’s **real form of the lefthand expression** like the righthandside **using :() forms**?

It is not clear what you are trying to do, but perhaps you are looking for

```julia
julia> ex = Meta.quot(Expr(:$, :(1 + 2)))
:($(Expr(:quote, :($(Expr(:$, :(1 + 2)))))))

julia> eval(ex)
3

```

You may also be interested in

[https://docs.julialang.org/en/v1/devdocs/ast/](https://docs.julialang.org/en/v1/devdocs/ast/)

---

<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 1, 2020, 9:40am UTC](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078/5 "2020-08-01T09:40:05Z")

</div>

So the difference is that the lefthand side is just a construction, however the righthand side has been evaluated using interpolation.

---

<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 1, 2020, 9:55am UTC](https://discourse.julialang.org/t/why-they-are-not-equivalent/44078/6 "2020-08-01T09:55:35Z")

</div>

Also note the `Meta.quot`. And technically interpolation is part of the evaluation semantics, so everything is

> [@Hawk](#):
>
> evaluated using interpolation
