# Meta.parse supports interpolation?

**URL:** https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677
**Category:** New to Julia
**Tags:** question
**Created:** [August 10, 2020, 12:30pm UTC](https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677 "2020-08-10T12:30:08Z")
**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 10, 2020, 12:30pm UTC](https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677/1 "2020-08-10T12:30:08Z")

</div>

It is confusing for me when I use Meta.parse() function as:

```julia
Julia> x = 2
Julia> Meta.parse(":(:(v = $x))")
:($(Expr(:quote,:($(Expr(quote,:(v = 2)))))))

```

In general, an interpolation with single $ in :(:($x)) should not interpolate the value of x (which is 2 in the above example).  
Since the manual doesn’t mention the case, is this rule special to Meta.parse() function?

---

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [August 10, 2020, 12:51pm UTC](https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677/2 "2020-08-10T12:51:32Z")

</div>

It’s just doing string interpolation before Meta.parse is called at all, and doesn’t care what the string contains:

```julia
julia> x = 2;

julia> ":(:( :) v = $x )])" # nonsense
":(:( :) v = 2 )])"

julia> Meta.parse(ans)
ERROR: Base.Meta.ParseError("missing comma or ) in argument list")

```

---

<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 10, 2020, 1:00pm UTC](https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677/3 "2020-08-10T13:00:10Z")

</div>

Oh, you are right, I have totally forgotten the string interpolation!

---

<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 10, 2020, 2:02pm UTC](https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677/4 "2020-08-10T14:02:59Z")

</div>

By the way, is there any method to use Meta.parse to parse such form as:

```julia
":(:(v = $x))"

```

to see how Julia transform into internal AST form?

---

<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 10, 2020, 2:50pm UTC](https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677/5 "2020-08-10T14:50:11Z")

</div>

The issue is on string, so you just need to produce the correct string. You can escape `$` with `\$`.

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [August 10, 2020, 4:35pm UTC](https://discourse.julialang.org/t/meta-parse-supports-interpolation/44677/6 "2020-08-10T16:35:03Z")

</div>

You might also be interested in the `Meta.@dump` macro, which prints the AST you give it, so you could do e.g. `Meta.@dump :(v = $x)` to inspect the AST. If you want to know how these are actually generated internally, I’m afraid, you will have to [learn Lisp](https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm).
