designspace.Primitive#

class designspace.Primitive(name: str, arity: int | tuple[int, int | None], fn: Any = None)#

Bases: object

An operator declared for a .symbolic() parameter, with its arity.

Naming a primitive as a bare string is enough to admit it, but then nothing checks how many arguments it is given. Declaring it this way adds that check. fn is metadata for your own interpreter, and the library never calls it.

name#

The operator name, as it appears in a tree’s “op” field.

Type:

str

arity#

An exact count, or a (lo, hi) range with hi=None for unbounded.

Type:

int | tuple[int, int | None]

fn#

An implementation, for a consumer’s own evaluator. Never called by the library, and not serializable.

Type:

Any

Examples

>>> ds.Primitive("add", 2).arity_range
(2, 2)
>>> ds.Primitive("sum", (1, None)).arity_range
(1, None)
property arity_range: tuple[int, int | None]#

The arity as a (lo, hi) pair, whichever form it was declared in.

Examples

>>> ds.Primitive("neg", 1).arity_range
(1, 1)