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

Unintuitive priority of or? #629

Closed
vcunat opened this issue Sep 2, 2015 · 6 comments
Closed

Unintuitive priority of or? #629

vcunat opened this issue Sep 2, 2015 · 6 comments
Assignees

Comments

@vcunat
Copy link
Member

vcunat commented Sep 2, 2015

A while ago I was taken unawares by the fact that the operator priority is higher for or than for function application. That is strognly against my functional-programming intuition of application always binding the strongest. Example of the current state:

{ truth =
  set.attribute or function param == (set.attribute or function) param;
}

I'm aware that changing such things is not to be taken lightly – maybe in nix-1.10 it might be bearable? (Unless you actually prefer the current priority.)

@vcunat
Copy link
Member Author

vcunat commented Sep 2, 2015

Perhaps there are some good arguments for that decision. One can't find such information in the nix manual... (but the priority order is documented in there clearly)

@shlevy shlevy added the backlog label Apr 1, 2018
vcunat added a commit to NixOS/nixpkgs that referenced this issue Sep 3, 2018
Broken in 62dca7c; the tricky thing is that it depends on nix version.
Explanation: NixOS/nix#629
@vcunat
Copy link
Member Author

vcunat commented Jun 5, 2020

I don't think there's sufficient motivation to keep an open ticket for this 🤷

@vcunat vcunat closed this as completed Jun 5, 2020
@zimbatm
Copy link
Member

zimbatm commented Jun 5, 2020

It belongs on a "language quirks" inventor page :-)

@vcunat
Copy link
Member Author

vcunat commented Jun 5, 2020

😄 the formulation made me recall http://lambda-the-ultimate.org

@roberth
Copy link
Member

roberth commented Dec 10, 2022

I think we could make the parentheses in the third operand semi-mandatory, by emitting a warning if the . or ast node is unparenthesized and occurs in a function application. This check would ideally be done during the parsing, because the ast is too lean (and we probably want to keep it that way).
It's not perfect, but at least we can fix the confusion without breaking compatibility.

ie don't warn for the unambiguous case:

(set.attribute or function) param

EDIT: at first I thought this looked unambiguous, but I've changed my mind:

set.attribute or (function) param

Perhaps there are some good arguments for that decision.

Fwiw, there's no or operator; only the _ . _ or _ ternary operator, with the same priority as _ . _.

@vcunat
Copy link
Member Author

vcunat commented Dec 11, 2022

Sounds like a good idea, from UX perspective at least. I think it will be rare to use or with a function on the right side, so warn-forcing explicit parenthesis in that case should be a low price overall.

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

No branches or pull requests

6 participants