Skip to content
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

feat: power operator with right associativity #4125

Merged
merged 9 commits into from
Jun 24, 2024
Merged

feat: power operator with right associativity #4125

merged 9 commits into from
Jun 24, 2024

Conversation

aljazerzen
Copy link
Member

@aljazerzen aljazerzen commented Jan 24, 2024

@max-sixty here is the right-asoc code

@max-sixty
Copy link
Member

max-sixty commented Jan 24, 2024

Great! I'll take it from here. Currently on my list after completing prql fmt

@max-sixty max-sixty marked this pull request as ready for review June 22, 2024 22:13
@max-sixty
Copy link
Member

@aljazerzen although I had to fix a few things, and the order of math.pow is reveresed, this was actually very close already.

So I think ready to merge, have a glance if you can

max-sixty added a commit to max-sixty/prql that referenced this pull request Jun 22, 2024
As an exhaust from PRQL#4125; seems to be a small improvement in organization; but not a strong view if others disagree?
Copy link
Member Author

@aljazerzen aljazerzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, it looks ready to be merged.

Comment on lines +225 to +234
// For the power operator, we need to reverse the order, since `math.pow a
// b` is equivalent to `b ** a`. (but for example `sub a b` is equivalent to
// `a - b`).
//
// (I think this is the most globally consistent approach, since final
// arguments should be the "data", which in the case of `pow` would be the
// base; but it's not perfect, we could change it...)
let (left, right) = match op {
ast::BinOp::Pow => (right, left),
_ => (left, right),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting.

We should probably apply this to other non-commutative operators, std.sub for example:

5 - 1 ~> std.sub 1 5

This would be handy in a few places, such as [5, 10, 3] | map (std.sub 1) ~> [4, 9, 2].

It is a bit confusing and a potential source of bugs. The good news is that it would not be noticed in the simple case of using operators, but only when the functions directly. This would probably be done by more experienced users, who might appreciate functional composability of the "reverse importance order" of arguments.

So, ATM, I'm leaning in direction of "swaping the arguments of all bin op functions".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, ATM, I'm leaning in direction of "swaping the arguments of all bin op functions".

Weirdly I just saw this, sorry.

I think that makes sense actually! I agree it won't make much difference to most but it is more correct...

@aljazerzen
Copy link
Member Author

aljazerzen commented Jun 24, 2024

(I cannot approve because I opened the PR, but I am Aljaž Mur Eržen, and I do approve of this PR)

@max-sixty max-sixty merged commit e0e719b into main Jun 24, 2024
37 checks passed
@max-sixty max-sixty deleted the right-asoc branch June 24, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants