nustack
ReferenceNu

core

Nu core: every interaction a program is built from.

Module nu.core.

Nu core: every interaction a program is built from.

nu.core is the home of the atoms. Its own surface is the native standard terms - the builtins - and the three other atom families sit beside them as subpackages:

  • flows - control flow (Sequential, Parallel, Race, IfDo, WhileDo, Stream).
  • spans - transparent wrappers governing a region (Retry, Timeout, TryCatch, Transaction, Snapshot).
  • reactive - the reactivity standard: the observer contract plus the On*Change atoms fabrics bind against.

Everything under here is an Interaction. Forms (nu.forms), the kind taxonomy (nu.lang) and the fabric refs (nu.context, and the fabrics in nustd) are separate concerns with their own homes. The whole surface re-exports flat from the root, so day to day you write nu.Add / nu.Sequential / nu.Retry and never name this package.

The native standard terms

Concrete atoms layered on nu.lang's sort taxonomy - the kinds a real Nu program is built from. The goal is a 1:1 map of Python's native builtin functions (the ones that are not methods of a class) onto Nu interactions: abs -> Abs, getattr -> GetAttr, print -> Print. Library functions (itertools, functools, ...) are not core; they land in nustd in a later pass. Class methods land in extensions later too.

Files group atoms by Python domain, not by sort - one file per logical family, crossing Query / Command / Action as the builtins do:

  • literal - the constant-yielding ScalarQuery
  • arithmetic - numeric ops (Add, Sub, Mul, Pow, Abs, DivMod, Round)
  • comparison - ordering and identity (Eq, Lt, Gt, Is)
  • logical - boolean ops (And, Or, Not, ToBool)
  • conditional - value-yielding branch selection (If)
  • bitwise - bit ops (BitAnd, BitOr, BitXor, LShift)
  • cast - type construction / conversion (ToInt, ToStr, ToList, ToDict, ToSet)
  • repr - representations (Repr, Format, Bin, Hex, Ord, Chr)
  • access - item and attribute access (GetItem, Len, GetAttr, SetAttr)
  • iteration - iterator sources (Iter, Next, Enumerate, Zip, Reversed)
  • transform - stream-to-stream lenses (Map, Filter, Sorted, Flatten)
  • reduction - stream-to-scalar folds (Sum, Min, Max, AnyOf, AllOf, Collect)
  • reflection - introspection (Type, IsInstance, Callable, Id, Hash)
  • sentinel - the EMPTY / INVALID predicates (IsEmpty, IsInvalid)
  • io - console effects through the stdio fabric (Print, Input). Logging lives at nustd.logging -- a Python logging module wrap.
  • dynamic - host-namespace escape hatches (Globals, Locals)

This surface is the pure Python builtins. The fabric interactions (writing through a Ref into the Context store, a database, stdio) live in their own fabric dirs - nu.context owns SetCmd / Delete / AttrRef, not here - and the Forms layer (types, classes) has its own home at nu.forms. Flows and Spans (Seq, Par, If, Retry, Transaction) are the subpackages above.

Modules

ModuleWhat
nu.core.flowsNu2 Flow atoms: the Command-composing sub-kind.
nu.core.spansSpan atoms: transparent Interactions that wrap a body to govern a region.

arithmetic

Module nu.core.arithmetic.

Arithmetic atoms: Python's numeric builtins and operators.

Full entries

NameSortCallMeaning
Absscalar_queryAbs(value)The absolute value of its one child.
Addscalar_queryAdd(*children)The sum of its scalar children.
Divscalar_queryDiv(left, right)The first child divided by the second (true division).
DivModscalar_queryDivMod(left, right)The (quotient, remainder) pair of its two children.
FloorDivscalar_queryFloorDiv(left, right)The first child floor-divided by the second.
MatMulscalar_queryMatMul(left, right)The matrix product of its two children.
Modscalar_queryMod(left, right)The first child modulo the second.
Mulscalar_queryMul(*children)The product of its scalar children.
Negscalar_queryNeg(value)The arithmetic negation of its one child.
Posscalar_queryPos(value)The unary plus of its one child.
Powscalar_queryPow(base, exponent)The first child raised to the power of the second.
Roundscalar_queryRound(value, ndigits)The first child rounded, to the second child's digits when given.
Subscalar_querySub(left, right)The first child minus the second.

reduction

Module nu.core.reduction.

Reduction atoms: Python's stream-to-scalar builtins.

Full entries

NameSortCallMeaning
AllOfreductionAllOf(stream)True if every item in its stream child is truthy (all).
AnyOfreductionAnyOf(stream)True if any item in its stream child is truthy (any).
CollectreductionCollect(stream)Drains its stream child into one list value.
CountreductionCount(stream)The number of items in its stream child (len over a stream).
FirstreductionFirst(stream)The first item of its stream child.
LastreductionLast(stream)The last item of its stream child.
MaxreductionMax(stream)The largest item in its stream child (max).
MinreductionMin(stream)The smallest item in its stream child (min).
SumreductionSum(stream)The sum of every item in its stream child (sum).

logical

