-
-
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
Syntax for non-standard identifiers #32408
Conversation
Ugh, tests are failing due to a somewhat dubious Symbol hack in |
Maybe it's time to add:
🎉 |
🎉 ... wait, what :-) That's a neat idea I think we just need a better name for it: when used in a block of code, it doesn't produce a (quoted) Symbol, but rather an identifier [edit: yes, an unquoted symbol is an identifier. But I was really expecting the quoted version there]. So we could have |
Agreed; |
I tried searching github for this and it turns out the RCall defines It seems @simonbyrne added this in JuliaInterop/RCall.jl#71 (comment) |
8862925
to
8be46c4
Compare
|
I think the look of julia> @macroexpand @info "msg" x=1 y=2
quote
#= logging.jl:305 =#
var"#25#level" = Base.CoreLogging.Info
#= logging.jl:306 =#
var"#26#std_level" = Base.CoreLogging.convert(Base.CoreLogging.LogLevel, var"#25#level")
#= logging.jl:307 =#
if var"#26#std_level" >= Base.CoreLogging.getindex(Base.CoreLogging._min_enabled_level)
#= logging.jl:308 =#
var"#27#group" = $(QuoteNode("REPL[23]"))
#= logging.jl:309 =#
var"#28#_module" = Main
#= logging.jl:310 =#
var"#29#logger" = Base.CoreLogging.current_logger_for_env(var"#26#std_level", var"#27#group", var"#28#_module")
#= logging.jl:311 =#
if !(var"#29#logger" === Base.CoreLogging.nothing)
#= logging.jl:312 =#
... etc etc |
Not sure if this matters but e.g.
is currently a syntax error and this gets printed from macro expansions. |
@KristofferC oh good catch. This particular case is easily fixed in the parser; not ideal but I think acceptable given that |
I seem to recall that there are some edge cases where it acts a little unexpectedly. The only one I can think of at the moment is when it is used after a julia> macro var_str(str)
esc(Symbol(str))
end
@var_str (macro with 1 method)
julia> x = 1+2im
1 + 2im
julia> x.im
2
julia> x.var"im"
ERROR: LoadError: type Complex has no field @var_str
Stacktrace:
[1] getproperty(::Any, ::Symbol) at ./sysimg.jl:18
in expression starting at REPL[4]:1 |
But wouldn't you have to write |
That would be True, without parser support |
I've added some parser support to fix the And there I was, thinking it would be a guilty pleasure to tackle an easy "good first issue" like #32354 and get it sorted out within the hour :-) |
1fcfcc0
to
947efbc
Compare
Good example @simonbyrne. I think I've got most of the cases in the parser sorted out now. For the Taken together, I think it might be better to declare that |
Makes sense; we can just add one case to |
We could try to find a non-breaking syntax for this (i.e. something that's currently an error). One option is |
Agreed, that will be a lot cleaner.
Ok that's an interesting idea. I wouldn't want to steal useful syntax for this but |
Perhaps something that is really non-breaking like Jeff’s |
Yes that's a natural consequence of the way the parser works. Good point. So comparing two alternatives for unquoted / quoted symbols:
The second is a bit double-negative-y, not backward compatible and less natural in the parser. On the plus side it gives a neat syntax for quoted symbol literals and an uglier syntax for funky variable names. |
Additional considerations which are kind of subjective:
Regarding breakingness of julia> x = "funky"; :$x
ERROR: syntax: extra token "x" after end of expression
julia> x = "funky"; :$(x)
ERROR: MethodError: objects of type Symbol are not callable So we don't really even have a referential transparency type of situation here—it would only break the literal use of |
I share the concern that |
I tried out
We don't get a very natural way to write quoted symbol literals with it;
Would it be a problem for the parser to eagerly interpolate |
Well, I continue to make a mess here, but I'll rebase all that rubbish away once the design converges. As of now, the parser changes include two modifications to
Subjectively I think these are the least surprising syntaxes which have been proposed so far in this thread. |
I'm not a big fan of |
I think this commit broke the following:
Any other variable name besides In any case surely no important package has the bad luck of triggering such an obscure bug :) |
Good catch, though I'm not sure why you refer to In any case we do have a problem:
Looking at the parser code I think this particular case can be fixed (thankfully we don't support arbitrary atoms in string interpolation syntax). Your example hits the |
Ah, the error you're seeing in
|
So there's three problems here:
|
Ok, I believe I've got a fix for the |
Awesome, @c42f, thanks for taking a quick look sorry to throw you off a bit with my alternate example! |
This is proving a bit more problematic than expected. Perhaps we got a little overeager and revert? |
Thanks @marius311 for the quick reporting. It turned out that your example was also an important bug. I was confused because cmd interpolations are parsed quite differently from string interpolations. @StefanKarpinski I think all the problems we know about should now be fixed in #32948 (awaiting CI) so I'd like to see how that pans out. This did have a lot more fallout than anticipated 😬 |
Yes, if that's the last of it then we can proceed. |
DynamicPolynomials.jl fails to precompile on Julia master - perhaps due to this PR? Please see JuliaAlgebra/DynamicPolynomials.jl#50 (comment) |
* unify interfaces * update screen after interact * add minor comment * add version check * update docker * revert to juali v1.2 due to https://github.com/JuliaLang/julia/pull/32408\#issuecomment-522168938 * update README
* unify interfaces * update screen after interact * add minor comment * add version check * update docker * revert to juali v1.2 due to https://github.com/JuliaLang/julia/pull/32408\#issuecomment-522168938 * update README
Introduce syntax for non-standard identifiers. Features:
.
as an identifier character, XRef Calling R functions with keyword argumets that have attributes JuliaInterop/RCall.jl#71 (comment))Various syntax choices were explored (see below), with
var"ident"
currently chosen. Though this has the familiar visual form of a string macro, special parser support was required to make it valid in every context where a normal identifier is allowed. Therefore, this is technically a breaking change. However, the use here has exactly the same semantics as the use in RCall which is the only package I could find on github which defines@var_str
.show
has been changed to use this syntax as necessary when printing expressions:var"@ident"
rather than as a macro call@ident
.var"#89#err"
rather than the bare#89#err