-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Behavior change in v1.3.0 regarding Symbol in a QuoteNode #34080
Comments
Here is an even simpler example: julia> :(Base.Enums.@enum)
:(#= REPL[12]:1 =# Base.Enums.var"@enum") So, where is that |
This is a bug since the output does not parse:
We should not use But, this should only affect expression printing. Why are you printing expressions instead of using macros or |
I have some code that can parse XSD files and define corresponding data structures in Julia. Doing this on the fly is not necessary since (1) the XSD files don't often change; (2) would cause annoying warnings saying incremental compilation may be broken. So I just print the generated expressions to a .jl file and call it done. I just did some debugging and it is indeed a print issue: 1|debug> n
In #show_sym#371(allow_macroname, , io, sym) at show.jl:990
992 elseif allow_macroname && (sym_str = string(sym); startswith(sym_str, '@'))
993 print(io, '@')
994 show_sym(io, sym_str[2:end])
995 else
>996 print(io, "var", repr(string(sym)))
997 end
998 end Is there a special reason for printing |
Yes; |
To clarify, the exact output in the OP:
is in fact correct. If you want to invoke the macro, you need to wrap that in a |
@JeffBezanson , thanks for your quick response. But I would argue that printing that Base.Enums.var"@enum" A begin
a
b
end to a .jl file, it is not going to run. In v1.2 it didn't print |
The printing with
The expression you want to print is a macro call. So, it should use the But, part of the point of metaprogramming with structured expression objects is to avoid going through text. If you want to generate text, why not just print the strings you want and avoid Exprs entirely? |
Or conversely, if you want to use expressions, why save them as text? Just save them as expressions using |
@JeffBezanson: I really appreciate Expr() since it provides a structured way to generate code instead of playing with strings. But I would also appreciate having the option of decoupling code generation and code evaluation. @StefanKarpinski : So, for those who really need to print expressions into text, it looks like a special treatment is needed for |
That example seems fine, I think. It is printing julia code based on the expression but it doesn't rely on how the expression itself is printed. |
No, no special treatment is needed for
As you can see, it printed perfectly. Using #34081 (or wait until it is on master), I recommend just experimenting with variations of these forms and hopefully it will make sense. |
@bliang26, IIUC, the issue is that the expression you're printing is not a macro call. |
@JeffBezanson, great, #34081 is very helpful. I'll wait for it. |
I have just upgraded to v1.3.0 and I noticed a behavior change regarding
QuoteNode()
. Here is a MWE:And here is what I used to get in v1.2.0:
which is the expected behavior.
My code heavily relies on this to automatically generate custom enum types. Please help. Thanks.
The text was updated successfully, but these errors were encountered: