# How to show the interpolated expression in metaprogramming

**URL:** <https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060>\
**Category:** New to Julia\
**Created:** [February 12, 2017, 12:46pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060 "2017-02-12T12:46:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [February 12, 2017, 12:46pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/1 "2017-02-12T12:46:00Z")

</div>

Here is an example given by the [docs](http://docs.julialang.org/en/stable/manual/metaprogramming/#code-generation).

```julia
for op = (:+, :*, :&, :|, :$)
  @eval ($op)(a,b,c) = ($op)(($op)(a,b),c)
end

```

I am using ASTInterpreter to step through and trying to see which `op` is being defined. But errors are thrown when I typed either

```julia
`op 

```

or

```julia
`$op 

```

How could I see the expression `op` in debugger? Thanks!!

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [February 12, 2017, 1:28pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/2 "2017-02-12T13:28:47Z")

</div>

Not sure about the debugger, but in the ordinary REPL you can do:

```julia
for op = (:+, :*, :&, :|, :$)
    @eval println($op)
end

```

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [February 12, 2017, 1:50pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/3 "2017-02-12T13:50:13Z")

</div>

Thanks for the comments. Unfortunately, it doesn’t work. Here is the error:

```julia
1|julia > println($op)
ERROR: UndefVarError: op not defined
 in _step_expr(::ASTInterpreter.Interpreter) at /home/chobbes/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl:653
 in step_expr at /home/chobbes/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl:666 [inlined]
 in #finish!#81(::Bool, ::Bool, ::Function, ::ASTInterpreter.Interpreter) at /home/chobbes/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl:1720
 in eval_in_interp(::ASTInterpreter.Interpreter, ::Expr, ::JuliaParser.Tokens.SourceExpr, ::String) at /home/chobbes/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl:1298
 in eval_code(::ASTInterpreter.InterpreterState, ::String) at /home/chobbes/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl:1529
 in (::ASTInterpreter.##72#78{ASTInterpreter.InterpreterState,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at /home/chobbes/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl:1654
 in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at ./LineEdit.jl:1579
 in RunDebugREPL(::ASTInterpreter.Interpreter) at /home/chobbes/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl:1693

```

Apparently, interpolation doesn’t work this way in debugger.

I think if `println($op) works, `$op should have worked too.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [February 13, 2017, 2:53pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/4 "2017-02-13T14:53:14Z")

</div>

Bump.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [February 14, 2017, 2:56pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/5 "2017-02-14T14:56:50Z")

</div>

Bump again. Btw, could this be something missing from the current debugger? A bug??

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [February 15, 2017, 3:28pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/6 "2017-02-15T15:28:12Z")

</div>

Metaprogramming happens at parse time, so ASTInterpreter doesn’t have access to it. The easiest way to do that is to put the macro body in a separate function and manually call that on the expression you want to debug.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [February 15, 2017, 3:49pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/7 "2017-02-15T15:49:11Z")

</div>

Thanks for the explanation. Indeed, ASTInterpreter can’t see anything happened in the phase of metaprogramming. No doubt at all. But it’s kind of counter-intuitive since one expects to be able to see the value of every single variable using a debugger, especially when what you’re doing is not debugging your own code but trying to use debugger to step through some other’s code (sometimes it’s a massive package). But my thought may be not very reasonable.

But anyhow I really appreciate your comments!

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [February 15, 2017, 3:54pm UTC](https://discourse.julialang.org/t/how-to-show-the-interpolated-expression-in-metaprogramming/2060/8 "2017-02-15T15:54:20Z")

</div>

Here is another thing I come across frequently - when I use back-tick to show the value of some variables, I got the correct value, but wrapped by `Core.Box()`. For example, I expect ```a return me the value of `a`. But what is returned is something like `Core.Box(a)`. Is this something normal?

I know you’re busy with 0.6. So don’t bother to answer me if you’re hectic. Thanks.
