# Expr malforming in Julia v 0.7

**URL:** <https://discourse.julialang.org/t/expr-malforming-in-julia-v-0-7/10393>\
**Category:** General Usage\
**Created:** [April 17, 2018, 4:34pm UTC](https://discourse.julialang.org/t/expr-malforming-in-julia-v-0-7/10393 "2018-04-17T16:34:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [April 17, 2018, 4:34pm UTC](https://discourse.julialang.org/t/expr-malforming-in-julia-v-0-7/10393/1 "2018-04-17T16:34:05Z")

</div>

Hi fellows

This is what happens

```nohighlight
julia> Expr(:macrocall,Symbol("@m"),:(:x),:y)
:(@m y)

```

I was expecting  
☹@m :x y)

Is this a bug?  
Thanks

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 17, 2018, 5:52pm UTC](https://discourse.julialang.org/t/expr-malforming-in-julia-v-0-7/10393/2 "2018-04-17T17:52:56Z")

</div>

`dump` shows that macro calls are actually parsed with an extra first argument which holds the current line number:

```julia
julia> dump(:(@foo x))
Expr
  head: Symbol macrocall
  args: Array{Any}((3,))
    1: Symbol @foo
    2: LineNumberNode
      line: Int64 1
      file: Symbol REPL[1]
    3: Symbol x
  typ: Any

```

so it looks like your `:x` is taking the place of that LineNumberNode. I’m not sure what the recommended practice is for constructing `:macrocall` expressions manually, but it looks like you can provide that argument yourself:

```julia
julia> Expr(:macrocall, Symbol("@m"), LineNumberNode(0), :x, :y)
:(#= line 0 =# @m x y)

```

or let Julia do the parsing for you:

```julia
julia> :(@m $(:x) $(:y))
:(#= REPL[11]:1 =# @m x y)

```

---

<div class="post-metadata">

**Author:** ![NaOH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naoh/32/5632_2.png) [@NaOH](https://discourse.julialang.org/u/NaOH)\
**Post date:** [April 17, 2018, 8:03pm UTC](https://discourse.julialang.org/t/expr-malforming-in-julia-v-0-7/10393/3 "2018-04-17T20:03:57Z")

</div>

You need to use `Meta.quot`:

```julia
julia> :(@m $(Meta.quot(:x)) y)
:(@m :x y)

julia> Expr(:macrocall, Symbol("@m"), Meta.quot(:x), :y)
:(@m :x y)

```

See:

- [metaprogramming - How to interpolate a symbol as a Symbol in a Julia Expr? - Stack Overflow](https://stackoverflow.com/questions/48272986/how-to-interpolate-a-symbol-as-a-symbol-in-a-julia-expr/48276355#48276355)

---

<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:** [April 17, 2018, 8:10pm UTC](https://discourse.julialang.org/t/expr-malforming-in-julia-v-0-7/10393/4 "2018-04-17T20:10:58Z")

</div>

This is not the issue. (the first reply already answered it)

---

<div class="post-metadata">

**Author:** ![NaOH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naoh/32/5632_2.png) [@NaOH](https://discourse.julialang.org/u/NaOH)\
**Post date:** [April 17, 2018, 9:03pm UTC](https://discourse.julialang.org/t/expr-malforming-in-julia-v-0-7/10393/5 "2018-04-17T21:03:27Z")

</div>

Ah, I see I was on 0.6.x, this breaking change is confusing because it is undocumented, just barely mentioned in NEWS, the only example is misleading, since it doesn’t need to be a `LineNumberNode` and one con not dispatch a macro on that:

> All macros receive an extra argument ` __source__ ::LineNumberNode` which describes the parser location in the source file for the `@` of the macro call. It can be accessed as a normal argument variable in the body of the macro. This is implemented by inserting an extra leading argument into the `Expr(:macrocall, :@name, LineNumberNode(...), args...)` surface syntax. (#21746)

This _well formed_ ekpression, looks nasty 😮 IMHO

```julia
julia> macro m(x, y) :($x, $y) end
@m (macro with 1 method)

julia> y = 5
5

julia> Expr(:macrocall, Symbol("@m"), rand(10), :(:x), :y)
:(@m :x y)

julia> eval(ans)
(:x, 5)

```

What I meant was that redits would still need to use `quot` or wrap in `:(...)` in order to return the desired output, also wouldn’t `@ __LINE__ ` be a better suggestion then (in this case it simply returns an int)?

We need to pass the line number node (or just anything) explicitly when constructing the expression manually yet it is inserted automatically when parsed? The metaprogramming API is getting real messy for my brain ☹

```julia
julia> Expr(:macrocall, Symbol("@m"), @ __LINE__ , :(:x), :y)
:(@m :x y)

julia> dump(ans)
Expr
  head: Symbol macrocall
  args: Array{Any}((4,))
    1: Symbol @m
    2: Int64 1
    3: QuoteNode
      value: Symbol x
    4: Symbol y
  typ: Any

```
