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 theOn*Changeatoms 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 ScalarQueryarithmetic- 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 atnustd.logging-- a Pythonloggingmodule 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
| Module | What |
|---|---|
nu.core.flows | Nu2 Flow atoms: the Command-composing sub-kind. |
nu.core.spans | Span atoms: transparent Interactions that wrap a body to govern a region. |
arithmetic
Module nu.core.arithmetic.
Arithmetic atoms: Python's numeric builtins and operators.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Abs | scalar_query | Abs(value) | The absolute value of its one child. |
| Add | scalar_query | Add(*children) | The sum of its scalar children. |
| Div | scalar_query | Div(left, right) | The first child divided by the second (true division). |
| DivMod | scalar_query | DivMod(left, right) | The (quotient, remainder) pair of its two children. |
| FloorDiv | scalar_query | FloorDiv(left, right) | The first child floor-divided by the second. |
| MatMul | scalar_query | MatMul(left, right) | The matrix product of its two children. |
| Mod | scalar_query | Mod(left, right) | The first child modulo the second. |
| Mul | scalar_query | Mul(*children) | The product of its scalar children. |
| Neg | scalar_query | Neg(value) | The arithmetic negation of its one child. |
| Pos | scalar_query | Pos(value) | The unary plus of its one child. |
| Pow | scalar_query | Pow(base, exponent) | The first child raised to the power of the second. |
| Round | scalar_query | Round(value, ndigits) | The first child rounded, to the second child's digits when given. |
| Sub | scalar_query | Sub(left, right) | The first child minus the second. |
reduction
Module nu.core.reduction.
Reduction atoms: Python's stream-to-scalar builtins.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| AllOf | reduction | AllOf(stream) | True if every item in its stream child is truthy (all). |
| AnyOf | reduction | AnyOf(stream) | True if any item in its stream child is truthy (any). |
| Collect | reduction | Collect(stream) | Drains its stream child into one list value. |
| Count | reduction | Count(stream) | The number of items in its stream child (len over a stream). |
| First | reduction | First(stream) | The first item of its stream child. |
| Last | reduction | Last(stream) | The last item of its stream child. |
| Max | reduction | Max(stream) | The largest item in its stream child (max). |
| Min | reduction | Min(stream) | The smallest item in its stream child (min). |
| Sum | reduction | Sum(stream) | The sum of every item in its stream child (sum). |
logical
Module nu.core.logical.
Logical atoms: Python's boolean operators and truthiness.
| 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. |
repr
Module nu.core.repr.
Representation atoms: Python's string and number renderings.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Ascii | scalar_query | Ascii(value) | The ascii string of its one child, with non-ASCII escaped. |
| Bin | scalar_query | Bin(value) | The binary string (0b...) of its one integer child. |
| Chr | scalar_query | Chr(value) | The character for its one integer code-point child. |
| Format | scalar_query | Format(value, spec) | The format of a value under an optional format spec. |
| Hex | scalar_query | Hex(value) | The hexadecimal string (0x...) of its one integer child. |
| Oct | scalar_query | Oct(value) | The octal string (0o...) of its one integer child. |
| Ord | scalar_query | Ord(value) | The Unicode code point of its one single-character child. |
| Repr | scalar_query | Repr(value) | The repr string of its one child. |
bitwise
Module nu.core.bitwise.
Bitwise atoms: Python's bit-level operators.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| BitAnd | scalar_query | BitAnd(*children) | The bitwise AND of its scalar children. |
| BitNot | scalar_query | BitNot(value) | The bitwise NOT of its one child. |
| BitOr | scalar_query | BitOr(*children) | The bitwise OR of its scalar children. |
| BitXor | scalar_query | BitXor(*children) | The bitwise XOR of its scalar children. |
| LShift | scalar_query | LShift(value, count) | The first child shifted left by the second. |
| RShift | scalar_query | RShift(value, count) | The first child shifted right by the second. |
reflection
Module nu.core.reflection.
Reflection atoms: Python's introspection builtins.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Callable | scalar_query | Callable(value) | Whether its one child appears callable (callable). |
| Dir | scalar_query | Dir(value) | The sorted attribute-name list of its one child (dir). |
| Hash | scalar_query | Hash(value) | The hash of its one child (hash). |
| Id | scalar_query | Id(value) | The identity of its one child (id). |
| IsInstance | scalar_query | IsInstance(value, klass) | Whether the first child is an instance of the second (isinstance). |
| IsSubclass | scalar_query | IsSubclass(cls, klass) | Whether the first child is a subclass of the second (issubclass). |
| Type | scalar_query | Type(value) | The type of its one child (type). |
| Vars | scalar_query | Vars(value) | The __dict__ of its one child (vars). |
access
Module nu.core.access.
Access atoms: Python's item and attribute management.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Contains | scalar_query | Contains(container, item) | Containment: item in container. |
| DelAttr | scalar_command | DelAttr(obj, name) | Attribute delete: delattr(obj, name). |
| DelItem | scalar_command | DelItem(target, key) | Subscript delete: del x[k]. |
| GetAttr | scalar_query | GetAttr(obj, name, default) | Attribute read: getattr(obj, name[, default]). |
| GetItem | scalar_query | GetItem(target, key) | Subscript access: x[k]. |
| HasAttr | scalar_query | HasAttr(obj, name) | Attribute presence: hasattr(obj, name). |
| Len | scalar_query | Len(value) | Length: len(x) of its one child. |
| SetAttr | scalar_command | SetAttr(obj, name, value) | Attribute write: setattr(obj, name, value). |
| SetItem | scalar_command | SetItem(target, key, value) | Subscript write: x[k] = v. |
| Slice | scalar_query | Slice(start, stop, step) | The slice(...) builtin: builds a slice object. |
iteration
Module nu.core.iteration.
Iteration atoms: Python's iterator sources and stepping.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Enumerate | stream_query | Enumerate(source, start) | Pairs each item of a source child with its running index. |
| Iter | stream_query | Iter(source) | Opens a scalar iterable child into a stream of its elements. |
| Next | scalar_action | Next(iterator) | Advances a ref-held iterator child and yields the item it pulls. |
| Reversed | stream_query | Reversed(source) | Yields the items of a source child in reverse order. |
| Zip | stream_query | Zip(*sources) | Threads several source children together item by item. |
comparison
Module nu.core.comparison.
Comparison atoms: Python's ordering and identity operators.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Eq | scalar_query | Eq(left, right) | Whether its two children are equal (==). |
| Ge | scalar_query | Ge(left, right) | Whether the first child is greater than or equal to the second (>=). |
| Gt | scalar_query | Gt(left, right) | Whether the first child is greater than the second (>). |
| Is | scalar_query | Is(left, right) | Whether its two children are the same object (is). |
| Le | scalar_query | Le(left, right) | Whether the first child is less than or equal to the second (<=). |
| Lt | scalar_query | Lt(left, right) | Whether the first child is less than the second (<). |
| Ne | scalar_query | Ne(left, right) | Whether its two children are unequal (!=). |
transform
Module nu.core.transform.
Transform atoms: Python's stream-to-stream builtins.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Filter | stream_query | Filter(source, predicate, key='item') | Keeps the items of a stream child for which a predicate holds (lazy). |
| Flatten | stream_query | Flatten(source) | Concatenates a source of iterables one level into a flat stream (lazy). |
| Map | stream_query | Map(source, transform, key='item') | Applies a query child to every item of a stream child (lazy). |
| SortBy | stream_query | SortBy(source, key, reverse=False, item='item') | Its source child, ordered by a per-item key expression (eager). |
| Sorted | stream_query | Sorted(source) | Its source child, ordered (eager). |
| Unique | stream_query | Unique(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.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Globals | scalar_query | Globals() | ESCAPE HATCH: the host module namespace dict. |
| Locals | scalar_query | Locals() | ESCAPE HATCH: the host local namespace dict. |
conditional
Module nu.core.conditional.
Conditional atoms: value-yielding branch selection.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| If | scalar_query | If(cond, then, else_) | The then branch if cond is truthy, else the else_ branch. |
| Switch | scalar_query | Switch(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.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Input | scalar_action | Input(ref) | Reads one line from the stdin fabric Ref in slot 0 and yields it. |
scalar_command | Print(ref, sep=' ', end='\n', flush=False) | Writes the values in slots 1.. to the stdout fabric Ref in slot 0. | |
| input | core.input() | Read one line from stdin (newline stripped) and yield it as a Str. | |
core.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.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| IsEmpty | scalar_query | IsEmpty(value) | True if its one child yields the EMPTY sentinel. |
| IsInvalid | scalar_query | IsInvalid(value) | True if its one child yields the INVALID sentinel. |
| NotEmpty | scalar_query | NotEmpty(value) | True if its one child does not yield EMPTY. |
| NotInvalid | scalar_query | NotInvalid(value) | True if its one child does not yield INVALID. |
reactive.interactions
Module nu.core.reactive.interactions.
Reactive change subscriptions -- unified interaction atoms.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| OnChange | scalar_query | OnChange(ref) | Opens a subscription to any change on a Ref's view. |
| OnChildChange | scalar_query | OnChildChange(ref, address) | Opens a subscription to changes on one named child of a Ref's view. |
| OnChildrenChange | scalar_query | OnChildrenChange(ref) | Opens a subscription to changes on any immediate child of a Ref's view. |
| OnDescendantsChange | scalar_query | OnDescendantsChange(ref, *pattern) | Opens a subscription to descendants of a Ref's view matching a pattern. |
| OnPrimitiveChange | scalar_query | OnPrimitiveChange(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.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| ToByteArray | scalar_query | ToByteArray(value, encoding) | The operand cast to bytearray. |
| ToBytes | scalar_query | ToBytes(value, encoding) | The operand cast to bytes. |
| ToComplex | scalar_query | ToComplex(real, imag) | The operand cast to complex. |
| ToDict | scalar_query | ToDict(value) | The key/value pairs of the iterable child collected into a dict. |
| ToFloat | scalar_query | ToFloat(value) | The operand cast to float. |
| ToFrozenSet | scalar_query | ToFrozenSet(value) | The iterable child collected into a frozenset. |
| ToInt | scalar_query | ToInt(value, base) | The operand cast to int. |
| ToList | scalar_query | ToList(value) | The iterable child collected into a list. |
| ToSet | scalar_query | ToSet(value) | The iterable child collected into a set. |
| ToStr | scalar_query | ToStr(value) | The operand cast to str. |
| ToTuple | scalar_query | ToTuple(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.
| Name | Call | Meaning |
|---|---|---|
| dict | core.dict(x) | Coerce x to a Nu Dict term. Dict(ToDict(x)) in one call. |
| float | core.float(x) | Coerce x to a Nu Float term. Float(ToFloat(x)) in one call. |
| frozenset | core.frozenset(x) | Coerce x to a Nu FrozenSet term. FrozenSet(ToFrozenSet(x)) in one call. |
| int | core.int(x) | Coerce x to a Nu Int term. Int(ToInt(x)) in one call. |
| list | core.list(x) | Coerce x to a Nu List term. List(ToList(x)) in one call. |
| set | core.set(x) | Coerce x to a Nu Set term. Set(ToSet(x)) in one call. |
| str | core.str(x) | Coerce x to a Nu Str term. Str(ToStr(x)) in one call. |
| tuple | core.tuple(x) | Coerce x to a Nu Tuple term. Tuple(ToTuple(x)) in one call. |