nustack
ReferenceCore

nu.core

Atom interactions on host values: arithmetic, logical, comparison, cast, reduction, transform, iteration, access, reflection, repr, sentinel, conditional, dynamic, reactive, io, bitwise, literal. One group per source file in nu/core/.

from nu import Add (flat-exported); dotted equivalent from nu.core.arithmetic import Add.

Literal

from nu import Literal

NameSortSignatureEffectMeaning
LiteralScalarQueryLiteral(value)pureconstant leaf - holds and yields a value

Arithmetic

from nu import Add, Sub, Mul, MatMul, Div, FloorDiv, Mod, Pow, Neg, Pos, Abs, DivMod, Round

NameSortSignatureEffectMeaning
AddScalarQueryAdd(*operands)puresum of children (commutative, associative, variadic)
SubScalarQuerySub(left, right)pureleft - right
MulScalarQueryMul(*operands)pureproduct of children (commutative, associative, variadic)
MatMulScalarQueryMatMul(left, right)pureleft @ right
DivScalarQueryDiv(left, right)pureleft / right (true division)
FloorDivScalarQueryFloorDiv(left, right)pureleft // right
ModScalarQueryMod(left, right)pureleft % right
PowScalarQueryPow(left, right)pureleft ** right
NegScalarQueryNeg(operand)pure-operand
PosScalarQueryPos(operand)pure+operand
AbsScalarQueryAbs(operand)pureabs(operand)
DivModScalarQueryDivMod(left, right)pure(quotient, remainder) pair
RoundScalarQueryRound(value, ndigits=None)pureround(value[, ndigits])

Bitwise

from nu import BitAnd, BitOr, BitXor, BitNot, LShift, RShift

NameSortSignatureEffectMeaning
BitAndScalarQueryBitAnd(*operands)purebitwise AND of children (commutative, associative, variadic)
BitOrScalarQueryBitOr(*operands)purebitwise OR of children (commutative, associative, variadic)
BitXorScalarQueryBitXor(*operands)purebitwise XOR of children (commutative, associative, variadic)
BitNotScalarQueryBitNot(operand)pure~operand
LShiftScalarQueryLShift(left, right)pureleft << right
RShiftScalarQueryRShift(left, right)pureleft >> right

Cast

from nu import ToInt, ToFloat, ToComplex, ToStr, ToBytes, ToByteArray, ToList, ToTuple, ToSet, ToFrozenSet, ToDict

Scalar casts are evaluable now; the collection constructors are declared structural stubs pending the stream/fabric runtime. ToBool (truthiness) lives in logical, not here.

NameSortSignatureEffectMeaning
ToIntScalarQueryToInt(value, base=None)pureint(value[, base])
ToFloatScalarQueryToFloat(operand)purefloat(operand)
ToComplexScalarQueryToComplex(real, imag=None)purecomplex(real[, imag])
ToStrScalarQueryToStr(operand)purestr(operand)
ToBytesScalarQueryToBytes(value, encoding=None)purebytes(value[, encoding])
ToByteArrayScalarQueryToByteArray(value, encoding=None)purebytearray(value[, encoding])
ToListScalarQueryToList(iterable)purelist(iterable) - structural stub
ToTupleScalarQueryToTuple(iterable)puretuple(iterable) - structural stub
ToSetScalarQueryToSet(iterable)pureset(iterable) - structural stub
ToFrozenSetScalarQueryToFrozenSet(iterable)purefrozenset(iterable) - structural stub
ToDictScalarQueryToDict(pairs)puredict(pairs) - structural stub

Comparison

from nu import Eq, Ne, Lt, Gt, Le, Ge, Is

NameSortSignatureEffectMeaning
EqScalarQueryEq(left, right)pureleft == right (commutative)
NeScalarQueryNe(left, right)pureleft != right (commutative)
LtScalarQueryLt(left, right)pureleft < right
GtScalarQueryGt(left, right)pureleft > right
LeScalarQueryLe(left, right)pureleft <= right
GeScalarQueryGe(left, right)pureleft >= right
IsScalarQueryIs(left, right)pureleft is right (commutative)

Conditional

from nu import If, Switch

Value-yielding branch selection - the Query siblings to the mutating IfDo / SwitchDo in nu.flows.control.

NameSortSignatureEffectMeaning
IfScalarQueryIf(cond, then, else_)pureyield then if cond truthy, else else_ (short-circuits)
SwitchScalarQuerySwitch(selector, cases, default=None)pureyield the value keyed by matching selector, else default

Dynamic

from nu import Eval, Compile, Globals, Locals, Exec

Eval / Compile fold purely over operand values. Globals / Locals / Exec are escape hatches into the live host interpreter namespace, bypassing the Context entirely.

NameSortSignatureEffectMeaning
EvalScalarQueryEval(source, globals=None, locals=None)pureeval(source[, globals, locals])
CompileScalarQueryCompile(source, filename, mode)purecompile(source, filename, mode) -> code object
GlobalsScalarQueryGlobals()pureescape hatch: live host globals() dict
LocalsScalarQueryLocals()pureescape hatch: live host locals() dict
ExecScalarQueryExec(namespace, source)pureescape hatch: exec(source, namespace), yields namespace

Logical

from nu import And, Or, Not, ToBool

Nu's And / Or do not short-circuit like Python's - they coerce every operand to bool and fold eagerly, always yielding a plain bool.

NameSortSignatureEffectMeaning
AndScalarQueryAnd(*operands)pureconjunction of children, eager (commutative, associative, idempotent); True if empty
OrScalarQueryOr(*operands)puredisjunction of children, eager (commutative, associative, idempotent); False if empty
NotScalarQueryNot(operand)purelogical negation
ToBoolScalarQueryToBool(operand)purebool(operand) truthiness

Reduction

from nu import Sum, Min, Max, AnyOf, AllOf, Count, First, Last, Collect

Scalar-over-stream folds - the Reduction sub-shape bridging a stream child down to one scalar.

NameSortSignatureEffectMeaning
SumReductionSum(stream)puresum of items (commutative, associative)
MinReductionMin(stream)puresmallest item (commutative, associative, idempotent); EMPTY if empty
MaxReductionMax(stream)purelargest item (commutative, associative, idempotent); EMPTY if empty
AnyOfReductionAnyOf(stream)puretrue if any item truthy (commutative, associative, idempotent)
AllOfReductionAllOf(stream)puretrue if every item truthy (commutative, associative, idempotent)
CountReductionCount(stream)purenumber of items (commutative, associative)
FirstReductionFirst(stream)purefirst item; EMPTY if empty
LastReductionLast(stream)purelast item; EMPTY if empty
CollectReductionCollect(stream)puredrain stream into a list

Transform

from nu import Map, Filter, Sorted, SortBy, Flatten, Unique

Stream-to-stream lazy lenses; Sorted and SortBy are eager (drain the source first). Map / Filter / SortBy bind each item into the attrs side-channel under a name child, read back in the body via AttrRef(<name>).

NameSortSignatureEffectMeaning
MapStreamQueryMap(source, transform, key="item")pureyield transform(item) per element, lazy
FilterStreamQueryFilter(source, predicate, key="item")pureyield items where predicate holds, lazy
SortedStreamQuerySorted(source)puresource ordered, eager (drains then sorts)
SortByStreamQuerySortBy(source, key, reverse=False, item="item")puresource ordered by per-item key expr, eager
FlattenStreamQueryFlatten(source)pureone-level concat of iterable-of-iterables, lazy
UniqueStreamQueryUnique(source)purefirst-seen-order dedupe, lazy (items must be hashable)

Iteration

from nu import Iter, Enumerate, Next, Zip, Reversed

Iterator sources are StreamQuery; Next steps a ref-held iterator (mutate-and-yield) so it is the first concrete Action in core.

NameSortSignatureEffectMeaning
IterStreamQueryIter(source)purelift a scalar iterable child into a stream
EnumerateStreamQueryEnumerate(source, start=0)pure(index, item) pairs, index from start
ZipStreamQueryZip(*sources)purethread sources item by item, stop at shortest
ReversedStreamQueryReversed(source)puresource items in reverse order
NextScalarActionNext(iterator)mutate + yieldadvance a ref-held iterator, yield the item

Access

from nu import GetItem, Len, Contains, Slice, GetAttr, HasAttr, SetItem, DelItem, SetAttr, DelAttr

Reads are ScalarQuery; writes are Command (local Python mutation, not a fabric write - context.Set / context.Delete own fabric writes).

NameSortSignatureEffectMeaning
GetItemScalarQueryGetItem(target, key)puretarget[key]
LenScalarQueryLen(operand)purelen(operand)
ContainsScalarQueryContains(container, item)pureitem in container
SliceScalarQuerySlice(start, stop, step)pureslice(start, stop, step)
GetAttrScalarQueryGetAttr(obj, name, default=None)puregetattr(obj, name[, default])
HasAttrScalarQueryHasAttr(obj, name)purehasattr(obj, name)
SetItemCommandSetItem(target, key, value)mutates targettarget[key] = value
DelItemCommandDelItem(target, key)mutates targetdel target[key]
SetAttrCommandSetAttr(obj, name, value)mutates objsetattr(obj, name, value)
DelAttrCommandDelAttr(obj, name)mutates objdelattr(obj, name)

Reflection

from nu import Type, IsInstance, IsSubclass, Callable, Id, Hash, Dir, Vars

NameSortSignatureEffectMeaning
TypeScalarQueryType(operand)puretype(operand)
IsInstanceScalarQueryIsInstance(value, klass)pureisinstance(value, klass)
IsSubclassScalarQueryIsSubclass(cls, klass)pureissubclass(cls, klass)
CallableScalarQueryCallable(operand)purecallable(operand)
IdScalarQueryId(operand)pureid(operand)
HashScalarQueryHash(operand)purehash(operand)
DirScalarQueryDir(operand)puredir(operand)
VarsScalarQueryVars(operand)purevars(operand) - the dict

Repr

from nu import Repr, Ascii, Format, Bin, Hex, Oct, Ord, Chr

NameSortSignatureEffectMeaning
ReprScalarQueryRepr(operand)purerepr(operand)
AsciiScalarQueryAscii(operand)pureascii(operand)
FormatScalarQueryFormat(value, spec=None)pureformat(value[, spec])
BinScalarQueryBin(operand)purebin(operand)
HexScalarQueryHex(operand)purehex(operand)
OctScalarQueryOct(operand)pureoct(operand)
OrdScalarQueryOrd(operand)pureord(operand)
ChrScalarQueryChr(operand)purechr(operand)

Sentinel

from nu import IsEmpty, NotEmpty, IsInvalid, NotInvalid

The one core family that observes sentinels rather than propagating them - no EMPTY / INVALID short-circuit in the compile thunk.

NameSortSignatureEffectMeaning
IsEmptyScalarQueryIsEmpty(operand)pureoperand is EMPTY
NotEmptyScalarQueryNotEmpty(operand)pureoperand is not EMPTY
IsInvalidScalarQueryIsInvalid(operand)pureoperand is INVALID
NotInvalidScalarQueryNotInvalid(operand)pureoperand is not INVALID

Reactive

from nu import OnChange, OnChildChange, OnChildrenChange, OnDescendantsChange, OnPrimitiveChange

Change subscriptions against the process-scope ObserverProtocol. Async-only - the sync compile path raises RuntimeError, use nu.arun.

NameSortSignatureEffectMeaning
OnChangeScalarQueryOnChange(ref)pure (async)subscribe to any change on the ref's view
OnChildChangeScalarQueryOnChildChange(ref, address)pure (async)subscribe to changes on one specific child
OnChildrenChangeScalarQueryOnChildrenChange(ref)pure (async)subscribe to changes on all immediate children
OnDescendantsChangeScalarQueryOnDescendantsChange(ref, *pattern)pure (async)subscribe to descendants matching a pattern
OnPrimitiveChangeScalarQueryOnPrimitiveChange(ref)pure (async)subscribe on a leaf ref's parent view, keyed by its address

IO

from nu.core.io import Print, Input, print, input, StdioRef, StdioBackend, STDOUT, STDERR, STDIN

Console read/write through the stdio fabric - not flat-exported at nu.*. Both go through a StdioRef (STDOUT/STDERR/STDIN) so effect synthesis keeps console IO serial. Prefer the lowercase wrapper functions print() / input(); they inject the Ref for you.

NameSortSignatureEffectMeaning
PrintCommandPrint(ref, *values, sep=" ", end="\n", flush=False)mutates stdio fabricwrite values to a stream, Python's print
InputScalarActionInput(ref)mutates + yields stdio fabricread one line from stdin, newline stripped

On this page