julia> 1..2 ∪ 3..5
ERROR: syntax: extra token ".." after end of expression
Stacktrace:
[1] top-level scope
@ none:1
That’s a bummer. I was hoping to use this syntax inside a macro expansion, but it doesn’t even parse. What are the alternatives? Any good unicode to recommend?
Yes. Both are the same, both need parentheses, both suck Is there any operator which looks better and whose precedence makes it work without parens? I looked at the operator list, and 1..2 || 3..4 works, but it has other problems.
Is your desired syntax simple enough to edit the text before standard parsing? A macro can take in a String, and such macros have syntactic sugar for non-standard string literals. I’m imagining it’d be written like setop"1..2 ∪ 3..5" and the String changed to "(1:2) ∪ (3:5)" before parseing.
Having a macro that parses differently from regular Julia code would be confusing, but it does seem like the Julia operator precedence is kinda bad here.
Only tangentially related since it doesn’t actually solve the original request, but I’ve been wondering what Julia would look like if it had an operator precedence system like Better operator precedence.
With the exception of the really common operators that have the same precedence in every language, I think that code is more readable with parentheses than without.
(My editor is colouring matching parentheses, which helps a lot for readability. But I also liked them before it had that feature.)
Conversely, I think a language that allowed the user to remove parentheses by re-defining the order of precedence would be very hard to read for me.