-
-
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
RFC: Add new pipe-like operator syntaxes </
, |>>
, etc.
#34340
base: master
Are you sure you want to change the base?
Conversation
Hm, to be honest, not clear to me that this is a high priority thing? At least from the Query.jl side of things I haven't missed it :) But I might be missing something deeper here. I think if it gets added, it should have an implementation with it, otherwise I don't see how one can add consistent functionality to it without type piracy? |
You can use operator names overlapping with julia> module MyModule
*(args...) = foldr(Base.:*, args)
end
Main.MyModule
julia> MyModule.:* === Base.:*
false But yes, I guess I'll open a PR to add |
In #25233 (comment), @StefanKarpinski mentioned that operators like this can be added even though they are technically breaking due to
|
</
, |>>
, etc.
</
, |>>
, etc.</
, |>>
, etc.
|
Why is it confusing? Do you mean it doesn't have |
They're confusing because they don't really visually convey to me what they do, nor are they used by any other system that I'm aware of. |
This seems very syntax-greedy. We often find ourselves in the situation of needing syntax for something and every last bit of available possible syntax is valuable. Why is having this many pipelike operators a good way to spend syntax? Some of them I can see, but all of these? Really? You can't use functions or one of the billion Unicode operators that Julia supports? Some other points from triage: other systems don't seem to support most of these—especially the slash and backslash variants—so this seems to be totally unprecedented operator territory. They're also just visually confusing to parse. This is veering deep in the Perl ASCII salad territory. When someone sees |
#34344 is a PR that only adds the |
My primary motivation was to add one or two operators (say But since the parser allows
But you don't see infix operators in isolation. If you see
As Dijkstra also noted, infix operator is great because you don't have to put parentheses. This is a strong indication that the operation is associative. Usual function call does not indicate this algebraic property.
Yes, it's great that Julia provides Unicode as a fallback option for situation like this. But I do hope that fundamental operations such as composition and opposite composition can be done with ASCII characters.
I think Other than that, I agree that it's impossible to infer the semantics of the operation. But I think it can be said for any less famous infix operators in programming.
I know similar operators If the concern is that |
I don’t have an opinion on this issue, but I thought I would mention that the operators with slashes are strongly suggestive of HTML/XML to me. |
Sure. But when I see |
I think I understand that ASCII syntaxes are real estates that should not be wasted and tweaking syntaxes in general is a one-way street. That's actually why I suggested adding all the combinations. Right now, But, admittedly, this is not exactly the best "fix" in the sense we can be even more cautious. For example, maybe it's better to make consecutive operators without spaces between them a syntax error? Even if we don't use Also, I still would like to add one rightward pipe operator (to be used for opposite the composition operator) and, ideally, another leftward pipe operator that is the flip version of it. How about |
This is pretty interesting. If we want a stronger visual analogy to piping which includes the With
which has a nice symmetry. (There's also It might be good to emphasize again the mathematical point of view which unifies transducers and iterator transforms into a single category with left and right actions JuliaFolds/Transducers.jl#67 (comment). That seems like an important enough observation to justify some kind of syntax eventually. A couple of other thoughts — somehow I find it troubling that |
This patch adds pipe-like operators such as
</
and|>>
(as requested in #25233) etc. All combinations of "heads"<
,<<
,>
, and>>
and "tails"|
,/
and\
are supported.To increase the probability of this PR to be merged, I'd like to avoid implementing any interface in
Base
on top of these syntaxes here. But the motivating example is to have the opposite composition operatorso that one can have
This is useful when you have an interface where using successive
|>
is a natural way to call functions (e.g., Query.jl, Transducers.jl). Then, the pipeline part can be factored out by using the opposite composition operator/>
. For symmetry, it may be useful to define</
to be the usual composition operator. This would give us an ASCII alias of∘
#33573. (Note: the associativity of</
and∘
are different. But composition is associative so I think it's OK.) See discussion started at JuliaFolds/Transducers.jl#67 (comment) for more explanations on the motivation.Another motivating usecase of a pipe-like operator
|>>
is discussed in #25233 and #34344.cc @davidanthoff Maybe you are interested in new operators like this too?