nushell.github.io icon indicating copy to clipboard operation
nushell.github.io copied to clipboard

Update operators.md

Open jesper-olsen opened this issue 11 months ago • 6 comments

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

jesper-olsen avatar Jan 06 '25 16:01 jesper-olsen

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.

fdncred avatar Jan 09 '25 12:01 fdncred

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.

jesper-olsen avatar Jan 09 '25 13:01 jesper-olsen

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.

fdncred avatar Jan 09 '25 13:01 fdncred

Related issue already on https://github.com/nushell/nushell/issues/13675

sholderbach avatar Jan 09 '25 15:01 sholderbach

I thought this issue sounded familiar.

fdncred avatar Jan 09 '25 15:01 fdncred

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"?

NotTheDr01ds avatar Apr 01 '25 18:04 NotTheDr01ds