# Interpolate @show macro

**URL:** https://discourse.julialang.org/t/interpolate-show-macro/71858
**Category:** General Usage
**Tags:** macros, interpolations
**Created:** [November 21, 2021, 11:48am UTC](https://discourse.julialang.org/t/interpolate-show-macro/71858 "2021-11-21T11:48:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)
#### Post date: [November 21, 2021, 11:48am UTC](https://discourse.julialang.org/t/interpolate-show-macro/71858/1 "2021-11-21T11:48:03Z")

</div>

I want to interpolate the @show macro function.

For example.  
I define a function

```julia
f(x) = x + 1

```

I want to see the behavior for different inputs:

```julia
julia> [@show f(x) for x = 1:3];
f(x) = 2
f(x) = 3
f(x) = 4

```

But what I really wanted to see is:

```julia
f(1) = 2
f(2) = 3
f(3) = 4

```

**Trials**  
I tried to interpolate but:

```julia
julia> [@show f($x) for x = 1:3];
ERROR: syntax: "$" expression outside quote around show.jl:955
Stacktrace:
 [1] top-level scope
   @ REPL[186]:1

```

Then I tried quoting the expression but:

```julia
julia> [@show f(:($x)) for x=1:3];
f($(Expr(:quote, :($(Expr(:$, :x)))))) = 2
f($(Expr(:quote, :($(Expr(:$, :x)))))) = 3
f($(Expr(:quote, :($(Expr(:$, :x)))))) = 4

```

although

```julia
julia> [println("f($(:($x)))") for x=1:3];
f(1)
f(2)
f(3)

```

Any suggestions ?

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [November 21, 2021, 3:17pm UTC](https://discourse.julialang.org/t/interpolate-show-macro/71858/2 "2021-11-21T15:17:05Z")

</div>

```julia
julia> f(x) = x + 1
f (generic function with 1 method)

julia> [@eval(@show(f($x))) for x = 1:3];
f(1) = 2
f(2) = 3
f(3) = 4

```

---

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [November 21, 2021, 3:55pm UTC](https://discourse.julialang.org/t/interpolate-show-macro/71858/3 "2021-11-21T15:55:41Z")

</div>

On my phone so can’t easily check but does something like

```julia
map(x-> @show f(x), collect(1:3))

```

Work?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [November 21, 2021, 4:30pm UTC](https://discourse.julialang.org/t/interpolate-show-macro/71858/4 "2021-11-21T16:30:16Z")

</div>

the things you tried didn’t work because `@show` is a macro and `print()` takes the string after interpolation. Essentially, `@show` sees the expression itself, so if you have `f(x)`, all `@show` can see is something like:

```julia
julia> Meta.@dump f(x)
Expr
  head: Symbol call
  args: Array{Any}((2,))
    1: Symbol f
    2: Symbol x

```

and it would simply print out this expression for you and print the result:

```julia
julia> @macroexpand @show f(x)
quote
    Base.println("f(x) = ", Base.repr(begin
                #= show.jl:1040 =#
                local var"#14#value" = f(x)
            end))
    var"#14#value"
end

```

it’s possible to make `@show` “understand” `$` just like `@btime`, but it will be manual work because essentially `$` is just another node in expression itself:

```julia

julia> Meta.@dump f($x)
Expr
  head: Symbol call
  args: Array{Any}((2,))
    1: Symbol f
    2: Expr
      head: Symbol $
      args: Array{Any}((1,))
        1: Symbol x

```

---

<div class="post-metadata">

### Author: ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)
#### Post date: [November 21, 2021, 4:36pm UTC](https://discourse.julialang.org/t/interpolate-show-macro/71858/5 "2021-11-21T16:36:29Z")

</div>

didn’t work for me:

```julia
julia> map(x-> @show f(x), collect(1:3))
ERROR: MethodError: no method matching (::var"#5#6")()
Closest candidates are:
  (::var"#5#6")(::Any) at REPL[5]:1
Stacktrace:
 [1] map(f::var"#5#6")
   @ Base ./abstractarray.jl:2382
 [2] top-level scope
   @ REPL[5]:1

```

But `[@eval @show f($x) for x=1:3]` worked nicely. thanks! Also thanks for the explanation.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [November 21, 2021, 4:46pm UTC](https://discourse.julialang.org/t/interpolate-show-macro/71858/6 "2021-11-21T16:46:31Z")

</div>

> [@filchristou](#):
>
> didn’t work for me:

Macros are greedy, you may need parentheses to let them understand where they have to stop parsing, as I did above:

```julia
julia> map(x-> @show(f(x)), collect(1:3))
f(x) = 2
f(x) = 3
f(x) = 4
3-element Vector{Int64}:
 2
 3
 4

```

Of course, changing comprehension with `map` doesn’t change much in terms of what `@show` sees.
