Skip to content

Are Boolean operators lazy? #2072

@numero-744

Description

@numero-744

Hello,

TL;DR: Are the and and or Boolean operators guaranteed to be lazy, so we can document it?


I encountered this bug nushell/nushell#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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions