Redundant `:($(` in expression printing

#1

Why does Julia add extra :($? For instance:

julia> :(:(:(1+2)))
:($(Expr(:quote, :($(Expr(:quote, :(1 + 2)))))))
0 Likes

#2

The above is technically correct, since this is the expression that would evaluate to the original one — the $(...) syntax interpolates its result, which is constructed using Expr.

Perhaps a more compact way of printing is possible, but I kind of like this one as it shows the full structure.

0 Likes

#3

What do you mean by “full structure”?
I don’t see anything missing from Expr(:quote, Expr(:quote, :(1 + 2))).

0 Likes

#4

You might like the printing of Meta.show_sexpr a bit better:

julia> Meta.show_sexpr( :(:(:(1+2))))
(:quote, (:quote, (:call, :+, 1, 2)))
2 Likes

#5

I think that generally show_unquoted_quote_expr tries to print an expression that “looks like” a canonical form. I agree that here it could be improved here for the Expr blocks. Perhaps open an issue?

1 Like

#6
1 Like