logical
Logical atoms: Python's boolean operators and truthiness.
Module nu.core.logical.
Logical atoms: Python's boolean operators and truthiness.
Maps Python's boolean operations onto Nu ScalarQueries. Pure compute; no Context effect of their own.
Builtins / operators to cover (Python -> Nu):
and->And,or->Or,not->Notbool(truthiness) ->ToBool
Sorts: all ScalarQuery (Q). And / Or are variadic; Not and
ToBool are unary. logical owns ToBool; cast does not define it.
And / Or semantics: Python's and / or short-circuit and return an
operand (not a bool). Nu short-circuits the same way but always coerces to
bool, so a Nu And / Or yields a plain boolean while leaving the
operands past the deciding one unevaluated. That is what makes them usable
as guards: And(not_empty(x), contains(x)) never runs contains when
x is empty. And yields True over no operands, Or yields
False.
Sentinels: every operand that is actually evaluated is checked; an EMPTY
or INVALID operand collapses the whole query to INVALID (per
nu.lang.sentinels). Short-circuit wins over sentinel poisoning - an
operand that is never evaluated can never poison the result.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| And | scalar_query | And(*children) | The conjunction of its boolean children, each coerced with bool. |
| Not | scalar_query | Not(value) | The negation of its one child. |
| Or | scalar_query | Or(*children) | The disjunction of its boolean children, each coerced with bool. |
| ToBool | scalar_query | ToBool(value) | The truthiness of its one child. |
| bool | core.bool(x) | Coerce x to a Nu Bool term. |
And
The conjunction of its boolean children, each coerced with bool.
And(*children)Path nu.core.And. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity None (0 required).
Arguments
| Name | Type | Default | Meaning |
|---|---|---|---|
*children | the values to conjoin. |
Yields
A plain bool. INVALID when an evaluated child is EMPTY or INVALID.
Notes
- Short-circuits like Python's
and: the first falsy child decides the result and the children after it are never evaluated. This is what letsAndguard - a guard that still runs the thing it is guarding is not a guard. - Short-circuit beats sentinel poisoning: a child that is never evaluated never contributes its sentinel, so
And(False, <INVALID>)isFalse, not INVALID. - No children at all yields True.
Example
nu.run(nu.And(True, True))[0]
nu.run(nu.And(True, False))[0]True
FalseNot
The negation of its one child.
Not(value)Path nu.core.Not. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 1 (1 required).
Arguments
| Name | Type | Default | Meaning |
|---|---|---|---|
value | the value to negate. |
Yields
A plain bool. INVALID when the child is EMPTY or INVALID.
Example
nu.run(nu.Not(True))[0]FalseOr
The disjunction of its boolean children, each coerced with bool.
Or(*children)Path nu.core.Or. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity None (0 required).
Arguments
| Name | Type | Default | Meaning |
|---|---|---|---|
*children | the values to disjoin. |
Yields
A plain bool. INVALID when an evaluated child is EMPTY or INVALID.
Notes
- Short-circuits like Python's
or: the first truthy child decides the result and the children after it are never evaluated. This is what letsOrguard - a guard that still runs the thing it is guarding is not a guard. - Short-circuit beats sentinel poisoning: a child that is never evaluated never contributes its sentinel, so
Or(True, <INVALID>)isTrue, not INVALID. - No children at all yields False.
Example
nu.run(nu.Or(False, True))[0]
nu.run(nu.Or(False, False))[0]True
FalseToBool
The truthiness of its one child.
ToBool(value)Path nu.core.ToBool. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 1 (1 required).
Arguments
| Name | Type | Default | Meaning |
|---|---|---|---|
value | the value to coerce. |
Yields
A plain bool. INVALID when the child is EMPTY or INVALID.
Example
nu.run(nu.core.logical.ToBool(0))[0]Falsebool
Coerce x to a Nu Bool term.
core.bool(x)Path nu.core.bool. Defined on nu.core.logical, bound as a function. Builds object.
Arguments
| Name | Type | Default | Meaning |
|---|---|---|---|
x | object | the value to coerce. |
Yields
A Nu Bool.
Notes
Bool(ToBool(x))in one call: Form-wraps the rawToBoolatom so the result composes like any other Nu term.
Example
nu.run(nu.core.logical.bool(1))[0]True