-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Parenthesis Postfix Function Syntax Allowing (x,y)f #38704
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
Comments
It should be noted that this is so unsettling to @ararslan that he hasn't even thrown his customary 👎🏻 on it, but merely put a 😕 on it instead. |
"aesthetic discomfort" was a pointed comment aimed at @ararslan |
I thought it deserved a 😕 given that the issue doesn't actually articulate why one would ever want to do this and what the perceived benefit would be. |
I will point out we have AFAIK exactly 1 post fix operator. I would maybe like some more postfix operators. |
The issue is missing some context from discussions on Slack around issues that result from juxtaposition. One potential benefit is that it feels wrong that |
A less provocative strategy for this issue could have been this: Regardless of whether
|
Because that's how the syntax is documented (https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/#man-numeric-literal-coefficients). If you want to get rid of this syntax, then open an issue about that instead perhaps? |
@KristofferC my syntax issue has nothing to do with integers or floating point numbers.
First method error makes sense. Second method error involves |
I didn't say it did. Read further in the section of the docs I linked:
|
One potential downfall is that |
I did read it and understand that it is where this syntax is documented. I am saying that the behaviour of
I don't want to get rid of the syntax. I want the syntax to mean something intuitive, which is why I opened this issue. |
What would To me this seems like a syntax change that just wants to extend tuple semantics for the sake of expanding them.. |
|
@ararslan It's not surprising that familiar prefix functions like But is the current situation actually intuitive? That Also. I didn't open this issue to unnecessarily propose breaking changes just for fun. The existing syntax surrounding juxtaposition and multiplication is a regular gotcha. It started a discussion on gripes channel about surprising, unintuitive results. e.g.
Trying to resolve these annoying juxtaposition issues naturally arises at the question of the correct behaviour for this syntax. |
@mbauman yes this is definitely breaking. Here's the specific behaviour right now.
So if we follow the spirit of this it creates the cases of Do we have a sense for what would break |
Really not sure if I should share this, but you don't need to change the parser to achieve this behaviour:
|
Lots. Quick and dirty grep; it's pretty shoddy and picks up lots of string interpolations and comments, but a large number of real cases. I didn't see one post-fixed numeric literal, but barely made it through the "B" packages. a1 = sqrt(3)L0.*(cos(π/6), sin(π/6))
p0 = [[cos(θ)L0, sin(θ)L0] for θ = range(0, stop=5π/3, length=6)]
(6x/L^2 - 6x^2/L^3)u0[5] +
C = transpose(F)F
xy'' + (α + 1 - x)y' + ny = 0
@test minutes(s) == (1.0 / 60.0)minutes
return -(nmd/2)*log(2pi)-(1/2)log(det(σ²))-(1/2)*diff'*σ²^(-1)*diff
@test A∧⋆(B) == (A⋅B)pseudoscalar(A)
... |
There are two pieces to this.
Just repeating what I said in the Slack thread:
I think this issue could benefit from more examples of domains that would benefit from postfix (I know there exists stuff in math/category theory, but I am no expert). (1) is one of those things that I wish had been done this way from the start, but it already lowers to |
I like (1), and that wouldn't be breaking. We can always add levels of indirection for folks to opt into. |
Yeah, part of my argument is that postfix can be achieved for specific packages that need it if juxtaposition being extended was "official" and not "clever." Circumventing the issue of forcing postfix calls everywhere. |
I don't like juxtaposition as function call syntax in general, but I agree that juxtaposition of numeric literals is fine to me (since it does save the odd character). I'm happy with the status quo.
You can do that already by only extending One painpoint I see is something like |
It's actually This issue is to unify that with the behaviour of juxtaposition with |
Why does this precedence breaking need to be done by the parser? All the parser does is output the tree I don't really see why Base would need to spend effort making precedence decisions either. If what's being juxtaposed are numbers, then follow the current behavior. Otherwise just throw a method error. I would argue against defining |
Precisely, so each package would make it's own decisions about the order this is done in. From a user perspective, this seems like a horrible idea, since now I have to learn additional precedence rules for each package I want to use because each package is free to define them as they wish, by choosing how to handle each |
Once we define juxtaposition between an operator and any other type we can't have infix operators anymore since we'd have to decide on a precedence in parsing: (2+4)*2 --> (((2+)4)*)2 which, if we removed the |
Yeah that's a good point! We could apply the same restrictions of infix operators as we currently do though. In which case infix operators must explicitly be wrapped in parentheses to count as being juxtaposed (e.g. Though I know there are people who want to use infix operators with juxtaposition to express some mathematical operations. |
@oxinabox that we already have one postfix operator and it is But the linear program, when transposed, If we had postfix notation this would very elegantly be written as This is my attempt at coming up with a realistic example of a postfix function. Incidentally the fact that |
Also, @oxinabox, I think we will get another postfix operator for |
Just like |
Yes, thank you for the correction. It was not correct that What I was trying to appeal to is that the connection between Tuples, and their syntax From the Julia Documentation on Tuples
So the involvement of the parenthetical It's true that parenthesis collect expressions for specifying precedence. In grade school, when we only knew about So, whereas
Again, why should this syntax involve multiplication? To be clear, if juxtaposition between two types really does behave like Is it a breaking change if we lower juxtaposition to it's own function |
Lowering to
Is the proposal to use (2) to make
Those aren't "exceptions" in the same sense, because most of the exceptions are actually syntax errors. Syntax errors are perfectly safe, because there's no risk of giving something the wrong meaning. And
I'd be perfectly happy to remove this case of juxtaposition. |
Potential benefit: better autocompleteIn object oriented programming language you get very easy method discovery with
might expand to suggestions. It isn't quite as powerful as
requires you to go back and add a bracket. But it still gives you one level of autocompletion. That would put it on par with python, which can only give one level since it is not statically typed so autocomplete can not help with the return value. |
If the extra cursor movement is ok, we could also do |
@JeffBezanson a good autocomplete is not something you should need to know/think about. So if you have to move around your cursor and press tab, it isn't really all that useful. It should just come up naturally while you type what you need to type anyway. If you have to do a certain thing, then knowing that certain thing is somewhat equivalent to knowing a |
I don't think being able to tab-complete a function name postfix on its arguments actually makes anything more discoverable given that you don't call it that way. |
@ararslan currently yes, but I thought this was about allowing for this syntax |
As a mathematician working in abstract algebra, specifically group theory. We use right actions all the time, and apply functions from the right; in the computer algebra system GAP (of which I am a developer) we offer the shorthand Despite being used to applying functions such permutations from the right all the time, I am not really in favor of the syntax That's of course just my opinion and purely subjective! The only reason I bring it up is that because people here mentioned that research mathematicians might appreciate it. I am sure some will, but some (like me) won't :-). |
(BTW, we also apply matrices from the right, |
The tab completion is an interesting aspect and I'm glad @timholy gave it it's own issue! @fingolfin that we "apply" matrices on the right or the left is exactly the abstraction I want to emphasize. Matrices are representations of linear programs whose call signature happens to be exactly multiplication, Trying to appeal to a notion that generalizes linear program "calling", i.e., matrices and matrix |
I think as a breaking change, we aren't likely to do this. Further discussion can continue, or be had on discourse. Tab-completion for methodswith will be added in #38791 |
* ?(x, y)TAB completes methods accepting x, y Closes #30052 xref #38704 xref #37993 Co-authored-by: Jameson Nash <[email protected]>
This issue is to discuss the possible advantages and disadvantages for allowing a postfix function call syntax where the function name appears after the closing parenthesis.
i.e.
(x)f
or(x,y)f
I think this notation has merit because it maintains the relationship between parenthesis
()
and function calling.Recall that, by definition, Tuples are an abstraction containing the arguments of a yet unspecified function:
(x,y)
.f(x,y)
gives the syntax to call the functionf
on the tuple of arguments.I propose we extend that intuition to also allow
(x,y)f
to be valid syntax for function calling.Right now it is not valid syntax. Further,
(x)f
is parsed as juxtaposition, so*
. This causesf(x)
to behave completely differently from(x)f
. I don't think that is ideal either.We would have to resolve some ambiguities e.g.
f(x)g
and(f)(g)
.Are there obvious problems with allowing this beyond aesthetic discomfort?
The text was updated successfully, but these errors were encountered: