Skip to main content

Compute functions reference

Every tag in the <compute> sub-language, grouped by what it does. The Compute Language section covers how they fit together.

Reading the signature column: int|str|list means any of the three, … means any number of children, ? marks an optional attribute, 1 means exactly one child expression, and — means the tag yields no value of its own. Slot tags — the children that carry a job title — are shown by name in the signature of the tag that owns them.

The attributes in the signature are the only ones a tag reads. Any other name — <join seperator="-"> for sep= — stops the run with TDC015 and the nearest real name, because a tag that ignored it would compute the value as if it were not written. comment= is accepted on every tag.

Literals and references​

In depth: The compute sub-language

TagSignatureWhat it does
<int>v= → intAn integer literal (attribute v)
<str>v= → strA string literal (attribute v)
<list>v= or int… → listA literal list of ints, or one built from nested expressions
<field>name= → strThe value of a sequence in scope — the same as ${{X}}
<use>name= → int|str|listA value bound by <let>
<let>name= + 1 → —Name an intermediate result for sibling tags
<current>→ int|strThe current iteration item (inside <do>)
<current_index>→ intThe current item's index, counting from zero
<acc>→ int|str|listThe accumulator (inside <reduce>)

Lists and iteration​

In depth: Lists & iteration

TagSignatureWhat it does
<each><over> <do> → listTransform every element → a new list
<reduce><over> <init> <do> → int|str|listFold a list into one value (<acc>)
<join>list + sep=? → strList → string (attribute sep)
<split>str + sep= → listString → list, cut on sep (required)
<at><in> <index> + default=? → int|strAn element by index (attribute default)
<length>str|list → intLength of a string or a list

Arithmetic​

In depth: Arithmetic

TagSignatureWhat it does
<add>int… → intSum of all children (empty → 0)
<subtract>int… → intFirst minus the sum of the rest
<multiply>int… → intProduct (empty → 1)
<divide>int int → intInteger division toward −∞ (2 children)
<mod>int int → intEuclidean remainder, always ≥ 0

Strings, encoding, formatting​

In depth: Strings & formatting

TagSignatureWhat it does
<encode>str(1) + as= → strCharacter → number (base36/ascii/hex/…)
<to_number>str → intDigit string → integer
<pad>int|str + width= fill=? → strPad on the left to a given width (width, fill)
<concat>int|str… → strJoin several parts into one string
<upper> / <lower>str → strUpper / lower case
<capitalize>str → strUppercase the first letter
<title>str → strUppercase the first letter of every word
<mask>str + pattern= → strDisplay mask (pattern: x/w/*)
<slice>str + from= to=? → strSubstring [from, to)
<replace>str + from= to= → strReplace every occurrence (from, to)
<trim>str → strStrip surrounding whitespace
<group>str + size=? sep=? → strGroup digits from the right (size, sep)

Conditionals​

In depth: Conditionals

TagSignatureWhat it does
<choose><when>… <otherwise> → int|str|listChoose a branch; requires an <otherwise>
<when><test> <then> → —A branch: <test> predicate + <then> value
<otherwise>1 → int|str|listThe "else" branch (required)
<test>1 → yes|noHolds one predicate, yields yes or no
<then>1 → int|str|listThe value of the matched branch
<equals>int int → yes|noPredicate: two ints are equal
<greater_than>int int → yes|noPredicate: A > B
<less_than>int int → yes|noPredicate: A < B
<is_digit>str(1) → yes|noPredicate: a character is a digit 0–9

Wrappers and special​

TagSignatureWhat it does
<over>1 → str|listThe input list for <each> / <reduce>
<do>1 → int|str|listThe iteration body for <each> / <reduce>
<init>1 → int|str|listThe accumulator's starting value for <reduce>
<in>1 → listThe list for <at>
<index>1 → intThe item index for <at>
<result>1 → int|strThe final value of a <compute>
<valid>1 → —Reject and retry until the value is valid

See the Compute Language section for worked examples.