Skip to content

Conversation

@jesper-olsen
Copy link
Contributor

logical not - higher precedence than and/xor/or, comparison.

logical not - higher precedence than and/xor/or, comparison.
@fdncred
Copy link
Contributor

fdncred commented Jan 9, 2025

Either I'm not following what this PR is supposed to do, or it's just not right. If you do help operators | sort-by precedence -r the order is correct in our current documentation.

@jesper-olsen
Copy link
Contributor Author

Take the expression "not true and false"

If "not" has lower precedence than "and" then it is equivalent to

not (true and false) = not false = true

if "not" has higher precedence than and, then it it is equivalent to

(not true) and false = false and false = false

The shell - like most other languages - implements the latter case. So the documentation
is wrong. "not" has the highest precedence of all the boolean operators.

@fdncred
Copy link
Contributor

fdncred commented Jan 9, 2025

ok, but then our help operators command and code that generates it must be wrong too. I'm not sure if 0 was hard coded for not or if it is system generated. I haven't looked.

@sholderbach
Copy link
Member

Related issue already on nushell/nushell#13675

@fdncred
Copy link
Contributor

fdncred commented Jan 9, 2025

I thought this issue sounded familiar.

@NotTheDr01ds
Copy link
Contributor

For some reason I thought this has been merged already - I checked last week and must have missed it still being open.

@jesper-olsen The operator precedence has changed slightly in 0.103, and it looks like your update needs an update. Can you move "Logical not" directly above "Logical and"?

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.

4 participants