That's because in the case of expressions, we are interested in the AST,
show representation is just an abstraction of that, there is also dump and
xdump:
julia> ex = :(:($x))
:($(Expr(:quote, :($(Expr(:$, :x))))))
julia> Meta.show_sexpr(ex); println()
(:quote, (:$, :x))
julia> dump(ex)
Expr
head: Symbol quote
args: Array(Any,(1,))
1: Expr
head: Symbol $
args: Array(Any,(1,))
1: Symbol x
typ: Any
typ: Any
julia> ex.args[1].args[1] = :y
:y
julia> ex
:($(Expr(:quote, :($(Expr(:$, :y))))))
julia> Meta.show_sexpr(ex); println()
(:quote, (:$, :y))
julia> dump(ex)
Expr
head: Symbol quote
args: Array(Any,(1,))
1: Expr
head: Symbol $
args: Array(Any,(1,))
1: Symbol y
typ: Any
typ: Any
You could overwrite those methods or write your own that prints them the
way you want to.
El domingo, 17 de enero de 2016, 1:50:05 (UTC-6), [email protected]
escribió:
>
> Hi!
>
> Was messing around with exceptions, and trying to see under the hood and
> construct macro expressions.
>
> Eg, Meta.show_sexpr(:(:(+ 1 2))) -> (:quote, (:call, :+, 1, 2))
>
> but how do you build an unquote expression?
>
> Meta.show_sexpr(:(:($(x+5) + 1))) -> (:quote, (:call, :+, (:$, (:call, :+,
> :x, 5)), 1))
>
>
> But Expr(:quote, Expr(:call, :+, Expr(:$, Expr(:call, :+, :x, 5)), 1)) ->
> :($(Expr(:quote, :($(Expr(:$, :(x + 5))) + 1))))
>
> In other words, it's not processing into the appropriate expression, and
> there's some weird intermediate syntax going on.
>
>
> How does one build an unquote expression? I.e, an expression that would
> eval to unquoting a variable?
>