I was messing around with how the syntax for the hexadecimal prefix works while thinking about #15731 and I found something entertaining:
julia> 0xenomorph
ERROR: UndefVarError: nomorph not defined
julia> xenomorph = 1
1
julia> 0xenomorph
ERROR: UndefVarError: nomorph not defined
julia> nomorph = 2
2
julia> 0xenomorph
28
julia> 0xgnomorph
ERROR: syntax: malformed expression
julia> 0xefnomorph
478
Maybe we should disallow juxtaposition with hexadecimals? Seems like it will just lead to confusion.
My favorite part is that the syntax coloring in github gets it exactly right :P
Syntax highlighting makes it obvious what is going on. In the REPL however it isn't very clear.
The solution is clear: Add syntax highlighting to the REPL.
I agree that adding syntax highlighting to the REPL would be great and would solve this issue. For this issue however I slightly lean towards disallowing juxtaposed hexadecimals as it avoids any potential confusion when syntax highlighting is unavailable.
+1 to disallowing juxtaposed hexadecimals. I see no mathematical precedent
for that, and it seems highly confusing that the matter of where the
literal ends and the next symbol begins depends on which is the first
character after f in the alphabet.
If we're disallowing juxtaposed hexadecimals we probably also want to do the same for binary and octals
julia> xep = 3
3
julia> 0xep0xep
42.0
julia> b0 = 2
2
julia> 0b1b0
2
julia> o0 = 3
3
julia> 0o1o0
3
The solution is clear: Add syntax highlighting to the REPL.
Looks like the syntax highlighting isn't quite right for the second last example. I believe it should highlight 0x
and not just 0
:
julia> 0x
ERROR: syntax: invalid numeric constant "0x"
julia> 0xg
ERROR: syntax: invalid numeric constant "0x"
julia> g = 1
1
julia> 0xg
ERROR: syntax: invalid numeric constant "0x"
julia> xg = 1
1
julia> 0xg
ERROR: syntax: invalid numeric constant "0x"
Most helpful comment
+1 to disallowing juxtaposed hexadecimals. I see no mathematical precedent
for that, and it seems highly confusing that the matter of where the
literal ends and the next symbol begins depends on which is the first
character after f in the alphabet.