nustack

refs.prog

kv program leaf: Nu source stored in a slot, runnable from it.

Module nustd.kv.refs.prog.

kv program leaf: Nu source stored in a slot, runnable from it.

The stored form is the value form (source text on both sides), so the leaf carries an interface rather than a codec. The base order is load-bearing: the leaf comes first so the ref reads storage; see the class docstring.

NameSortCallMeaning
ProgramRefrefProgramRef(address, parent_ref=None, owner_shape=None)A Nu program stored as source text in a KV leaf, with the Program verbs.

ProgramRef

A Nu program stored as source text in a KV leaf, with the Program verbs.

ProgramRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.ProgramRef. Kind Ref, sort ref, cardinality scalar.

Reading it yields the source verbatim, the same as any str leaf. What the Program surface adds is the ability to turn that stored text into a tree and run it, so a program becomes a value a shape can hold, write and replace at run time.

Notes

  • No codec: source text is both the stored form and the value form, unlike the std refs that translate between the two.
  • The base order is load-bearing. ItemRef first makes the class a ref that reads storage; with Program first the passthrough would win and the ref would yield its parent instead of the stored value, silently, with no fabric touch recorded.
  • Construction errors surface when the stored source is loaded or run, not when it is written, so bad source stores fine.

Example

class App(Shape):
    job = ProgramRef.slot()
run(App.job.set(SOURCE), ctx)
run(App.job.run(), ctx)

Inherited methods

From nu.domains.shape.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.item.MutableItemForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.item.ItemForm:

CallBuildsMeaning
.exists()BoolWhether this slot holds a value, as a Bool.
.missing()BoolWhether this slot holds no value, as a Bool: the negation of exists().

From nu.prog.forms.Program:

CallBuildsMeaning
.load(entry='out', scope=None, filename='<nu program>', brace=<UNSET>, rewrite=None)NuConstruct the term without running it.
.run(entry='out', scope=None, filename='<nu program>', brace=<UNSET>, rewrite=None, on_error=None)NuConstruct the term and drive it.

From nu.lang.forms.Form:

CallBuildsMeaning
a == bBoolSelf equal to other by value: an Eq term, never a Python bool.
a != bBoolSelf not equal to other by value: a Ne term, never a Python bool.
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

On this page