Module nu.core.logical.

Logical atoms: Python's boolean operators and truthiness.

Full entries

NameSortCallMeaning
Andscalar_queryAnd(*children)The conjunction of its boolean children, each coerced with bool.
Notscalar_queryNot(value)The negation of its one child.
Orscalar_queryOr(*children)The disjunction of its boolean children, each coerced with bool.
ToBoolscalar_queryToBool(value)The truthiness of its one child.
boolcore.bool(x)Coerce x to a Nu Bool term.

repr

Module nu.core.repr.

Representation atoms: Python's string and number renderings.

Full entries

NameSortCallMeaning
Asciiscalar_queryAscii(value)The ascii string of its one child, with non-ASCII escaped.
Binscalar_queryBin(value)The binary string (0b...) of its one integer child.
Chrscalar_queryChr(value)The character for its one integer code-point child.
Formatscalar_queryFormat(value, spec)The format of a value under an optional format spec.
Hexscalar_queryHex(value)The hexadecimal string (0x...) of its one integer child.
Octscalar_queryOct(value)The octal string (0o...) of its one integer child.
Ordscalar_queryOrd(value)The Unicode code point of its one single-character child.
Reprscalar_queryRepr(value)The repr string of its one child.

bitwise

Module nu.core.bitwise.

Bitwise atoms: Python's bit-level operators.

Full entries

NameSortCallMeaning
BitAndscalar_queryBitAnd(*children)The bitwise AND of its scalar children.
BitNotscalar_queryBitNot(value)The bitwise NOT of its one child.
BitOrscalar_queryBitOr(*children)The bitwise OR of its scalar children.
BitXorscalar_queryBitXor(*children)The bitwise XOR of its scalar children.
LShiftscalar_queryLShift(value, count)The first child shifted left by the second.
RShiftscalar_queryRShift(value, count)The first child shifted right by the second.

reflection

Module nu.core.reflection.

Reflection atoms: Python's introspection builtins.

Full entries

NameSortCallMeaning
Callablescalar_queryCallable(value)Whether its one child appears callable (callable).
Dirscalar_queryDir(value)The sorted attribute-name list of its one child (dir).
Hashscalar_queryHash(value)The hash of its one child (hash).
Idscalar_queryId(value)The identity of its one child (id).
IsInstancescalar_queryIsInstance(value, klass)Whether the first child is an instance of the second (isinstance).
IsSubclassscalar_queryIsSubclass(cls, klass)Whether the first child is a subclass of the second (issubclass).
Typescalar_queryType(value)The type of its one child (type).
Varsscalar_queryVars(value)The __dict__ of its one child (vars).

access

Module nu.core.access.

Access atoms: Python's item and attribute management.

Full entries

NameSortCallMeaning
Containsscalar_queryContains(container, item)Containment: item in container.
DelAttrscalar_commandDelAttr(obj, name)Attribute delete: delattr(obj, name).
DelItemscalar_commandDelItem(target, key)Subscript delete: del x[k].
GetAttrscalar_queryGetAttr(obj, name, default)Attribute read: getattr(obj, name[, default]).
GetItemscalar_queryGetItem(target, key)Subscript access: x[k].
HasAttrscalar_queryHasAttr(obj, name)Attribute presence: hasattr(obj, name).
Lenscalar_queryLen(value)Length: len(x) of its one child.
SetAttrscalar_commandSetAttr(obj, name, value)Attribute write: setattr(obj, name, value).
SetItemscalar_commandSetItem(target, key, value)Subscript write: x[k] = v.
Slicescalar_querySlice(start, stop, step)The slice(...) builtin: builds a slice object.

iteration

Module nu.core.iteration.

Iteration atoms: Python's iterator sources and stepping.

Full entries

NameSortCallMeaning
Enumeratestream_queryEnumerate(source, start)Pairs each item of a source child with its running index.
Iterstream_queryIter(source)Opens a scalar iterable child into a stream of its elements.
Nextscalar_actionNext(iterator)Advances a ref-held iterator child and yields the item it pulls.
Reversedstream_queryReversed(source)Yields the items of a source child in reverse order.
Zipstream_queryZip(*sources)Threads several source children together item by item.

comparison

Module nu.core.comparison.

Comparison atoms: Python's ordering and identity operators.

Full entries

NameSortCallMeaning
Eqscalar_queryEq(left, right)Whether its two children are equal (==).
Gescalar_queryGe(left, right)Whether the first child is greater than or equal to the second (>=).
Gtscalar_queryGt(left, right)Whether the first child is greater than the second (>).
Isscalar_queryIs(left, right)Whether its two children are the same object (is).
Lescalar_queryLe(left, right)Whether the first child is less than or equal to the second (<=).
Ltscalar_queryLt(left, right)Whether the first child is less than the second (<).
Nescalar_queryNe(left, right)Whether its two children are unequal (!=).

transform

Module nu.core.transform.

Transform atoms: Python's stream-to-stream builtins.

Full entries

