Skip to content

The standard library

These pages are for writing programs. Building on the library, or replacing parts of it, is under Host developers.

The standard library is a language: the primitive types, the ops every application has, and the symbols that are sugar over them. It is what you get before your application adds anything of its own.

The pages beside this one are generated from the library itself, one per segment, each op with its real signature and an example that was run to produce the value shown. They cannot drift from the code, because they are read out of it at build time.

This page is the part that is written by hand: the conventions all of them assume.

Every entry leads with one, and it is the real one, printed from the op:

Filter(list: any[], predicate: (any) -> boolean) -> any[]

The name, then each input with its type, then what comes out. Those input names are the ones you use when you pass arguments by name rather than in order, which Operators and symbols covers. The rest of this page is the parts of a signature that are not obvious on sight.

A signature ending in ... takes as many values as you give it:

output sum   = Add(1, 2, 3, 4)
output any   = Or($a, $b, $c)
output joined = Concat([1, 2], [3], [4, 5])

Add(nodes...: number) means one input called nodes that swallows every argument. Any op whose signature has the ... works this way: And, Multiply and Concat are three more.

The symbol form of a variadic op takes two at a time, so 1 + 2 + 3 nests where Add(1, 2, 3) does not. Same answer; the op form says “sum these” more directly.

An input marked ? may be left out: Join(parts~: string[], separator?: string) joins with nothing between the parts when it gets no separator. Leaving out an input that is not marked is a missing_op_input warning, with the type’s default standing in.

An input marked ~ converts what it is given. parts~: string[] accepts a list of anything, and each value in it becomes text before Join runs, so Join([1, 2], ", ") is "1, 2" with no ToString and no warning. The conversion is the op’s, declared on that one input and written under its signature; nothing else in the language converts on its own. A host can declare the mark on an op of its own with convert: true, and a lambda can carry it on a parameter, (t~: string) => Upper(t) (Naming a function). The shape still has to match: Join(5) is a type error.

An input typed lazy, as in then: lazy any, is evaluated only when the op reads it, or never. If reads the branch it takes, Default its fallback only for a null, and And and Or stop at the first value that decides them, so the rest may be anything, including something that could not be computed. The mark sits on the type and not on the name, because it says how the op receives the value, not what the value is; it combines with a name’s mark, nodes...: lazy boolean. A host declares it with lazy: true (Extending the language).

An input with none of the marks, one that only names a type, gives no value for no value: an op handed a null there, or a value of another kind, gives null and does not run. The marks say which inputs take one: any takes the value as it is, ? reads it as absent, ~ converts its leaves, lazy leaves it to the op.

An input typed any accepts any data value. Length(list: any[]) takes a list of anything, Equals(a: any, b: any) compares anything with anything.

This is not the op being careless. It is the op saying it does not care, which is true: Length counts without looking inside. What you lose is the check. Pass Length a list of strings and nothing complains, because nothing needed to.

Where an op can be more precise, it is, which is the next convention.

A signature is the general shape. Several ops narrow it for the particular call:

let numbers = [4, 8, 15]
output kept = Filter(numbers, n => n > 10)

Filter’s signature says -> any[], but this call produces a number[], because the list it was given was one. The same holds for Map (from its function’s return type), Find (the element type), Reduce (from the starting value) and If, which gives you the branch type when both branches agree and any when they do not.

So the reference tells you what an op accepts, and the editor tells you what your call produced. When they differ, the editor is right.

An input written (number) -> boolean wants a function. The list ops have one, and between them they are how iteration is expressed:

let items = [4, 8, 15, 16, 23]
output big = Filter(items, item => item > 10)

There is nothing special about those ops. A function is a value in this language, so an op taking one is an ordinary op, and you can hand it a lambda written in place or a name bound earlier. What the signature does not show is that the parameter type is worked out for you: the item above is a number because items is a list of numbers, so you rarely need to annotate it.

Lambdas and lists covers writing them.

The ops are grouped, and the grouping is real: it is a field on each op, which is what splits these pages up, and what fills this table.

SegmentWhat is in it
logicAnd, Or, Not, Xor, Equals, NotEquals, GreaterThan, LessThan
controlIf, IsSet, Default
arrayLength, Concat, Flatten, Average, Max, Min, Includes
arithmeticAdd, Subtract, Negate, Multiply, Divide, Mod, Pow, Abs, Round, Floor, Ceil, Clamp
listFilter, Map, Find, Every, Some, Reduce
conversionToString, ToNumber, ToBool
stringJoin, Upper, Lower, Trim, Contains, StartsWith, EndsWith

An application need not take all of them. One that never touches a list can leave the list ops out, and a program on it that calls Filter is told no operation or binding exists by that name, with the nearest one suggested. A symbol goes with its segment, so an application without arithmetic has no + either. If you are reading this inside somebody’s product, the editor’s own lists say which ops it has, and what it added. Choosing the segments is one line for whoever built the application, and Extending the language shows it.

Everything here is the floor, not the ceiling. An application embedding Dendrite registers its own types and its own ops, and those behave exactly like these: same call syntax, same checking, same reference format if it generates one. You cannot tell from a program whether Filter came from the standard library or from the application, and that is the point.