nushell / nushell/nushell.github.io
Are Boolean operators lazy?
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 258
- Forks
- 561
- Avg merge
- 3h 20m
- Merged PRs (30d)
- 15
Description
Hello,
TL;DR: Are the and and or Boolean operators guaranteed to be lazy, so we can document it?
I encountered this bug https://github.com/nushell/nushell/issues/10237 which makes last error out on an empty input instead of returning a null if I understand correctly.
So I have written this workaround:
let filler = if ($text != "") and ($text | split chars | last) == "%" { "%" } else { " " }
This code works without errors for me, so the RHS of the and Boolean operator must not be evaluated / be lazily evaluated.
To put it short, the and operator seems lazy (nu version 0.108.0)
I cannot find it documented in Boolean | Nushell and looking for "lazy" in the documentation does not yield anything related to Booleans.
Is and guaranteed to be lazy in future versions? What about or?
Should we document this behavior?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Boolean documentation page and the referenced Nushell issue 10237. Verify whether and and or are guaranteed to evaluate lazily, then document the confirmed behavior and its implications for the shown example on the appropriate Boolean documentation page.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100