NameSortCallMeaning
Filterstream_queryFilter(source, predicate, key='item')Keeps the items of a stream child for which a predicate holds (lazy).
Flattenstream_queryFlatten(source)Concatenates a source of iterables one level into a flat stream (lazy).
Mapstream_queryMap(source, transform, key='item')Applies a query child to every item of a stream child (lazy).
SortBystream_querySortBy(source, key, reverse=False, item='item')Its source child, ordered by a per-item key expression (eager).
Sortedstream_querySorted(source)Its source child, ordered (eager).
Uniquestream_queryUnique(source)Yields each item of a source child once, first-seen order (lazy).

dynamic

Module nu.core.dynamic.

Dynamic dispatch atoms: reach into the live Python interpreter namespace.

Full entries

NameSortCallMeaning
Globalsscalar_queryGlobals()ESCAPE HATCH: the host module namespace dict.
Localsscalar_queryLocals()ESCAPE HATCH: the host local namespace dict.

conditional

Module nu.core.conditional.

Conditional atoms: value-yielding branch selection.

Full entries

NameSortCallMeaning
Ifscalar_queryIf(cond, then, else_)The then branch if cond is truthy, else the else_ branch.
Switchscalar_querySwitch(selector, cases, default=None)The case value whose key matches the selector, or the default.

io

Module nu.core.io.

IO: console read/write through the stdio fabric.

Full entries

NameSortCallMeaning
Inputscalar_actionInput(ref)Reads one line from the stdin fabric Ref in slot 0 and yields it.
Printscalar_commandPrint(ref, sep=' ', end='\n', flush=False)Writes the values in slots 1.. to the stdout fabric Ref in slot 0.
inputcore.input()Read one line from stdin (newline stripped) and yield it as a Str.
printcore.print(sep=' ', end='\n', file=None, flush=False)Write values to a stdio stream. Mirrors builtins.print.

sentinel

Module nu.core.sentinel.

Sentinel atoms: the predicates that observe EMPTY / INVALID.

Full entries

NameSortCallMeaning
IsEmptyscalar_queryIsEmpty(value)True if its one child yields the EMPTY sentinel.
IsInvalidscalar_queryIsInvalid(value)True if its one child yields the INVALID sentinel.
NotEmptyscalar_queryNotEmpty(value)True if its one child does not yield EMPTY.
NotInvalidscalar_queryNotInvalid(value)True if its one child does not yield INVALID.

reactive.interactions

Module nu.core.reactive.interactions.

Reactive change subscriptions -- unified interaction atoms.

Full entries

NameSortCallMeaning
OnChangescalar_queryOnChange(ref)Opens a subscription to any change on a Ref's view.
OnChildChangescalar_queryOnChildChange(ref, address)Opens a subscription to changes on one named child of a Ref's view.
OnChildrenChangescalar_queryOnChildrenChange(ref)Opens a subscription to changes on any immediate child of a Ref's view.
OnDescendantsChangescalar_queryOnDescendantsChange(ref, *pattern)Opens a subscription to descendants of a Ref's view matching a pattern.
OnPrimitiveChangescalar_queryOnPrimitiveChange(ref)Opens a subscription to changes at a leaf Ref, through its parent view.

cast

Module nu.core.cast.

Cast atoms: Python's type constructors and conversions.

Full entries

NameSortCallMeaning
ToByteArrayscalar_queryToByteArray(value, encoding)The operand cast to bytearray.
ToBytesscalar_queryToBytes(value, encoding)The operand cast to bytes.
ToComplexscalar_queryToComplex(real, imag)The operand cast to complex.
ToDictscalar_queryToDict(value)The key/value pairs of the iterable child collected into a dict.
ToFloatscalar_queryToFloat(value)The operand cast to float.
ToFrozenSetscalar_queryToFrozenSet(value)The iterable child collected into a frozenset.
ToIntscalar_queryToInt(value, base)The operand cast to int.
ToListscalar_queryToList(value)The iterable child collected into a list.
ToSetscalar_queryToSet(value)The iterable child collected into a set.
ToStrscalar_queryToStr(value)The operand cast to str.
ToTuplescalar_queryToTuple(value)The iterable child collected into a tuple.

cast_fns

Module nu.core.cast_fns.

Cast wrappers: coerce x into a Nu term of the target Form.

Full entries

NameCallMeaning
dictcore.dict(x)Coerce x to a Nu Dict term. Dict(ToDict(x)) in one call.
floatcore.float(x)Coerce x to a Nu Float term. Float(ToFloat(x)) in one call.
frozensetcore.frozenset(x)Coerce x to a Nu FrozenSet term. FrozenSet(ToFrozenSet(x)) in one call.
intcore.int(x)Coerce x to a Nu Int term. Int(ToInt(x)) in one call.
listcore.list(x)Coerce x to a Nu List term. List(ToList(x)) in one call.
setcore.set(x)Coerce x to a Nu Set term. Set(ToSet(x)) in one call.
strcore.str(x)Coerce x to a Nu Str term. Str(ToStr(x)) in one call.
tuplecore.tuple(x)Coerce x to a Nu Tuple term. Tuple(ToTuple(x)) in one call.

On this page