-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
osutils macros: @unix
, @osx
, etc.
#4233
Comments
It is using a macro to write the bodies of the macros. |
Ah, I see. Yes, that's a bit confusing. The thing I really don't like about this "fake ternary" syntax punning is how brittle it is: julia> @osx? 1 : 2
1
julia> @osx? 1:2
1
julia> @osx? 1 :2
ERROR: wrong number of arguments
julia> @osx? 1: 2
1
julia> @osx?1:2
1
julia> @osx? 1:2
1
julia> @osx?1 :2
ERROR: wrong number of arguments
julia> @osx?1: 2
1
julia> @osx?1 : 2
1
julia> @osx?
ERROR: wrong number of arguments
julia> @osx ? 1 : 2
1
julia> @osx ?1:2
1
julia> @osx ?
ERROR: wrong number of arguments
julia> @osx ? 1 :
ERROR: wrong number of arguments
julia> @osx ? 1
ERROR: assertion failed: :(isa(ex,Expr)) Most of these syntax variations work for actual ternary operator expressions but half of them fail here because this isn't really a ternary operator even though it's supposed to look like one. A couple of alternative options:
I lean towards the last option myself, since it's the simplest and reduces the number of things in base. |
+1 for combining them into one set of macros |
Other than a better error message for that last expression (or allow it), I don't see how the rest are valid -- they look to me like incomplete expressions. |
No kidding they're incomplete. The point is that the REPL doesn't let me finish the input because it has no idea what it's parsing. |
In other words, this "syntax" is absurdly sensitive to whitespace – in particular line breaks confuse the hell out of it. |
You're missing the point that this looks like a ternary operator so the user expects it to behave like one syntactically – but it isn't one at all and doesn't behave like one syntactically at all and instead breaks in all sorts of ways that ternary operators don't. If you just stop trying to make it look cute and make it what it is – individual expressions passed to a macro – then all the confusion goes away. Yes, it looks slightly less pretty, but it's much more usable. |
|
Yes, that's why I proposed it since it actually has the syntax it looks like it has. And that does reduce all of these things to a single macro which is rather nice. |
A few more issues with this, for the record.
In v0.3 julia> @osx? print("A"):print("B")
A In v0.4 julia> @osx?print("!"):print("B")
ERROR: wrong number of arguments
julia> @osx? print("A"):print("B")
A
julia> function f()
println(1)
println(2)
@osx?print("Y"):print("N")
end
ERROR: wrong number of arguments |
OT: the parser is fine with this expression, the error happens later when starting to evaluate it. |
I said this in a different issue but can't find it right now, this fake ternary would be better replaced by a conditional macro |
+1 to |
@vtjnash also suggests the possibility of a |
implements JuliaLang#5892 closes JuliaLang#6674 and JuliaLang#4233
The stuff in base/osutils.jl that implements
strikes me as a bit too cute. It took me a minute screwing around with the syntax to figure out what was even going on with this macro. Cute as the resulting usage may be, this strikes me as an abuse of syntax. If we do keep it, the documentation needs to be improved to include how you actually call these things and ideally, it would tell you the same information when you inevitably use it incorrectly.
Also, why does the implementation do syntax structure checking at run-time? That should be done during macro expansion.
cc: @vtjnash, @loladiro, @johnmyleswhite (people who touched this file).
The text was updated successfully, but these errors were encountered: