-
-
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
Should there be Infix Macros? #11608
Comments
Interesting question to raise. I agree with the sentiment that it would be good to get rid of the special-casing of Macros don't do dispatch in the same way as functions, and usually with operators the most common usage is extending the base versions with new methods for new package/user types. You don't often see a package introducing and claiming an operator for |
In some sense another special case is |
|
Not much to add, just a +1 for "let's explore whether this is a good idea". |
Another potential use case:
now throws a deprication warning so that you have to write:
A infix macro overload of |
OT. but for this case I would like a easier way to do integer division (if there isn't one now)... |
And I think |
|
And even better julia> ÷
div (generic function with 31 methods) |
Thanks. |
|
@IainNZ Would |
It would be more consistent - I wasn't suggesting |
As someone who generally wishes you couldn't use macros without putting their arguments in parentheses, I'm pretty negative on the idea of infix macros. I think it would often be hard to read complex expressions involving infix macros. What would the following transform into? x = 1.0
y = 0.0 @in@ x == 1.0 ? 1 @in@ 2 : 3 @in@ 4 |
@johnmyleswhite Cases like that are why I always use parenthesis, even with normal operators, even when not necessary in that particular language... (because otherwise, you can confuse yourself or other programmers when the precedence isn't the same... best to always be explicit...) y = ((0.0 @in@ x) == 1.0) ? (1 @in@ 2) : (3 @in@ 4) |
That's a good strategy, but then why not use |
I'm not advocating in-fix macros, just that if they go in, I think the syntax should be |
In this case, for the same reason we write (@johnmyleswhite, I hear your concern about adding things to the language that people have to maintain, etc.. Practically speaking, I'm not sure how well founded that concern is in this case, mainly because of how Julia works: someone interested enough in this would have to spend the time learning how the parser works, and adding the functionality in, and then it would have to go through a comment period, where it's usefulness would have to be clearly demonstrated. I suspect the first step in this is quite a ways off. But if someone were to try it, I'd like to at least see what it looked like.) |
Doesn't the same precedent (I think that's what the complaint is?) argument apply without being macros / with current julia syntax, "what
|
I think we'd just have to have a precedence table for that, and if there were macro versions of operators then we'd probably have the macro versions follow the same precedence as the standard operators? I'm more worried about the extensibility of these. Macros operate on untyped expressions. So is there no way for 2 packages to simultaneously have definitions for the same macro-operator that could be used together unambiguously in a single user code base? This is essentially the situation we're in with |
This issue is purely speculative and not really actionable. The only way forward here would be to develop an actual implementation. I think you will find that much harder to do in practice than it seems. |
It is actionable in the negative. |
In #5571 (around here) it was discussed that if
|>
was defined by a macro, it could be (directly) enhanced by packages,to give people the varios pipeline styles they desire (and perhaps eventually allow it to be deprecated then removed from core).
Now, pipelining isn't for everyone.
Similarly though, tilde is already an infix macro: see #4882
It may be only actually in use in Dataframes.jl -- defined here.
If you look at that defition, you can see it is a macro taking 2 arguments:
lhs
andrhs
We allow the redefining of a section of the unicode operator range as Infix functions -- that is functions of two arguements that can be written between the two arguements.
Not having
~
as a special case would be a good thing -- which means either generalising the mechanism, or removing it.Should we have generally overloadable macro infix operators?
if so, what should the syntax be?
@+
where the+
is anything that is valid as Operator.@+@
.<backtick>+<backtick>
(idk how to write backtic character in markdown, inside a code block)An
The text was updated successfully, but these errors were encountered: