The specification
This document is the specification of Vex 1.0. Each normative statement has a requirement ID in square brackets, for example [EVAL.TOTAL]. Each requirement ID has at least one test that names it. The test spec-coverage.test.ts makes CI fail when an ID has no test, or when a test names an ID that this document does not define.
The design and the reasons for it are in docs/REVIEW.md. The v0.9 specification is in docs/archive/spec-v0.9.md.
1. Model
Section titled “1. Model”A Vex program is an expression. It evaluates at one key of a space. The key where it starts is the origin. The key where relative references read is the focus. At the start, the focus is the origin.
| Term | Meaning |
|---|---|
| space | An immutable collection of records with keys: a record space, an array space or a grid space |
| origin | The key where an evaluation starts |
| focus | The key where a reference without an address reads |
| address | A list of moves from the focus |
| axis | A relation between the focus and a list of target keys |
| domain | A set of values and the ops on them |
| result | A value, or an error value with a code |
2. Spaces
Section titled “2. Spaces”- A record space has the property names of an object as keys, in their order.
- An array space has the keys
"0","1"and so on. - A grid space has the key
"row,column"for each cell. A row can be shorter than the others. - SPACE.TREE7 tests pass A tree space has records by key, and a parent for each key that is not a root. A parent that is not a key, or a cycle of parents, makes the constructor throw. The children of a key are in key order.
- SPACE.GRAPH2 tests pass A graph space has records by key, and the edges from each key, in order. A graph can have cycles, and an edge can go from a key to itself. A second edge to the same key is the same edge. An edge to a key that is not in the graph makes the constructor throw.
- SPACE.RECORDS1 tests pass Each space that
spacemakes hasrecords, a frozen list of its records in the order ofkeys. For each key, the record at its index is the record thatgetgives. - A space copies its input. A later change to the input does not change the space.
3. Addresses
Section titled “3. Addresses”A move changes the key where a reference reads.
- NAV.KEY1 tests pass The move
key(k)goes to the keyk. If the space has no keyk, the result is the error#REF!. - NAV.INDEX1 tests pass The move
index(i)goes to the key at positioniin the key order. A position outside the keys gives#REF!. - NAV.COMPUTED6 tests pass The key of
keyand the position ofindexcan be an expression. These expressions evaluate first, in order, at the position of the node of the address. The first error is the result. A key that is not a text, or a position that is not a number, gives#VALUE!. Then the moves apply. - NAV.OTHER.PAIR2 tests pass The move
othergoes to the other key of a space with two keys. In a space with a different number of keys, it gives#REF!. - NAV.OFFSET2 tests pass The move
offset(d)addsdto the position of the focus: one number in an array space, two numbers in a grid space. A position outside the space, or an offset in a record space, gives#REF!. - NAV.OFFSET.TREE3 tests pass In a tree space, the move
offset(d)with one number goes to the sibling at distancedin key order. The roots are the siblings of a root. A position outside the siblings gives#REF!. - NAV.ORIGIN1 tests pass The move
origingoes back to the origin of the evaluation. - NAV.PARENT8 tests pass The move
parentgoes to the parent of the focus in a tree space. A root gives#REF!, and a space that is not a tree gives#REF!. - NAV.SEQUENCE2 tests pass The moves of an address apply in order. If one move fails, the address fails. Vex does not simplify addresses, because a simplification could hide a failure.
4. Expressions
Section titled “4. Expressions”An expression is plain JSON data. It has one of these kinds.
| Kind | Fields | Value |
|---|---|---|
lit |
value |
the value |
ref |
path, at |
the field at the path, in the record at the address |
app |
op, args |
the op applied to the values of the arguments |
let |
bind, body |
the body, with names bound to the values of the bindings |
var |
name |
the value of a bound name |
rec |
fields |
a record of the values of the fields |
each |
axis, body, at, as |
a list: the body at each target of the axis, from the key of the address |
fold |
axis, init, step, result, at, as |
the result, after a step at each target of the axis |
iterate |
limit, init, step, until, result |
the result, after the steps |
fix |
name, join, init, step |
the row of the focus, after the rounds of a column (FIX.ROUNDS) |
last |
name |
the row of the focus, in the last round of the fix with the name (FIX.LAST) |
ext |
kind, data |
the value of an extension handler |
- IR.JSON22 tests pass An expression gives the same expression after
serializeandparse, if each literal is JSON data or a value of a domain. A domain value needsencodeanddecodein its domain. A domain value can be in a list or a record of a literal. A key__proto__of a record of a literal, of aletor of arecis a key too. - IR.JSON.NUMBER2 tests pass A literal number that JSON has no text for (
-0,NaN,Infinityor-Infinity) gets the form{ "$vex": "number", "value": text }. - IR.JSON.ESCAPE2 tests pass A record of a literal with the key
$vexgets the form{ "$vex": "escape", "value": record }. Thusparsedoes not read data as a domain value. A record with another form of$vexstays data.
4.1 Documents
Section titled “4.1 Documents”A document is the form of an expression in coeval, the kernel of the family. Its rules are the decision D12 of coeval. Each term is an envelope { "type": t, "value": v }. toDocument writes a document, and fromDocument reads it.
Since decision D13 of coeval, the kernel is the core of Vex. It checks and analyzes each document by the contracts of the kinds of Vex. It is also the reference tier of Vex (EVAL.REFERENCE).
| Expression | Document |
|---|---|
lit |
the JSON value, or { "type": "lit", "value": v } |
ref |
{ "type": "ref", "value": ["self", ...moves, ...fields] } |
var |
{ "type": "ref", "value": ["names", name] } |
app |
{ "type": ["ops", ...keys], "value": [...args] } |
let |
{ "type": "let", "value": { "bind": names, "body": term } } |
fn |
{ "type": "fn", "value": { "params": texts, "body": term } } |
call |
{ "type": "call", "value": { "fn": reference, "args": terms } } |
rec |
{ "type": "record", "value": { ...fields } } |
each |
{ "type": "each", "value": { "axis", "as", "body", "at" } } |
fold |
{ "type": "fold", "value": { "axis", "as", "init", "step", "result", "at" } } |
iterate |
{ "type": "iterate", "value": { "limit", "init", "step", "until", "result" } } |
fix |
{ "type": "fix", "value": { "name", "join", "init", "step" } } |
last |
{ "type": "last", "value": name } |
ext |
{ "type": ["ext", ...keys], "value": data } |
| a move | { "type": ["moves", kind], "value": v } |
| an axis | { "type": ["axes", name], "value": { ...parameters } } |
- DOC.ROUND-TRIP5 tests pass
fromDocument(toDocument(e))givese, if each literal is JSON data or a value of a domain withencodeanddecode. A document is JSON data, so it can go through JSON text. - DOC.TERM4 tests pass In a position that holds terms, an envelope is a term, and another JSON value is a literal. A literal with the shape of an envelope is
{ "type": "lit", "value": v }. The root of a document fromtoDocumentis always an envelope. A term has nonameand noownentries. A type can be a text, a list of keys or a reference into the world. - DOC.LITERAL4 tests pass The value of a literal has the JSON form of IR.JSON. Thus a domain value,
-0,NaNand the infinities have the forms with the key$vex. - DOC.OPS1 tests pass The type of an op is
["ops", ...keys]. The keys are the name of the op, split at its dots. The value is the list of the arguments. - DOC.REF1 tests pass A reference is a path from a root. A reference from
selfhas the moves of its address and then the segments of its path. A reference fromnameshas one step: a name of alet, a function, a loop or the caller. Vex reads from no other root. - DOC.MOVE2 tests pass The value of the move
keyorindexis a term. A text key and a number position are fixed. Another term is a computed key or position, for example a term in an envelope. A literal of another kind gives#VALUE!at run time (NAV.COMPUTED). The value ofoffsetis the list of its numbers. The value ofother,originandparentisnull. - DOC.ADDRESS4 tests pass The field
atofeachandfoldis a reference fromselfwith moves only. An empty address and no address are the same expression, and the document has no fieldatfor them. - DOC.CONSTRUCT14 tests pass The constructs
let,fn,record,each,fold,iterateandfixhave the fields of the table, and no other fields. Onlyat,asanduntilare optional.asis a list of one or two names. It needs the axislist, also insidereverseandwhere. Its two names are not the same, and a name ofinitis not a name ofas.limit,params,nameandjoinare data, not terms (DOC.LIMIT). The value oflastis the name of itsfix. - DOC.LIMIT3 tests pass The field
limitofiterateis a whole number, an envelope of the kindlimitwith a whole number, or an envelope{ "type": "size", "value": { "axis" } }. A data limit has the formsize, and its axis has the form of DOC.AXIS. A number gives the bare number when it is written. - DOC.CALL2 tests pass The field
fnofcallis a reference to a name:{ "type": "ref", "value": ["names", name] }. Thus a call applies a function that aletbinds. - DOC.AXIS3 tests pass The value of an axis is a record of its parameters, with the same names as the fields of the axis. An axis without parameters has the value
{}.listandtestare terms, andaxisis an axis. - DOC.EXT1 tests pass The type of an extension is
["ext", ...keys]. The keys are the kind, split at its dots. The value is the data, without a change. - DOC.ENTRY9 tests pass
compile,evaluate,explainandparsetake a document or an expression. For a document, they give the results of its expression.tiered,generateandemitModuleof the compiler also take a document. - DOC.ERROR14 tests pass
fromDocumentdoes not throw. A document that is not valid gives#VALUE!with the reason and its location as a JSON Pointer. A document nested deeper thanMAX_DOCUMENT_DEPTHdocuments gives#DEPTH!. The expression of a valid document is valid, as EVAL.SHAPE tells.toDocumentgives#VALUE!for an expression that is not valid, or for a literal without a JSON form. It writes an expression of any depth. - DOC.CHECK13 tests pass
VEX_WORLDgives the contract of each kind as data: the shape of its parts, the data of its fields and its names. Thecheckof the kernel reads it beforefromDocumentreads the expression. Thus the kernel finds each kind that Vex does not have, and each missing or extra field. It also finds each value of a field of the wrong type, and each part of a kind that its position does not permit. Only the grammar of Vex stays infromDocument: the steps of a reference, the address, the function of a call and the loop names.
5. Evaluation
Section titled “5. Evaluation”- EVAL.TOTAL7 tests pass The interpreter does not throw. It gives a value or an error value. A value is not
undefined. - EVAL.PURE1 tests pass An evaluation does not change any state. Two evaluations of the same expression at the same key give the same result.
- EVAL.SHAPE9 tests pass
compileandevaluatecheck the shape of the expression first, asisExprdoes. An expression that is not valid gives#VALUE!with the reason, and the evaluation does not start. For example, a node of a newer version of Vex has a tag that an older version does not know.shapeErrorgives the reason, and a sheet and the compiler give the same error. - EVAL.NESTING7 tests pass
compileandevaluateaccept an expression nested up to 500 levels deep. A deeper expression gives#VALUE!before the evaluation.isExpranddepsuse a stack, not recursion, so they accept an expression of any depth. - EVAL.DEPTH15 tests pass An evaluation in the limit of EVAL.NESTING does not fill the call stack of the engine. If host code fills the call stack, for example an extension or an op, the error is
#DEPTH!.ifError, a reduction that skips errors and#ARGSdo not hide#DEPTH!, because the engine failed, not the data. - EVAL.ORIGIN4 tests pass An origin that is not a key of the space gives
#REF!. - EVAL.LOCATION4 tests pass An error value has the path of the node that made it, and the origin and the focus of the evaluation at that node. An extension handler can give an error without an origin. Then the interpreter adds the path, the origin and the focus of the extension node.
- EVAL.COMPILE4 tests pass
compile(e, options)gives a program. Itsrunandexplaingive the same results and the same traces asevaluateandexplain. One program evaluates at each origin of each space, and one evaluation does not change a later evaluation. - EVAL.REFERENCE344 tests pass The interpreter of
@mark1russell7/vex, the compiler of@mark1russell7/vex-compilerand the reference tier give the same value or the same error code. The reference tier is the kernel of coeval.kernelPlangives the plan of a program in the kernel, with the machinevexMachine. Itsevaluateevaluates the plan. Itsreferencereads the document with the reference interpreter of the kernel, which compiles nothing.referenceEvaluateof@mark1russell7/vex-testkitusesreference. - EVAL.AGREE10 tests pass
agreeof a plan of the kernel evaluates the program withevaluate,reference, the traced evaluation of the kernel and a second evaluation. Then it evaluates the tier of the caller, when the caller gives one. It gives the result, or the first tier that gives another result. Two errors agree when they have the same code. Two values of one class agree when their fields agree.
5.1 References
Section titled “5.1 References”- REF.FOCUS2 tests pass A reference without an address reads the field at the focus.
- REF.PATH2 tests pass A path with more than one segment reads nested fields. The empty path reads the whole record.
- REF.MISSING6 tests pass A missing field, or a field with the value
null, gives#N/A. - REF.FORBIDDEN2 tests pass The segments
__proto__,constructorandprototypeare not fields. They give#N/A. - REF.ADDRESS1 tests pass A reference with an address reads at the key where the address points. A failed address gives
#REF!.
5.2 Ops
Section titled “5.2 Ops”- CALL.METHOD4 tests pass For an op without
fn, the interpreter calls the method of the receiver with the same name. - CALL.FN1 tests pass For an op with
fn, the interpreter callsfnwith the receiver and the other arguments. - CALL.UNKNOWN-OP3 tests pass An op that the domain of the receiver does not declare gives
#NAME?. An inherited member, for exampletoString, is not an op. - CALL.RECEIVER2 tests pass A receiver that no domain accepts gives
#VALUE!, if no free function has the name of the op. - CALL.FREE2 tests pass A free function applies when no domain accepts the receiver.
- CALL.PARAMS4 tests pass If an op declares the kinds of its parameters, an argument of the wrong kind gives
#VALUE!. - CALL.LIFT5 tests pass If an op declares
liftScalar, the interpreter changes each number argument into a domain value withfromScalar. - CALL.THROW2 tests pass An op that throws gives
#CALC!. The error keeps the thrown value. A full call stack gives#DEPTH!(EVAL.DEPTH). - CALL.RESULT63 tests pass An op result that is
undefinedornullgives#CALC!. A number that is not finite, or a domain value that fails thevalidcheck of its domain, gives#NUM!. - CALL.ARGS15 tests pass The interpreter evaluates all arguments. One failed argument gives its own error. Two or more failed arguments give
#ARGS, with each error as a cause. - CALL.STRING-ARGS1 tests pass A string literal is a value. The builder makes a field reference only from a bare string.
5.3 Bindings and records
Section titled “5.3 Bindings and records”- LET.BIND4 tests pass
letbinds each name to the value of its binding, for the body. - LET.LAZY-ERROR3 tests pass A binding that fails has an effect only where a
varreads it. - LET.UNBOUND2 tests pass A name without a binding gives
#NAME?. - LET.VARS2 tests pass The caller of the interpreter can give variables.
- FN.BIND5 tests pass A binding of
letcan be a function: the nodefnwith the names of its parameters and a body. The names of the parameters are distinct. A function is only the value of a binding oflet. - FN.CALL25 tests pass The node
callapplies a bound function to arguments. Each parameter gets the result of its argument at the call, and an argument that fails has an effect only where the body reads it. The body evaluates at the position of the call, with the names of the place of the binding. A parameter, a binding or a name of a loop with the name of a function hides the function. - FN.TOTAL1 tests pass A binding of
letdoes not see the other bindings of thatlet. Thus a function cannot call itself or another binding of itslet, and each call ends. - FN.ARGS1 tests pass A call with another number of arguments than the parameters gives
#VALUE!. A call of a name without a binding gives#NAME?, and a call of a value gives#VALUE!. - FN.VALUE4 tests pass A function is not a value: a
varof its name gives#VALUE!. - REC.FIELDS19 tests pass
recmakes a record of its fields. Each field is an own field of the record, also the field__proto__. Two or more failed fields give#ARGS.
5.4 Axes
Section titled “5.4 Axes”- AXIS.ALL1 tests pass The axis
allhas each key of the space as a target. - AXIS.OTHERS1 tests pass The axis
othershas each key except the focus as a target. - AXIS.OTHERS.ORIGIN1 tests pass Inside an axis, the focus is the target, and the origin does not change. A value bound outside the axis keeps its value. Thus a base value from the origin and a field of the target can meet in one body.
- AXIS.OTHER.PAIR1 tests pass The axis
otherhas the other key of a pair as a target. Outside a pair, it gives#REF!. - AXIS.NEIGHBORS2 tests pass The axis
neighbors(4)orneighbors(8)has the neighbor cells of the focus in a grid as targets. Outside a grid, it gives#REF!. - AXIS.TREE10 tests pass In a tree space, the axis
childrenhas the children of the focus as targets, in key order.ancestorshas the parent first and the root last.descendantshas each key under the focus, depth first, with each parent before its children.siblingshas the other children of the parent, or the other roots for a root. In a space that is not a tree, each of these axes gives#REF!. - AXIS.WINDOW5 tests pass The axis
window(from, to)has the targets of the movesoffset(d)for each whole numberdfromfromtoto, in order. The offset 0 is the focus, and an offset outside the space has no target. In a tree space, the offsets go among the siblings. In a space where an offset with one number is not valid, the axis gives#REF!. - AXIS.REVERSE5 tests pass The axis
reverse(axis)has the targets ofaxisin the reverse order, from the last to the first. The inner axis is a base axis: notwhere,reverseortable. A test goes outside it:where(reverse(axis), test). A fold over it starts at the last target, and an error of the inner axis is the error of the reverse order. - AXIS.LIST16 tests pass The axis
list(expr)has the keys of the items of the list thatexprgives as targets, in the order of the list.exprevaluates at the key of the address, before the targets. A value that is not a list gives#VALUE!. An error item gives an error item for its target. A key that is not in the space has no record. The axisreversecan contain the axislist. - AXIS.LIST.ITEM8 tests pass In
eachorfoldover the axislist, the fieldas: [item]binds the nameitemto the value of the item of each target. An error item gives an error item for its target, as AXIS.LIST tells. There, the body or the step does not evaluate, and the names bind nothing. In a fold, that error is the value of the fold. - AXIS.LIST.INDEX7 tests pass The second name of
as: [item, index]binds the position of the item, from 0, asnthcounts. LIST.LENIENT applies: the error items do not count. Thusnth(list, index)gives the item. Underreverse, the index is the position in the list, not in the order of the loop. - AXIS.LIST.SCOPE13 tests pass The names of
asare visible only inbodyand in eachstep. They hide an outer name of the same name. The test ofwhere, the list, the address,initandresultdo not see them. There, the name refers to the outer binding, or gives#NAME?. - AXIS.TABLE7 tests pass The axis
table(name)has each key of the tablenameof the evaluation as a target, in key order. Its body and its test evaluate in the space of that table, and there the origin is the target. A value of the space of the origin goes in through a variable. An evaluation without that table gives#REF!. - AXIS.GRAPH7 tests pass In a graph space, the axis
successorshas the ends of the edges from the focus, in the order of the edges.predecessorshas the keys with an edge to the focus, in key order.reachablehas each key that a path of one or more edges reaches, once, in the order of a breadth-first search, without the focus. In a tree space, the edges go from a parent to its children. In another space, each of these axes gives#REF!. - AXIS.WHERE5 tests pass The axis
where(axis, test)keeps the targets ofaxiswheretestgivestrue. A test that fails, or that does not give a boolean, gives an error item for that target. - AXIS.OTHERS-UNION1 tests pass The targets of
othersand the focus are the targets ofall. - AXIS.OTHER-TWICE1 tests pass In a pair, the address
[other, other]points to the focus. - AXIS.ADDRESS3 tests pass An axis with an address finds its targets from the key where the address points, not from the focus. A failed address gives
#REF!. Inside the body, the focus is the target, and the origin does not change. - AXIS.ADDRESS-EXTEND1 tests pass Let
kbe the key of the address. For a body that does not read the origin, the axis gives the same list as the axis at origink. - AXIS.EXTEND1 tests pass For an expression that does not read the origin, the item at key
kofeach(all, e)equalseevaluated at origink. This is the law of a comonad: extract after extend gives the program.
5.5 Lists
Section titled “5.5 Lists”- LIST.LENIENT16 tests pass A list op skips error items by default. With
{ strict: true }, the first error item is the result. - LIST.OPS16 tests pass
listOps(options)gives the list ops ofcompilefor the values of a host, on a list and on an array (LIST.ARRAY). Each op gives the result ofevaluate. An error of the op has the position and the path of the call. An error of an item stays as it is. - LIST.EMPTY6 tests pass
min,max,meanandfirstof an empty list give#N/A.sumgives 0 andcountgives 0. Forreduce, refer to LIST.REDUCE.EMPTY. - LIST.REDUCE.EMPTY1 tests pass An empty
reducegives the identity of the op, if exactly one domain has an identity for the op. If more domains have one, it gives#N/A, and the optiondomainnames the domain to use. An unknown domain name gives#NAME?. - LIST.KINDS3 tests pass
sum,mean,minandmaxneed numbers.any,allandnoneneed booleans. A value of another kind gives#VALUE!. - LIST.REDUCE3 tests pass
reducefolds the values from the left with a domain op. For an associative op, any order of reduction gives the same value. - LIST.VALUE3 tests pass A list is a value. A
letcan bind it, and a list op applies to a name of a list. - LIST.SHAPE4 tests pass A value is a list only if its kind is
vex.listand each item has a textkeyand a result. A result is{ ok: true, value }with a value that is notundefined, or{ ok: false, error }with an error value. An error value has a textcode,kindandmessage, and apath. Another value with the kindvex.listis a record, so no list op applies to it. - LIST.SORT12 tests pass
sortBy(list)gives a list with the items in the order of their values, from the smallest. The sort is stable. The values are all numbers withoutNaN, or all texts. Texts compare by their UTF-16 code units. Another value gives#VALUE!. - LIST.SORT.BY12 tests pass
sortBy(list, { by: name })sorts the items by the result of the opnameon each value, as LIST.SORT tells, and keeps their keys and values. The op comes from the first domain that accepts the value and has the op, as forreduce. LIST.LENIENT applies before the op, so{ strict: true }gives the first error item. The op applies in the order of the list, and its first error is the result. A value without the op gives#NAME?, and anamethat is not a text gives#VALUE!. An empty list gives an empty list, and no op applies. - LIST.TAKE2 tests pass
take(list, n)gives a list of the firstnitems. A largerngives each item. - LIST.NTH4 tests pass
nth(list, i)gives the value of the item at the positioni, from 0. A position after the last item gives#N/A. Fortakeandnth, a number that is not a whole number from 0 gives#VALUE!. - LIST.SETNTH6 tests pass
setNth(list, i, value)gives a list with the valuevalueat the positioni, from 0, asnthcounts. The item at the position keeps its key. Each other item keeps its key and its value. The list that the op reads does not change. A position after the last item gives#N/A, and the op adds no item. A number that is not a whole number from 0 gives#VALUE!. A missing value gives#VALUE!. The value can be any value, also a list. LIST.LENIENT applies: by default, an error item is not in the new list, and the position does not count it. With{ strict: true }as the fourth argument, the first error item gives its error. - LIST.DROP3 tests pass
drop(list, n)gives a list of the items after the firstnitems. A largerngives an empty list. As fortake, a number that is not a whole number from 0 gives#VALUE!. - LIST.APPEND4 tests pass
append(list, other)gives a list of the items oflistand then the items ofother. Two items can have the same key. - LIST.WITHOUT3 tests pass
without(list, other)gives a list of the items oflistwhose key is not the key of an item ofother. - LIST.FLAT5 tests pass
flat(list)gives a list of the items of the lists that are the values of the items oflist, in order. A value that is not a list gives#VALUE!. - LIST.BUILD15 tests pass An item of a list from
sortBy,take,drop,append,withoutorflatkeeps its key and its value. LIST.LENIENT applies to each list that the op reads: by default, an error item is not in the new list. With{ strict: true }, the first error item oflistis the result, and then the first error item of the other lists, in order. The argumentothermust be a list, and another value gives#VALUE!. - LIST.GET12 tests pass
get(list, key)gives the value of the first item with the keykey. A key that no item has gives#N/A, and a key that is not a text gives#VALUE!. LIST.LENIENT applies: by default, an error item is not an item of its key. With{ strict: true }, the first error item of the list is the result. - LIST.LITERAL13 tests pass A literal can be a list. Its JSON form is the form of
vexList:{ "kind": "vex.list", "items": [...] }, and each item has akeyand the result{ "ok": true, "value": v }. Thus the empty list and a list with one key are literals. A literal of the kindvex.listwith an item of another form is a record (LIST.SHAPE). - LIST.ARRAY25 tests pass An array is a list where a list op or the axis
listneeds a list. The key of each item is its position, from"0", and its value is the value at the position. A position without a value, or withnull, gives an error item of#N/A, as REF.MISSING tells. A list op applies to an array only when no domain and no function of the host has the op for the array. Thus each result of a domain or of a function stays. The second list ofappendandwithout, and each list offlat, can be an array too. - LIST.INDEXOF7 tests pass
indexOf(list, value)gives the position of the first item with the valuevalue, from 0, asnthcounts. LIST.LENIENT applies. A value that no item has gives#N/A. The value must be a number, a text or a boolean, and===compares it. Another value gives#VALUE!. - LIST.INCLUDES8 tests pass
includes(list, value)givestruewhen an item equalsvalue, and elsefalse. The opeqof the first domain that acceptsvaluecomparesvaluewith each item in order, and the firsttruestops the walk. An error ofeqis the result, and a result that is not a boolean gives#VALUE!. A value without such an op gives#NAME?, also for an empty list, and a missing value gives#VALUE!. LIST.LENIENT applies, and an empty list of a value witheqgivesfalse. As for LIST.ARRAY, a domain or a function of the host with the opincludescomes first on an array. - LIST.DISTINCT4 tests pass
distinct(list)gives the first item of each value, in the order of the list, with its key. LIST.LENIENT applies. Each value must be a number, a text or a boolean, and another value gives#VALUE!.===compares the values, as forindexOf. Thus eachNaNstays. - LIST.GROUP6 tests pass
group(list, keys)gives one item for each distinct text ofkeys, in the order of its first position. The value of the item is the list of the items oflistat the positions of its text. The item at a position has the key at the same position ofkeys, so both lists must have the same number of items. Another number gives#VALUE!.keyscan be an array, as LIST.ARRAY tells. LIST.LENIENT applies to both lists, first tolist. A position with an error item or an error key is not in a group. A key that is not a text gives#VALUE!. The groups are lists, not functions, so FN.VALUE stays true. - LIST.JOIN4 tests pass
join(list, sep)gives the texts of the items, in order, with the textsepbetween them. An empty list gives the empty text. LIST.LENIENT applies. Asepthat is not a text gives#VALUE!, and so does an item that is not a text. A domain or a function of the host with the op comes first on an array, as LIST.ARRAY tells. - LIST.FILL11 tests pass
fill(n, value)gives a list ofnitems with the valuevalue. The key of each item is its position, from"0".nmust be a whole number from 0 to 100000, and another value gives#VALUE!. A missing value gives#VALUE!. As for LIST.ARRAY, a domain or a function of the host with the opfillcomes first.
5.6 Special forms
Section titled “5.6 Special forms”- FORM.IF3 tests pass
ifevaluates only the branch that its condition selects. A condition that is not a boolean gives#VALUE!. - FORM.AND-OR1 tests pass
andandorstop at the first argument that decides the result. - FORM.IFERROR5 tests pass
ifErrorgives its first argument, or its second argument when the first is an error.
5.7 Iteration
Section titled “5.7 Iteration”-
LOOP.NAMES9 tests pass
foldanditeratebind the names of their recordinitto its values, at the node. A step evaluates each expression of the recordstepwith the values before the step. Then each name ofstepgets its new value, and the other names keep their values.resultevaluates at the node with the last values, and it gives the value. A name ofstepthat is not a name ofinitmakes the expression not valid. -
FOLD.ORDER3 tests pass
foldmakes one step at each target of its axis, in the order of the axis. The focus of a step is the target. A target that a test ofwhereremoves has no step. The tests evaluate before the steps, so a test cannot read the names of the fold. -
FOLD.ERROR3 tests pass The first error of a value, of a test or of
resultis the value of the fold. A test that is not a boolean gives#VALUE!. -
ITERATE.LIMIT5 tests pass
iteratemakeslimitsteps at the position of the node.limitis a whole number from 0 to 100000 in the expression, or a data limit (ITERATE.LIMIT.DATA). -
ITERATE.LIMIT.DATA50 tests pass A data limit is a record with the one field
axis. The limit is the number of targets of the axis, soiteratemakes the steps of afoldover that axis. The axislistgives the count of a list. The limit evaluates one time, afterinitand before the first test ofuntil, at the position of the node. It reads the names outside the loop, and not the names of the loop. LOOP.SIZE reads a data limit as it reads the axis of afold. Thus a limit that reads a list of an outer loop is a use of that list. -
ITERATE.LIMIT.ERROR22 tests pass A data limit that is not valid gives
#NUM!of the kindlimit, andcausesholds the inner error. These limits are not valid: an axis that the run cannot read, a value that is not a list, and a count above 100000. An error of a list, of an item or of a test also makes the limit not valid.#DEPTH!and#CYCLE!stay as they are, because they stop the run and do not come from the limit (EVAL.DEPTH, SHEET.CYCLE). If items give both,#DEPTH!decides. -
ITERATE.UNTIL4 tests pass With
until, the test evaluates before each step and after the last step. A true test stops the iteration. With no true test, the value is#NUM!. A test that is not a boolean gives#VALUE!. -
ITERATE.ERROR3 tests pass The first error of a value, of the test or of
resultis the value of the iteration. -
LOOP.LIST17 tests pass A name of
foldoriteratecan hold a list (LIST.VALUE). A step gives a new list from the values before the step, for example withappend,drop,setNthandwithout. Thus a list can be the stack or the seen set of a search, or the positions of a layout. A step reads the old value at a key withget(LIST.GET). -
LOOP.SIZE115 tests pass The size of a value of a loop has a bound that is a polynomial of the number of steps. A value does not grow by a factor at each step. The size of a list or a text includes its items and characters. A step gives each name a new value. Each sum of the bound of that value uses the old lists and texts of the loop at most one time (LOOP.SIZE.BRANCH). For example, a step with
append(xs, xs)usesxstwo times, and it doubles the list at each step.A nested loop or
eachreads an item at each step or target. Thus a body with one copy of its item uses the list one time (LOOP.SIZE.COPY). A body that holds another list of the loop uses that list many times. A function counts the uses of its arguments. A value from outside the loop is a constant, soappend(xs, outside)is valid. A chain of names that grows by a factor at each step is not valid.compilerefuses an expression that breaks this rule with#VALUE!, and so do tier 2,emitModuleandvex_check. The reason names the loop, the name and the op. -
LOOP.SIZE.BRANCH4 tests pass The bound of a value is the largest value of at most eight sums.
ifandifErrorgive the larger of two values, not their sum, so a step can swap two names in anif. A sum with no name of a cycle of the loop sets a value again, so it does not add at each step. A sum that another sum covers does not count. A bound with more than eight sums becomes one sum that covers each of them. -
LOOP.SIZE.COPY7 tests pass A step can copy a list of the loop item by item. In
fold(list(xs), { acc: empty }, { acc: append(acc, fill(1, it)) }, acc), the nameacchas the bound ofxs. Thus a loop overappend(xs, fill(1, n))is valid. A step that appends two copies of each item doubles the list, so it is not valid. -
LOOP.SIZE.OPS12 tests pass Each op that can give a list or a text has a size rule as data. The rule is the property
sizeof the op, orsize: "fixed"of its domain. A function of the host has a rule in its propertysize. An op with no rule that gets a value of the loop makes the loop not valid, and the reason names the op. -
LOOP.SIZE.SETNTH6 tests pass The size rule of
setNthcounts the list one time and the value one time. The bound keeps the old item, because a bound cannot subtract. The count of the items does not grow. The largest item is the larger of the old largest item and the value. An item of the list is the measure of the largest item, not the size of the list. ThussetNth(xs, i, add(nth(xs, i), 1))is valid, asappend(xs, fill(1, nth(xs, i)))is. A value that holds the list uses the list two times, sosetNth(xs, 0, xs)is not valid. A value that holds two old items doubles the largest item, sosetNth(xs, 0, append(nth(xs, 0), nth(xs, 0)))is not valid. -
LOOP.SIZE.PART14 tests pass A value has a fifth measure: its largest part, the largest item of an item. The items of a record are its fields. A field of an item has the size of a part of the list. Thus a record from the fields of one item does not grow the parts. Thus
setNth(xs, 0, rec({ a: field(nth(xs, 0), "a"), b: field(nth(xs, 0), "b") }))is valid. A record of two whole items is not valid, because a part of the new item is an old item.takewith a literal limit has the bound of that number of the largest item. Thusappend(take(xs, 2), take(xs, 3))is valid. The same bound holds for the items ofeach. It does not hold for a list with long keys, because a key is not in the bound of an item. A size rule gives the largest part in its propertypart. Its uselimitreads the literal number at the positionlimitof the op. -
LOOP.SIZE.READINGS9 tests pass The check reads a program two times, and one reading that accepts the whole program makes it valid. The first reading counts a part as a whole item, and it counts a fixed number of items as the whole list. The second reading keeps the parts and the rules
byParts. Neither reading covers the other. In the first readingfill(1, take(xs, 3))has a list of one item, and in the second reading it holds three old items. The reason of a refusal comes from the first reading.
5.8 Steps
Section titled “5.8 Steps”A step is a level of the power of the language. A host sets the highest step that it accepts.
- STEP.LADDER11 tests pass The steps of Vex are A, B and C, from the lowest to the highest. Step A has loops with a fixed count. Step B adds limits from the data, and fixed points whose steps move one way. Step C adds functions that call themselves, with a budget. Each construct has a step as data in
CONSTRUCT_STEPS. The data limit ofiterateis the constructiterate.size, of step B. Each other construct is of step A. - STEP.LOWEST3 tests pass The step of a program is the highest step of its nodes. The reason is the first node with that step, in the order of
children, with its construct and its path.programStepgives the step and the reason. - STEP.MAX11 tests pass The host option
maxStepsets the highest step that the host accepts. The default is B. A program abovemaxStepis not valid.compile, tier 2,emitModuleandvex_checkrefuse it, and the reason names the needed step. A program has no field for its step, so a document cannot raise its own step. A value ofmaxStepthat is not a step is not valid. The default B fails closed. Each construct of step B has a bound of cost from the size of the input. Each construct of step A has one too (LOOP.SIZEand the evaluation budget). A construct without such a bound has step C. - STEP.VALUE5 tests pass The option
maxStepchanges only which programs the host accepts. Each accepted program gives the same value at each step. LOOP.SIZE, EVAL.PURE and P17 hold at each step. - STEP.CYCLE2 tests pass A cycle of cells without an explicit fixed point gives
#CYCLE!at each step. - STEP.TOOLSstatus unknown
vex_checkgives the step of the program and the reason.vex_explaingives the step at the root, on the first line of the trace.
5.9 Fixed points
Section titled “5.9 Fixed points”The node fix makes a column: one value for each row of the space. It repeats a step until no row changes. Each step moves each row one way, so the rounds stop, and the result does not depend on the order of the rows. The construct is of step B.
- FIX.ROUNDS9 tests pass
initevaluates at each row, and it gives round 0. Roundrevaluatesstepat each row, and each read sees only roundr - 1. The first round with no changed row ends the rounds. The value of the node is the row of the focus. - FIX.ROWS3 tests pass The rows are the keys of the space where the node evaluates. In a body of the axis
table, they are the keys of that table. The focus ofinitand ofstepis the row. The origin stays the origin of the node, so a read of the origin gives one source for all the rows.depsgives the axisallaround the reads ofinitand ofstep. - FIX.JOIN4 tests pass
joinisor,and,maxormin. The next value of a row is the join of its old value and the value ofstep. The joinsorandmaxmove a row up. The joinsandandminmove a row down. Thusjoindeclares the direction of the column. - FIX.KIND5 tests pass The values of
orandandare booleans. The values ofmaxandminare finite numbers. A value of another kind gives#VALUE!. A number that is not finite gives#NUM!. - FIX.LAST6 tests pass The node
lastgives the value of the focus in the last round of thefixwith the name. The innerfixof a name hides an outer one. Alastbelongs in thestepof afixwith its name. Each otherlastis not valid. The names offixare not names oflet, sovardoes not read a column. An axis moves the focus of a read. A focus that is not a row gives#REF!. - FIX.MONOTONE12 tests pass A program is valid only if the check proves that each
stepdoes not fall when the last round rises, for each join. A proof comes only from FIX.OPS and from these rules. The startinitdoes not read the last round.ifhas a test that does not read the last round. A branch ofif, an argument ofand,orandifError, a binding ofletand a body ofeachcan read it. The axis, the address and the tests ofeachdo not read it, and the body of the axistabledoes not read it. Each other node with a part that reads the last round has no proof. These nodes are a record, a move of a reference,fold,iterate, a call, and afixthat reads an outerfix.compile, tier 2,emitModule, the kernel andvex_checkrefuse a program without a proof, and the reason names the part. - FIX.OPS11 tests pass An op has a direction for each argument as data, in the property
monotoneof its spec:upordown. A function of the host states it in the same property. The list opsany,all,minandmaxhaveupfor the list, andnonehasdown. The first argument of an op that reads the last round has a known kind, because the kind selects the op. An op without a rule cannot take a value that reads the last round. The direction of an op is a law. The op does not fall when anupargument rises. It does not rise when adownargument rises. - FIX.LIMIT7 tests pass A column of
nrows makesn + 1rounds at most, and 100000 at most. A boolean column stops in this limit. A number column stops in it when its steps follow paths, because a path has fewer rows than the column. A column that still changes in the last round gives#NUM!of the kindlimit, and no value of a row. A host option does not change the limit (STEP.VALUE). A step can set a cap withminormax. - FIX.ERROR11 tests pass Each row evaluates in each round, also after an error of another row. One failed row gives its error, and two or more give
#ARGSwith each error as a cause.#DEPTH!wins over each other error (EVAL.DEPTH), and#CYCLE!wins next (SHEET.CYCLE). An error of a row fails the column, solastdoes not read an error. A row catches its own error withifError. - FIX.ORDER3 tests pass The rounds do not read the order of the rows. Each round reads only the last round, and an op that reads the order of the items has no rule.
sumhas no rule too, because the rounding of floats depends on that order. A part that does not read the last round can read the order, as in each program. - FIX.TRACE3 tests pass
explainrecords an event for each round after the event of its reads. The fieldroundholds its count from 0 and the keys of the rows that it changed. The result of the event is the column as a list. The node then records its usual event.
6. Folds
Section titled “6. Folds”- TRACE.EVENTS11 tests pass
explainrecords one event for each node evaluation, in the order that the nodes finish. A reference event records its reads. - TRACE.AXIS1 tests pass Inside an axis, the focus of each event is the target.
- DEPS.READS13 tests pass
depsgives each reference of an expression, with its address, the axes around it and the address of each axis. The static kit of the kernel finds the references of the document of the expression (refsOf). The contracts give the names that each kind binds. Vex adds the axes and the reads of a function at each of its calls. - DEPS.COMPUTED1 tests pass A computed move keeps its expression in the address that
depsgives. Only a run knows its key.depsalso gives the references of that expression, with the axes around its node.
7. Domains
Section titled “7. Domains”- DOMAIN.OWNED3 tests pass A domain owns its op table.
defineDomaindoes not change a class or a prototype, and an import has no side effects. - DOMAIN.LAWS12 tests pass Each law that a domain declares holds for the values of the domain.
@mark1russell7/vex-testkitchecks each law with property tests. - KIND.PRIMITIVE3 tests pass A domain with
primitiveaccepts each value of that JavaScript type, and no other value. The law checker of the test kit checks it. - KIND.RETURNS6 tests pass An op with
returnsgives a result of that kind, or an error. The law checker checks each such op on random values. The kinddomain:Nameis a value of the domainName, for example the opxyofNumDomaingives a value ofXYDomain. The law checker checks such an op when its optiondomainshas that domain. - KIND.RETURNS.LIST3 tests pass The kind
list:number,list:stringorlist:booleanis avex.listwith items of that primitive type. An error item does not break the kind. The law checker checks such an op on random values.
7.0 The ops codePoints and epochMillis of TextDomain
Section titled “7.0 The ops codePoints and epochMillis of TextDomain”- TEXT.CODEPOINTS16 tests pass
codePoints(text)gives a list of numbers with one item for each code point of the text, in order. The key of an item is its position, from"0". A pair of surrogates is one item, and a lone surrogate is an item with its own value. The empty text gives the empty list. The op has the kindlist:number. A receiver that is not a text has no op. - TEXT.EPOCHMILLIS7 tests pass
epochMillis(text)reads an ISO 8601 time and gives the number of milliseconds since1970-01-01T00:00:00Z, so the ops of numbers compare two times. The text isYYYY-MM-DD, orYYYY-MM-DDTHH:MM, an optional:SSand an optional fraction, thenZor an offset±HH:MM. Atand azin lower case are the same asTandZ(RFC 3339 §5.6). A date alone is 00:00 UTC of the day. Only the first three digits of a fraction count, so the op cuts a fraction to milliseconds and does not round it. A time withoutZor an offset gives an error, because a local time depends on the computer (EVAL.PURE). Any other text gives#CALC!, also a day or an hour that does not exist, for example2026-02-30.
7.1 The axes of Vec2Domain
Section titled “7.1 The axes of Vec2Domain”A layout rule often works along a main axis and a cross axis, for example the total of a stack. A unit axis dir is (1, 0) for a row or (0, 1) for a column. These ops let one program serve both dimensions.
- VEC2.ALONG2 tests pass
along(v, dir)givesdot(v, dir): the component ofvalong the unit axisdir.across(v, dir)givesdot(v, swap(dir)): the component on the other axis. On the axis (1, 0),alonggives x andacrossgives y. - VEC2.COMPOSE4 tests pass
compose(dir, main, cross)givesdir * main + swap(dir) * cross. On a unit axis,alongof the result givesmain, andacrossof the result givescross. - VEC2.SELECT3 tests pass
select(mask, a, b)gives the component ofawhere the component ofmaskis not 0, and the component ofbwhere it is 0. A number argument becomes a vector with that number twice. - VEC2.FINITE3 tests pass A
Vec2with a component that is not finite is not valid, so an op that gives one gives#NUM!. Thus a bound cannot be infinite. An open bound usesselect:select(vec2(0, 1), max(v, lo), v)bounds only y, andselect(hi, min(v, hi), v)sets no bound wherehihas a 0.
7.2 The domain JsonDomain
Section titled “7.2 The domain JsonDomain”JsonDomain of @mark1russell7/vex-domains reads JSON data, for example the documents of a database. Each op is a function of plain data, so a standalone module can copy it. Put JsonDomain last in the list of domains. Then add, eq and the other ops of NumDomain, TextDomain and BoolDomain come first. The names keys, get and values are list ops, so the domain does not use them.
- JSON.IS2 tests pass
JsonDomainaccepts a text, a finite number, a boolean, an array and a plain object. A plain object has the prototypeObject.prototypeornull. A list of Vex and the value of a class are not JSON values. - JSON.KIND1 tests pass
kind(v)gives the kind of a JSON value:"boolean","number","string","array"or"object". - JSON.KINDS2 tests pass
kinds(c)gives the kind of each item of an array, in order, or of each field of an object, in the order offields. Anull, anundefinedor a hole gives"null". The result is an array with the repeats, and the list ops read it (LIST.ARRAY). An item that is not a JSON value gives#CALC!. - JSON.FIELDS1 tests pass
fields(o)gives the keys of the objecto, in the order ofObject.keys. An array or another receiver that is not an object gives#CALC!. - JSON.LEAVES4 tests pass
leaves(o, depth)gives the leaves of the objecto, in the order of a walk over its own fields, asfieldsreads them. The walk goes into an object with fields when the path of its field has fewer thandepthkeys. Each leaf is a record{ path, kind, value }with the kind ofkinds, and a"null"leaf has novalue. A path joins the keys with., but after an empty path it is the key alone. A numberdepththat is not a whole number from 1 to 100 gives#CALC!. A receiver that is not an object, and a value that is not JSON, give#CALC!too. - JSON.FIELD1 tests pass
field(o, k)gives the value of the own fieldkof the objecto. A missing key, a field that isnull, a key that is not a text and a receiver that is not an object give#CALC!. Thus an inherited member, for exampleconstructor, is not a field.
7.3 The sign and the smallest axis
Section titled “7.3 The sign and the smallest axis”A force separation pushes two boxes apart along the axis of their smallest overlap, with the sign of their gap. For the overlap o and the gap g, the push is minAxis(o) * sign(g) * o. A gap of 0 on that axis gives no push.
- NUM.SIGN4 tests pass
sign(n)gives the value ofMath.sign(n): 1 for a positive number, -1 for a negative number, 0 for 0 and -0 for -0. An infinite number gives 1 or -1, because an op checks its result and not its receiver.NaNgives#NUM!. - VEC2.SIGN6 tests pass
sign(v)ofVec2Domaingives the sign of each component, as NUM.SIGN tells. A componentNaNgives#NUM!, as VEC2.FINITE tells. An infinite component gives 1 or -1. - VEC2.MINAXIS10 tests pass
minAxis(v)gives (1, 0) ifx <= y, else (0, 1). The comparison uses the signed values, andminAxis(abs(v))compares the sizes. A tie gives (1, 0), and 0 and -0 tie. Infinite values compare as numbers. A componentNaNgives#NUM!. For finite components,along(v, minAxis(v))givesminComponent(v), andacross(v, minAxis(v))givesmaxComponent(v). - XY.SIGN5 tests pass
signandminAxisofXYDomaingive the components of the same ops ofVec2Domain. Each one is a function of plain data, so a standalone module can copy it.
7.4 The domain InsetsDomain
Section titled “7.4 The domain InsetsDomain”InsetsDomain of @mark1russell7/vex-domains keeps the four sides of an inset as plain data, so a module can copy it. start is the pair of the leading sides, and end is the pair of the trailing sides.
- INSETS.VALUE4 tests pass A value is a plain object with exactly the number fields
startX,startY,endXandendY.insets(startX, startY, endX, endY)ofNumDomainmakes a value. PutInsetsDomainbeforeNumRecordDomain, which accepts the same objects. - INSETS.LIFT3 tests pass A number in the argument of
addbecomes a value with four equal sides. A number as the receiver stays a number. Thusinsets(0, 0, 0, 0).add(pad)takes a number or a value, with no test of the type. - INSETS.SIDES3 tests pass
startX,startY,endXandendYgive one side.startgives theXYvalue (startX,startY), andendgives (endX,endY). A box inset addsstartto the corner, and it subtractsstartandendfrom the size. - INSETS.VEC24 tests pass
startVec2andendVec2give the same pairs asVec2values, for a program ofVec2Domain. A module cannot copy the classVec2, so it refuses these two ops with a reason. - INSETS.ARITH3 tests pass
addadds each side, and its identity isinsets(0, 0, 0, 0).scale(i, k)multiplies each side byk, soscale(i, -1)gives the outset ofi. - INSETS.FINITE3 tests pass A value with a side that is not finite is not valid, so an op that reads or gives one gives
#NUM!. An inset with an infinite side has no box, as VEC2.FINITE has no vector.
7.5 The domain QuantityDomain
Section titled “7.5 The domain QuantityDomain”QuantityDomain of the entry @mark1russell7/vex-domains/quantity keeps an amount in a unit as plain data. The package @mark1russell7/quantity does the unit arithmetic, and it converts each amount exactly. The entry is apart from the main entry, so a bundle without amounts does not get the unit tables.
- QTY.VALUE5 tests pass A value is a plain object with exactly the fields
valueandunit.valueis a number, andunitis the canonical spelling of a unit of@mark1russell7/quantity. Thus{ value: 2, unit: "hr" }is not a value, and the decoder of a document gives{ value: 2, unit: "h" }for it. PutQuantityDomainbeforeJsonDomain, which accepts the same objects. - QTY.FINITE1 tests pass A value that is not finite is not valid, so an op that gives one gives
#NUM!. Thus a division by 0 gives#NUM!. - QTY.COMPARE3 tests pass
lt,lte,gt,gte,eqandcomparecompare two amounts of one kind exactly, each in its own unit. Thuslteof 155 mm and 16 cm istrue.minandmaxgive the result in the unit of the receiver. - QTY.ARITH6 tests pass
addandsubtractgive the result in the unit of the receiver, exactly for decimal inputs.multiplyanddividetake a number.ratiodivides two amounts of one kind, and it gives a number. No op lifts a number, because a number has no unit. - QTY.KIND1 tests pass Two amounts of different kinds, for example a length and a mass, give
#CALC!with the reason of@mark1russell7/quantity. A unit ofconvertorvalueInwith another kind, or a unit that does not exist, gives#CALC!too. - QTY.CONVERT2 tests pass
convert(a, unit)gives the amount in another unit of the same kind, andvalueIn(a, unit)gives its number.value,unitandkindgive the parts of an amount.
8. The builder
Section titled “8. The builder”- BUILD.IMMUTABLE2 tests pass A builder call gives a new chain. An earlier chain does not change.
- BUILD.AXIS.ADDRESS1 tests pass The moves before an axis are the address of the axis. Thus
parent().children(f)evaluatesfat each child of the parent. - BUILD.LIST.KEYS1 tests pass A list chain has
keys()anderrors().keys()gives the keys of the items with a value, in the order of the axis.errors()gives the error of each item that failed. - BUILD.IF1 tests pass
if(then, otherwise)on a boolean chain gives the formif: the expression isapp("if", value, then, otherwise). - BUILD.LIST.READ1 tests pass A list chain gives its list at an origin with
result,atandexplain, like a chain. Each item has the key of its target and its result. - BUILD.FN9 tests pass
root.fn(kinds, body)makes a function with the kinds of its parameters.functions(fns, body)of a chain binds the functions, andcallgives a chain of a call of each function. - BUILD.LIST.ORDER9 tests pass A list chain has
sortBy,takeandnth. Its methodeach(body)is the axis list over its items.foldneeds the list of an axis. - BUILD.LIST.BUILD9 tests pass A list chain has
drop(n),append(other),without(other)andflat().otheris a list chain, and another value makes the builder throw aTypeError. The body of an axis can give a list chain. Then the value of each item is a list, and only such a list chain hasflat. - BUILD.LIST.GROUP1 tests pass A list chain has
distinct(),group(keys)andjoin(sep).keysis a list chain of texts, and another value makes the builder throw aTypeError.groupgives a list chain whose items are lists.joinneeds a list chain of texts, andsepis a text or a chain of a text. - BUILD.LIST.LOOP3 tests pass In
iterateandfold, a name whose first value is a list chain is a list chain instep,untilandresult. Its next value must be a list chain with items of the same type. A list chain asresultgives a list chain.root.list(items)gives a list literal, and a list chain hasget(key). The key is a key of the space or a chain of a text. - BUILD.LIMIT3 tests pass The limit of
iteratein the builder is a number, aDataLimitfromdataLimit(axis)or a list chain. A list chain gives a data limit over the axislist. - BUILD.LIST.ITEM3 tests pass In
eachof a list chain, the body also gets a chain of the item and a chain of its index (AXIS.LIST.ITEM, AXIS.LIST.INDEX). In a fold over the axislist, the step also gets the index after the item. The builder writesasonly with the names that the body or the step reads. A loop inside a body or a step gets other names. Another axis has no index, so a step that reads it makes the builder throw aTypeError. - BUILD.FIX10 tests pass
fix(name, join, init, step)of a chain gives the nodefix(FIX.ROUNDS), and the chain has the kind of the join.stepgets a chain oflast, so a program of the builder has no read outside astepof its column. A chain oflastthat leaves itsstepgives the error of FIX.LAST. A column inside astephas another name in the node, so it does not hide the column around it. - BUILD.CALL3 tests pass
call(name, ...args)applies a free function ofwithOptions: the expression isapp(name, value, ...args). A domain op with the same name for the value comes first at run time. - TYPE.FROM1 tests pass
from(p)accepts only the fields of the record type, and the chain value has the type of the field. - TYPE.OPS1 tests pass
._has only the ops of the domain of the current value, with the parameter types of each op. - TYPE.LIFT3 tests pass A number argument for a domain parameter needs
liftScalaron the op. - TYPE.STATE1 tests pass After an op gives a value that no domain of the chain accepts, the chain has no
._. - TYPE.OTHER1 tests pass
other()exists only on a chain over a space with two keys, or with keys that the compiler does not know. - TYPE.KEYS1 tests pass Evaluation accepts only the keys of the space.
- TYPE.LIST1 tests pass A number reduction needs a list of numbers.
- TYPE.NO-ANY1 tests pass No value type of the builder is
any. - TYPE.CALL1 tests pass
callaccepts only the names of the free functions whose first parameter accepts the current value. The other arguments have the types of the other parameters, and the chain value has the return type of the function.
9. Sheets
Section titled “9. Sheets”A sheet has named columns of formulas over a space. A cell is one column at one key. A formula reads a cell with a cell reference: the extension node ext("vex.cell", { column, at }).
- SHEET.CELL19 tests pass A cell reference resolves its address from the focus, then gives the result of that cell. An unknown column gives
#NAME?, and an address outside the space gives#REF!. The data of a cell reference has only fixed moves. - SHEET.CELL.COMPUTED11 tests pass
cell(column, at)takes computed moves (NAV.COMPUTED). An address of fixed moves gives a cell reference. Another address givesfirst(each(window(0, 0), cell(column), at), { strict: true }), so the form has no new node. A read gives the error of its cell, of an expression or of a move. The axiswindowneeds an array space or a tree space, so another space gives#REF!. - SHEET.CELL.COMPUTED.ORDER4 tests pass A read with a computed move keeps
SHEET.ORDER. The run finds the cell of the read when it evaluates the read, so a cycle that only the values make gives#CYCLE!. The expressions evaluate before the first move, so a failing move does not stop a read of a cell in an expression. - SHEET.CELL.FORMULA6 tests pass A cell can have its own formula. That formula replaces the formula of its column at its key, and the other keys keep the formula of the column. A cell without a formula gives
#NAME?. In the builder,cellFormula(k, column, formula)gives the formula of a cell, and the formula must give a value of the type of the column. - SHEET.TABLES4 tests pass A run can have more tables, each with a name, a space, columns and formulas of cells. A cell reference reads the table of the space where it evaluates, so the body of the axis
table(name)reads the cells of that table. Each cell of each table evaluates once, and a cycle across tables gives#CYCLE!. - SHEET.RECURRENCE4 tests pass A column can read itself at another key. A recurrence over the key order, for example a running total, gives the same result as a loop. The first key that a host reads does not change a result, also at the end of a long recurrence.
- SHEET.DECLARE1 tests pass
declare<T>()gives the types of columns before their formulas. A formula can read a declared column with its type, also the column itself or a later column. The formula of a declared column must give a value of the declared type.declarehas no effect at run time. - SHEET.CYCLE10 tests pass Each cell on a cycle of cell references gives
#CYCLE!. A cycle can contain one cell, or cells at different keys. - SHEET.DEEP6 tests pass A run evaluates a chain of cell references of any length. The length does not depend on the call stack of the engine, and the results are the results of a recursive search.
- SHEET.ORDER5 tests pass The result of a cell does not depend on the order of the evaluations.
ifErrordoes not hide a cycle from the cells on that cycle. - SHEET.FILL13 tests pass
fill(table)evaluates each cell of a table before the reads. Each column comes after the columns that it reads, and the keys of a column follow its reads from itself. A read then gives the result of a read without the fill. - SHEET.COMPILE8 tests pass A run with the option
compileevaluates each formula of a column with a compiled program. It gives the results of a run without the option. A formula compiles once for each compiler and its options, also across runs. A compiled program reads the cells of the run that evaluates it. - COMPILE.SHEET.COMPUTED2 tests pass Tier 2 evaluates a read with a computed move with no fallback. An error of the cell goes to tier 1 (
COMPILE.LIST.VALUE). The results stay the results of the reference.
10. The compiler
Section titled “10. The compiler”These requirements apply to @mark1russell7/vex-compiler.
-
COMPILE.TIERED278 tests pass
tiered(e, options)gives a program with the interface ofcompile. For each space, origin, variables and tables, itsrungives the result ofevaluate. -
COMPILE.FALLBACK10 tests pass Where the generated code of tier 2 cannot give the result, tier 1 gives it. This rule applies in each context, also in the first argument of
ifErrorand in an item of a list op. A page that does not permitnew Functionuses tier 1. -
COMPILE.FIX19 tests pass Tier 2 lowers
fixandlastto an array of rows and a loop of rounds. A program withfixruns in tier 2, with the result of tier 1 at each key. This includes each error value of a row and the failure at the round limit. A program that the check of a step refuses keeps the reason of the check. -
COMPILE.FIX.MODULE21 tests pass
emitModuleandemitSheetModulelowerfixandlast, with the results of the interpreter and ofSheetRun. A column that reads no key evaluates once, on its first read. A row that reads a cell does not stop the next rows, so the search of a sheet sees each read. A column at a key of a literal or offillhas no row. Thus a module refuses it with the reason of the axislist. -
COMPILE.ERRORS33 tests pass Tier 2 gives the error result of a program. The error has each field of the error of
evaluate: code, kind, message, op, path, origin, focus, causes and thrown value. The result#ARGSis such a result. An argument evaluates once, in the order ofevaluate. A run that tier 2 ends with an error is no fallback ofTierStats. -
COMPILE.LIST.VALUE176 tests pass Tier 2 gives a list op on a list value, a list literal and
fill. Each list op on a list value uses the code of the interpreter (LIST.OPS). Thus a list with an error item gives the result ofevaluate. An error of the op is an error of the program (COMPILE.ERRORS).ifErrorgives its second argument, a list op skips the error item, and a binding oflethas no value. These send the evaluation to tier 1:#DEPTH!and an error of an item thatstrictgives. -
COMPILE.LIST.ARRAY414 tests pass Tier 2 gives a list op on an array, also in the body of a list op. The op comes after the domains and the functions of the host, as in
evaluate(LIST.ARRAY). It uses the code of the interpreter (LIST.OPS), so the op skips a hole. Withstrict, the error of the hole is an error of the program. One case sends the evaluation to tier 1:errorsof an array with a hole, because its values have the position of the call. The result is the result ofevaluate. -
COMPILE.LIST.AXIS107 tests pass Tier 2 gives
each,foldand a data limit (ITERATE.LIMIT.DATA) over the axislist, also withreverse,where, an address andas. The results are the results of AXIS.LIST, AXIS.LIST.ITEM, AXIS.LIST.INDEX and AXIS.LIST.SCOPE. A value that is not a list is an error of the program (COMPILE.ERRORS). An array is a list (LIST.ARRAY). A list with an error item, or an array with a hole, sends the evaluation to tier 1. -
COMPILE.EXT27 tests pass In tier 2, an error of an extension is an error of the program, as an error of an op is.
ifErrorgives its second argument, a list op skips the error item, and a binding oflethas no value. An error of an extension at the result is the result of tier 2 (COMPILE.ERRORS). These send the evaluation to tier 1:#DEPTH!of an extension and a full call stack. Tier 2 skips no extension whose#DEPTH!the interpreter gives, also after an error that the program catches. The result is the result ofevaluate. -
COMPILE.TRACE1 tests pass A run with a trace, and
explain, use tier 1. Thus they give the traces of the interpreter. -
COMPILE.MEMO60 tests pass A program keeps the value of each node that depends only on the space, for each space. Thus a run at each key of a space evaluates such a node once. A space does not change, so each run gives the result of
evaluate. -
COMPILE.GROUP7 tests pass A program keeps the value of a node for each space and each value of its keys. A key reads the origin or a name from outside the node, and nothing that the node changes. Thus an aggregate over the group of the origin evaluates once for each group.
-
KIND.STATIC24 tests pass When the kinds of the values of an op site decide its op, the site uses that op with no guard. A value against the schema, or a result against a primitive kind of
returns, sends the evaluation to tier 1. A result of the kind of a domain gets the checks of the interpreter. -
KIND.DOMAIN2 tests pass A value of a domain without a primitive type has the kind of its domain,
domain:Name. An op withreturns: "domain"gives this kind, and a schema can declare it for a field. A module checks such a field with a copy ofisof the domain. It checks each copy of an op with thesamplesof the domain. -
KIND.FIELDS25 tests pass A domain declares
fieldswhenisaccepts only plain objects with exactly these names. Two domains with different names have no common value. Thus a module keeps each of them in its own op, in each order of the domains. The law checker tests the declaration. -
KIND.LIFT27 tests pass A module gives a number at a lifted position to a copy of
fromScalarof the domain. This needs the kinds of the receiver and the number before the run. Tier 2 keeps the dispatch of the runtime for this site. -
COMPILE.MODULE94 tests pass
emitModule(e, options)gives an ES module with no import of Vex. For an input that keeps the schema, its run gives the value of the interpreter at each key, orVEX_ERRORfor an error. An input against the schema throws aVexContractError. The optionnameis the name of the run. A reserved word, a name that the module declares or a global that a module reads gives a reason. -
COMPILE.MODULE.NESTING14 tests pass
emitModuleandemitSheetModulerefuse a program past the limit of EVAL.NESTING, with the reason of the interpreter. The refusal comes before a walk with recursion, so a program of each depth gives the reason, not aRangeError. -
COMPILE.MODULE.RESULT29 tests pass In a module, an op result that is
undefined,nullor a number that is not finite gives the error of the interpreter (CALL.RESULT). This rule applies to each declarationreturns. The module prints the checkk_valuearound such an op. An op has no check when its kind isnumber, or when the checkvalidof its domain refuses each such result. An op also has no check when its text proves a value. A proof reads the expression body of an arrow function: a comparison, a negation,&&or||of these, or an object literal. -
COMPILE.MODULE.TREE6 tests pass With the option
space: "tree", the module is for a tree space. Its run takes the parents after the variables: the position of the parent of each record, or -1 for a root. The key of a record is the text of its position. A parent that is not -1 or a position, or a cycle of parents, throws aVexContractError. The moveparent, the offsets, the window and the axes of a tree and of a graph give the targets of the interpreter. -
COMPILE.MODULE.TREE.ALLOC3 tests pass A forward loop over
ancestorsin a module walks up the parents, with no array. The reverse order keeps the array. The output array of a run has its length before the first key. The order of a tree keeps its keys in flat arrays of integers, and it reads only the parents. A test limits the heap bytes, the external bytes and the objects for each node of the tree case of the gate. The test reads no time. -
COMPILE.MODULE.SHEET25 tests pass
emitSheetModule(columns, options)prints the formula columns of a sheet as a standalone module. Its run gives an object with an array for each column: the result at each key, orVEX_ERROR. These results are the results ofSheetRunwith the same formulas of cells and the same budget of the stack. Thus each cell on a cycle givesVEX_ERROR. The run fills the columns in the static order ofSheetRun.fill. A formula that reads a column before the formula of that column needs the kind of that column in the optionkinds. -
COMPILE.MODULE.SHEET.DIRECT9 tests pass A sheet module without formulas of cells has no search when each read of a cell reads a finished cell. A read of a column before its own column in the fill order reads a finished cell. A read of its own column reads a finished cell in three forms. These are the parent in a pre-order tree fill, the children in a post-order tree fill and one earlier key in a forward array fill. The results stay the results of
SheetRun. -
COMPILE.MODULE.ONCE1 tests pass A sheet module with no search has no function for a column. The code of each formula is in a loop over the keys, and the results stay the results of
SheetRun. Columns that follow each other in the fill order share one loop when they have the same order of the keys. Each read of an earlier column of the loop must read the key itself or one of the three forms of COMPILE.MODULE.SHEET.DIRECT. -
COMPILE.MODULE.LIST9 tests pass A module has the list ops
drop,append,without,flat,getandindexOf. It has list literals, a list op over aletand lists as names offoldanditerate. Its run gives the values of the interpreter. A step must give a list of the kind of the first list of its name. The axislistover a list with the keys of a literal or offillreads no record at a target. A read of a record at such a target gives a reason. -
COMPILE.MODULE.LIST.RESULT14 tests pass The value of a module can be a list, also a list of lists. The run gives it as a
vex.listwith the keys of the interpreter as text. Only a list that one object serves to more than one key is frozen (COMPILE.MODULE.FUSE.OUT). Each other list of a result is not frozen. A column of lists of a sheet holds onevex.listfor each cell, so its lists are not frozen. An error item has the errorVEX_ERROR.ifandifErrortake lists as branches. A list in only one branch gives a reason. -
COMPILE.MODULE.LIST.ARG9 tests pass An argument of an op after its receiver can be a list. The op gets a frozen
vex.list, as in the interpreter. An error item has the errorVEX_ERROR. A parameter that takes no list gives the error of the interpreter. An argument of a call can be a list too. A list as the receiver of an op that is not a list op of the module gives a reason. -
COMPILE.MODULE.LIST.CALL7 tests pass The value of a call can be a list. The place of the call takes it as a list, also the list ops, the axis
list, a field and an argument. Each kind of the arguments has its own function and the facts of its list. A list of a call at a place that takes no list gives a reason. -
COMPILE.MODULE.LIST.INPUT37 tests pass A field of the schema can have a
ListKind, also a list of lists and a list ofdomain:<Name>. The record holds the list as avex.list. The program uses the field as a list, and the run gives the values of the interpreter. Another value, an item of another kind and an error item of#DEPTH!throw aVexContractError. The axislistcannot read a record at a key of such a list. -
COMPILE.MODULE.LIST.NESTED14 tests pass
nth,firstandgetover a list of lists give a list, and each list op of a module takes that list. This is true at the place of the read, through a name of alet, through a parameter and through a call. Each level of a list has this rule. The run gives the values of the interpreter. An item of a list of values is not a list, and a list op over it gives the reason of a value. -
COMPILE.MODULE.LIST.VAR12 tests pass A variable of the schema can have a
ListKind, also a list of lists. The variables of the run hold the list as avex.list, or as an array withlists: "plain". The program uses the variable as a list, and the run gives the values of the interpreter. The run reads each list once. A list against its kind gives the error of the variables, also for a list that the program does not read. The axislistover such a list reads no record, so it gives a reason. It takes namesas. -
COMPILE.MODULE.LIST.OP22 tests pass An op of a domain with the kind
list:<Kind>gives a list of the module (KIND.RETURNS.LIST). The place of the op takes it as a list, also the list ops, the axislist, a name and a result. Its run gives the values of the interpreter. A result that is not such a list is an error of Vex. The keys are text, so the axislistcannot read a record at a key of such a list. An earlier domain with the op can decide the site. Then the place of a list gives a reason. -
COMPILE.MODULE.LIST.PLAIN26 tests pass
emitModuleandemitSheetModulehave the optionlists, with the default"envelope". The default prints the same module as before. Withlists: "plain", a list field of the input holds an array of the values of its items. A list of lists holds arrays to the depth of its kind. The key of an item is the text of its position. TheVEX_ERRORof the module is an error item. Another value throws aVexContractError.The value of the run and a column of lists give an array of the values of the items, with no keys. An error item is
VEX_ERROR. A list in a record or in an argument of an op stays avex.list. The run gives the values of the interpreter in this form. Another value oflistsgives a reason. -
COMPILE.MODULE.LIST.FIELD2 tests pass A field of a record can be a list. The record holds the list as a frozen
vex.list, with the keys of the interpreter as text. An error item has the errorVEX_ERROR. An op of a domain reads the lists of such a record. -
COMPILE.MODULE.KEYS32 tests pass
emitModuleandemitSheetModulehave the optionkeys, with the defaultfalse. Withkeys: true, the run takes the keys of its records as its last argument: an array with one different text for each record. The value at each position is the value of the interpreter at the key of that position, over a space with these keys. Aget, awithout, avex.listand the movekeyuse these keys. A key of a literal and offillstays that key. A program that reads no key of a record prints the same text as without the option, and its run ignores the argument. Keys that are not such an array throw aVexContractError. A record space has no offset and no axiswindow. Thus a program that reads a key in an array space and has one of these gives a reason. A sheet with formulas of cells gives a reason. -
COMPILE.MODULE.BANDstatus unknown A module copies the ops of a domain of bands,
BandDomainof the pilots. A program makes bands, reads their fields, and moves, flips, joins and compares them. The run gives the values of the interpreter, andVEX_ERRORfor an error. -
COMPILE.MODULE.NTH.INDEX3 tests pass A module keeps the items with values of a list on its array at the first
nth,countorfirstof the list. Each laternth,countandfirstof that list does not read the list again. A key of a node of the memo can be a list. -
COMPILE.MODULE.LIST.SHARE1 tests pass In a module, a list op does not copy a list without error items to read its items with values. It reads the array of the list. No op changes such an array, so
sortBysorts a copy. -
COMPILE.MODULE.APPEND.OWN9 tests pass In a module, a step of a name of
foldoriteratecan append to the list of the name. Such a step is a read of the name,append(step, X),if(c, step, step)or aletwith such a step as its body. The other parts of the loop must not read the name. Then the first append copies the list, and each later append adds its items to that copy. Thus n appends cost O(n), not O(n squared). The values and the errors stay the values and the errors of the interpreter. -
COMPILE.MODULE.APPEND.LET7 tests pass In a module, a step of COMPILE.MODULE.APPEND.OWN can also be a
letthat binds such a step to a new name. No other binding reads the name, and the body does not read the old list. The body can read the new name in each way, and its value can be another list. Then the appends of the binding add their items to the array of the loop. The next append after another list copies that list. A read of the new name withgetgives the items of the list at that read, also after a later push. A read of it in an argument or in a field does too. The values and the errors stay the values and the errors of the interpreter. -
COMPILE.MODULE.APPEND.READ7 tests pass In a module, a step of another name can read the name of COMPILE.MODULE.APPEND.OWN when it comes before the step of the name. Each read must be the list of
count,nthorfirst, or the list of the axislistof a fold. Then the step of the name still adds its items to the array of the loop. A read inuntiland each other read keep the copy of each append. Withfuse, a later step can also read the name (COMPILE.MODULE.APPEND.LATE). The values and the errors stay the values and the errors of the interpreter. -
COMPILE.MODULE.APPEND.OTHER4 tests pass With
fuse, a branch ofifin a step of COMPILE.MODULE.APPEND.OWN can be another list, when one branch is such a step. The binding of aletcan be such anif, and its body can be a step of the new name. Then the appends of the step add their items to the array of the loop when their list is that array. Each other list gets one copy. The values and the errors stay the values and the errors of the interpreter. -
COMPILE.MODULE.APPEND.LATE3 tests pass With
fuse, a step of another name can read the name of COMPILE.MODULE.APPEND.OWN or COMPILE.MODULE.APPEND.OTHER after the step of the name. Each such read must be a read of COMPILE.MODULE.APPEND.READ. Then the step of the name prints after the other steps, so each read comes before the first push. Each other owner must keep its reads before its step. Otherwise each append keeps its copy. The values and the errors stay the values and the errors of the interpreter. -
COMPILE.MODULE.APPEND.PUSH3 tests pass With
fuse, an append of COMPILE.MODULE.APPEND.OWN or COMPILE.MODULE.APPEND.OTHER makes no array for its right list when a fused loop can push its items. The items go into the array of the loop when the left list is that array. Otherwise they go into one copy of the left list. The keys,strict, the values and the errors stay those of the interpreter. -
COMPILE.MODULE.APPEND.KEEP5 tests pass With
fuse, a branch of COMPILE.MODULE.APPEND.OTHER can beflatover aneachover the axislistof the name. Each item of the body gives at most one item, and the body does not read the name. Then the filter moves the kept items down in the array of the loop when its list is that array, and it sets the length. Each other list gets a new array. The keys,strict, the values and the errors stay those of the interpreter. -
COMPILE.MODULE.SHEET.LIST12 tests pass A column of a sheet module can hold a list. A formula reads the list of a cell with the list ops,
get,indexOfand the axislist. The results stay the results ofSheetRun. A column of lists that a formula reads before its own formula needs aListKindin the optionkinds. Each formula of the column must give a list that fits its kind. -
COMPILE.MODULE.SHEET.COMPUTED8 tests pass A sheet module takes a read with a computed move, and the results stay the results of
SheetRun. A read of a finished column reads the array of that column. Another read goes through the search, which finds its cell in the run, also on a cycle that only the values make. A module over a graph gives a reason, because a graph has no window. A list op can read a list at a computed key. -
COMPILE.MODULE.GRAPH8 tests pass With the option
space: "graph", the module is for a graph space. Its run takes the edges after the variables: for each record, an array of the positions of the ends of its edges. The key of a record is the text of its position. Edges that are not an array of positions for each record throw aVexContractError. The axessuccessors,predecessorsandreachablegive the targets of the interpreter, in its order. An offset and the moveparentgive an error. A window and the axes of a tree give a reason. -
COMPILE.MODULE.REDUCE8 tests pass A module has
reducewith a literal op name and the optionsstrictanddomain. Its run gives the value of the interpreter. The first item is the first value. The op of each later step comes from the kinds of the items. No items give the identity of the one domain that has one. The op must give a value of the kind of the items. -
COMPILE.MODULE.FORM127 tests pass A domain can give a
moduleForm, the parts that a module copies in place of its own.Vec2Domainhas one, so a program overVec2values can be a module. A module has no import, so it holds a vector as plain data, thetoJSONof aVec2. An input can hold plain data or aVec2. ThetoJSONof a value of tier 1 or tier 2 equals the value of the module. An error stays at its key. A form changes no value of tier 1 or tier 2, and it changes no module of a program without its domain. -
COMPILE.MODULE.FILL11 tests pass A module has
fillwhen no domain has the opfill(LIST.FILL). Its run gives the values and the errors of the interpreter. The value can be a list, sofillcan give a list of lists. The keys “0” to “n - 1” are not the keys of records, as for COMPILE.MODULE.LIST. A domain with the opfillcomes first. -
COMPILE.MODULE.FILL.RANGE6 tests pass With
fuse, a module makes no array forfill(n, v)when onlycountor a loop over the axislistreads the list. The list can also betakeof such a list, with no option. The loop goes over the count, and each item has its position as its key andvas its value. The count has the checks offillandtake. Thus the values and the errors stay the values and the errors of the interpreter. A name, another op, a key of a node of the memo and a domain with the opfillkeep the array. -
COMPILE.MODULE.SETNTH6 tests pass A module has
setNthover a list, with the optionstrict(LIST.SETNTH). Its run gives the values and the errors of the interpreter. The array of the old list does not change. The value can be a list when the items of the list are lists. A list of lists with a value that is not a list gives a reason. A list of values with a list as the value gives a reason. A missing position or a missing value gives a reason. -
COMPILE.MODULE.SORT.BY3 tests pass A module has
sortBywith the optionby(LIST.SORT.BY). The kinds of the items must decide the op ofby, and the module copies that op. Its run gives the values of the interpreter. Abythat is not a literal text, or items whose kinds do not decide the op, give a reason. -
COMPILE.MODULE.LOOP.EMPTY19 tests pass The first value of a name of a loop can be the empty list. The name then takes the kind of its items from its step, when the program has no module without that kind. A step can get the kind from another such name. Each step must then give items of that kind, or a reason gives the step. A program that no step decides keeps the reason of its first print. A program with a module without that kind keeps its text. Its run gives the values of the interpreter.
-
COMPILE.MODULE.LIMIT.ONCE5 tests pass In a module, a data limit (ITERATE.LIMIT.DATA) that reads no key is a constant of the run. The first key that reaches the limit counts the targets, and each later key reads that count. Thus a loop that stops early pays only for its steps. A key that does not reach the limit does not start the count. The values and the errors stay those of the interpreter (ITERATE.LIMIT.ERROR).
-
COMPILE.MODULE.LIST.ITEM13 tests pass A module has the names
asofeachandfoldover the axislist(AXIS.LIST.ITEM, AXIS.LIST.INDEX, AXIS.LIST.SCOPE). Its run gives the values and the errors of the interpreter, also withreverse,whereandstrict. An item that is a list is a list in the body. A step that reads such a name keeps the append of COMPILE.MODULE.APPEND.OWN. -
COMPILE.MODULE.FUSE.OFF5 tests pass
emitModuleandemitSheetModulehave the optionfuse, with the defaulttrue. Withfuse: false, they print the code without fusion. Thus a test and a bench can compare the two forms. A declaration of a print that the printer drops does not stay in that form. A value that is not a boolean gives a reason. -
COMPILE.MODULE.FUSE.FACTS34 tests pass The printer of a module keeps two facts of each list and the count of the reads of each list node. A list is
cleanwhen no item holds the error sentinel, andfreshwhen no other part holds its array. The facts are true for each run. Withfuse: false, they do not change the printed code. -
COMPILE.MODULE.FUSE.CLEAN8 tests pass With
fuse, an op over a list that the facts prove clean has no scan for error items and no test of the sentinel. The factcleanof each list argument is a part of the signature of a function. The values, the errors and the order of the reads do not change. -
COMPILE.MODULE.FUSE17 tests pass With
fuse,flatover aneachwhose body is a list is one loop with one output. The module does not print the list of theeach. A body ofifpushes from its branch, andfill(1, v)pushesv. Its run gives the values and the errors of the interpreter. The output is clean and fresh.A chain of
appendwith a part that pushes is also one output, and each part pushes its items in order. A part that the module keeps for other reads gives its array, and a loop copies its items. In a sheet with a search, a chain that reads a cell keeps its arrays.sortByover a clean and fresh list sorts that array in place, in the stable order of the interpreter. -
COMPILE.MODULE.FUSE.ITEM7 tests pass In a fused chain, an item that fails adds no item. With
strict, it is the error of the chain. An error item of a source stays where the interpreter meets it. A strict loop over cells reads each cell before it raises the error. -
COMPILE.MODULE.FUSE.ADOPT13 tests pass With
fuse, an append into the list of its name (COMPILE.MODULE.APPEND.OWN) takes a clean and fresh first list as its own array. Thus the first append makes no copy. An append of the result of the loop pushes into the array of the loop when no other part of the result reads the list. Aletof the result can bind that append to a new name. The values and the errors do not change. -
COMPILE.MODULE.EACH.SAME10 tests pass With
fuse, aneachover the axislistwhose body is the name of the item gives the array of its list. It makes no copy. Theeachhas nowhere, noreverseand no address. Its value is not fresh, so no op changes that array in place. The values and the errors stay those of the interpreter. -
COMPILE.MODULE.FUSE.OUT14 tests pass With
fuse, a value ofemitModulethat does not depend on the key has onevex.listfor each run. Each key gets that object, so the object is frozen, with its array of items and its nested lists. The module makes the list on its first read. Withfuse: false, and for a plain array oflists: "plain", each key has its own list, and this list is not frozen. The values and the errors do not change. -
COMPILE.MODULE.FUSE.SORT11 tests pass With
fuse,sortByover a clean and fresh list of 64 items or fewer uses an insertion sort. Such a sort does not call the sort of the engine. A longer list calls the sort of the engine one time. The optionbyapplies one time to each item, in order, in both forms. The order, the values and the errors stay those of the interpreter (LIST.SORT, LIST.SORT.BY). -
COMPILE.MODULE.SIZE3 tests pass With
fuse, the printer removes the code that a run does not need. The values, the errors and the refusals stay those of the module withfuse: false. Withfuse: false, the printer does not remove this code. A text of the program can hold the code that a rule looks for. That text can stop a rule, but no rule changes it. -
COMPILE.MODULE.SIZE.FILL6 tests pass With
fuse,fill(0, x)prints the empty array when the code ofxcannot fail. It also prints the empty array whenxhas only literals and ops and the interpreter gives the empty list. Each otherfillkeepsFI, so the list keeps its error. A branch of a fused loop with such an empty list prints no block. -
COMPILE.MODULE.SIZE.KEY3 tests pass With
fuse, a loop over an array does not print a key that no code reads. -
COMPILE.MODULE.SIZE.ALIAS6 tests pass With
fuse, aconstthat gives a second local name to a value is not printed, and each read reads the first name. Theconststays when a write of the first name can change the value of a read. -
COMPILE.MODULE.SIZE.ONCE5 tests pass With
fuse, a lazy cell can print its value at its read. The cell must have onereturnand one read in the formG(c()), and that read must run at most once.Gstays, so a valueEstays an error. -
COMPILE.MODULE.SIZE.INLINE7 tests pass With
fuse, an op or a check of a domain with one call prints its body at the call. Each argument of the call must be a name, and the body must be an expression that reads only its parameters and globals. -
COMPILE.MODULE.FAULT37 tests pass The option
faultsof a module selects what a catch does with an exception. Withvalue, the default, each exception at a binding, an item or a key is the error of Vex. Withthrow, an exception that starts in a function of a domain is the error of Vex, as in the interpreter. Each other exception leaves the run. Thus a fault of the printed code does not become a value. A text of the program that holds a catch stays that text. -
COMPILE.MODULE.BYTESstatus unknown A committed module equals its print byte for byte. A pinned commit of the compiler gives the print, and a difference fails the gate of the repository of the module. The message gives the first line that differs and the command that prints the file again. The check of a pull request reads no published version, so its result depends only on the pull request. A daily check prints from the last release and fails when the output differs from the files.
-
COMPILE.MODULE.BYTES.HASHstatus unknown The pilots keep the sha256 of the print of each module of ireko in
ireko-prints.json. Thus a reader checks a committed file with no run of Vex. A test fails when a hash differs from the current print, and its message names each module that differs. -
COMPILE.GROWTH18 tests pass The gate has shapes, each at two legal sizes. The time of a print grows with its places at most by the exponent of the gate. The text of a module grows at most linearly. The shapes
originandwideoriginstate their own limits and reasons. The gate ispackages/compiler/bench/growth.ts. -
COMPILE.GROWTH.NOISE6 tests pass A time exponent of the growth gate reads pairs: process
iof the small size and processiof the large size. The rule isgrowthVerdictof@mark1russell7/rigor-bench. An interval of the pairs under the limit passes, and an interval over the limit fails. An interval that holds the limit reads five more pairs. When the interval still holds the limit, the row is a no read with a warning, and it does not fail the gate. A held time of the source of tier 2 has the same rule. -
COMPILE.SOURCE.SIZE35 tests pass A line of the source of tier 2 has no indent, so the block nesting of a line does not change its size. A let with no function keeps the map of functions of the lowering. The gate
packages/compiler/bench/growth.tsreads the time and the bytes of tier 2 for each shape, against the places. A bytes exponent over its limit fails the gate, and the limit of each shape finds 5 % more bytes at its large size. A row with different bytes in its processes is report only on its bytes. The time is report only. -
COMPILE.MODULE.COSTstatus unknown The time of a print of each module of ireko stays under its limit against a fixed base commit. The gate reads each module alone, and its row
buildreads the modules with a shared object in one process. The program of a module picks its limit, and a line of a module states its reason. The rule istailLimitVerdictof@mark1russell7/rigor-bench. A second pair is a fault only over its limit and over the worst second pair of the A/A arm of the run. A read with an A/A arm over the cap does not decide. The gate ispackages/pilots/bench/module-cost.ts, and it must fail a known added cost. It must also fail a cost in 2 of the 7 rounds that leaves the median under its limit. A pass states that no module has a slowdown over its limit. A pass does not state that a module is not slower. The limits are 1.10 to 1.23,boundshas 1.25, and the gain rowsbuildandavoidhave 0.98 and 0.89 on the models ofGAIN_MODELS. -
COMPILE.MODULE.RECORDstatus unknown Each read of the gate of
COMPILE.MODULE.COSTwrites one JSON line for each row. Each line names its format, its kind (gateorfault), its step, the facts of the processor and if its read decided. A read of a cost takes only the decided rows of the kindgate. A line with another format or no known kind is a fault. -
COMPILE.PLACES70 tests pass A compile counts the places of a program first. A place is a node at one position of the tree of the program, so a shared object counts once for each place. A module and tier 2 refuse a program with more than 32,768 places. The error has the code
COMPILE.PLACES, the count and the limit. The interpreter has no such limit, so tier 1 runs a program that a compile refuses. This is a stated difference between the interpreter and a compile. -
COMPILE.MODULE.TEXT16 tests pass The bytes of a module do not depend on the program that loaded the compiler or the domains. The module parses the text of each copied function and prints the tree. A text that is not one expression stays as it is.
-
COMPILE.MODULE.SIZE.FLAT2 tests pass With
fuse, a module has list helpers with no argument for the depth when each list field of the schema has the depth 0. -
COMPILE.MODULE.SIZE.DEAD7 tests pass With
fuse, a module has no helper, op or constant of the run that no code reads. -
COMPILE.MODULE.NAME16 tests pass The option
namegives the name of the export of the run. A reserved word,VEX_ERRORandVexContractErrorare not names of the run. Each other identifier is a good name. A run name hides nothing from the code of the module or from a copy of an op. If the code has the name as a token, the module prints the run under an internal name. The code does not have that name, and the module exports the run withas. Else the module printsexport function. -
COMPILE.MODULE.SCAN21 tests pass A
foldoverwhere(all, test)can be a scan. Its test compares a valueTof the target with a key of the origin by<or<=. Its first values, its steps and its result must read no key of the origin. Then a run evaluatesTonce and each step at most once at each record. The values and the errors stay the values and the errors of the interpreter. -
COMPILE.MODULE.EXIT14 tests pass In a module, a name of
foldwhose step isand(name, ...)stops at false, andor(name, ...)stops at true. When each such name stops, the loop leaves. The rest of the targets runs only the checks, the tests and the steps of the other names. Thus the values and the errors stay the values and the errors of the interpreter. A fold with an append into its own list has no exit. -
COMPILE.MODULE.PAIRS11 tests pass A module prints the steps of a
foldoverallagain, with no test and no name that holds a list. Each read of a column at the focus of the fold, or of a loop in its steps, reads the pack of the column. A column of a call of the printed function has a pack in each call. The values and the errors do not change. -
COMPILE.SOURCE11 tests pass
generate(e)gives the same source for the same expression. The source has no name and no literal of the expression. It reads them from its constants, by index.
11. Examples
Section titled “11. Examples”- EXAMPLE.SEPARATION3 tests pass The test is
position + size - other.positionin a pair of boxes. A component that is not positive shows that the box at the origin ends before the other box starts. - EXAMPLE.NEAREST4 tests pass The minimum of the distances from the origin to the others is the distance to the nearest other record.
- EXAMPLE.OFFSETS3 tests pass The reduction with
addof the offsets from the origin to the others is the sum of the offsets. - EXAMPLE.TREE10 tests pass In a tree of people, the salary of a person plus the sum over
descendantsis the cost of the team of that person. Thecountoverancestorsis the depth of the person. - EXAMPLE.SCHEMA3 tests pass A program of
JsonDomainfinds the schema of up to 20 JSON documents. It gives one record for each field path, in the order that the paths first occur. A record has the path, the distinct kinds and the count of the documents with the path. The program goes into an object that is not empty at a depth under 3, and it does not go into an array.
12. The mutation lane
Section titled “12. The mutation lane”- LANE.GATE6 tests pass A full run reads each part of the lane, and each published package has a score of 95 % or more. A time-out of the clock counts as not found. A part with no report gives no read, and a no read fails the gate.
- LANE.PARTS4 tests pass The parts of a package cover each file of the package once, and the parts of a file cover each line once. Each input gives the same parts.
- LANE.CUT4 tests pass The lane cuts each group into its parts at end lines. An end line is the closing line of a method or the last line of a file. Of all such cuts, the lane takes the cut with the smallest largest part under the cost maps, then the smallest sum of squares. A file with no cost map has the mean cost of a line of the files of its group with a map.
- LANE.DELAY3 tests pass The full run starts each week. A night reads only the changed files, and a score of a night fails nothing. A fault with no change in its own file shows at the next full run, at most 7 days later. A page with a score states the date of its run, and a score older than 7 days reads stale.
- LANE.DRYRUN2 tests pass A change of the files of the lane starts the first test run of Stryker on each part. A part that fails this run fails the check, and it gives no score. A part that passes stops after its plan, and the plan is the output of the check.
- LANE.PLAIN4 tests pass A test file of the compiler with imports that reach the printer reads the copy of the domains that Stryker does not mutate. Each other test file of the compiler reads the mutated copy. The lane refuses a file that this rule cannot classify, and a test that reads two copies.
- LANE.TESTS7 tests pass Each part prints its count of tests beside its score. In a full run, a fall of more than 20 % against the last good read of the part gives no read. A count compares only with a last good read of the same mutated files. An entry in
tools/mutation/planned-falls.jsonaccepts one fall, while the last good read equals the old count of the entry. A part that fell or that gave no report keeps its old count. - LANE.FILES7 tests pass A test file of a published package that no part of a full run reads gives no read for that package. The list
NOT_READoftools/mutation/layout.tsstates the reason of each exception, and an entry that is not true fails the load check. The selection of the load check and the test files of the reports are two reads of one question. In a full run, a difference on a file gives no read with its own text, and the gate does not pick one read. A full run with no saved selection also gives no read. - LANE.COST10 tests pass Each part writes its plan when Stryker makes it, and one line for each mutant that ends. The plan gives the planned net time of each line, and each cost line gives the line of its mutant. A time-out costs its clock limit, and another run costs its planned net time. A part of a full run stops itself 10 minutes under the limit of its job, so its artifact keeps these costs. The plan of a part gives an estimate of its clock, and an estimate over 100 minutes has a mark. The plan also gives the 40 tests of the largest cost. The cost of a test is its time, times the runs of mutants that start it. Under the committed cost maps, the estimate of each part of a full run is at most 100 minutes.
- LANE.SPEED2 tests pass Each part has its own runner, and the speed of the runners differs. The cost maps divide the net time of each part by the speed factor of its runner. The factor of a part is a median over the tests of its plan. Each test gives the ratio of its time to its median time in the group. A test counts from 200 ms, in the plans of at least half of the parts of the group. A part with no such test has the factor 1.
- LANE.STATIC1 tests pass A dry run fails when its plan has more static runs in a file than the limit of the file. The limits are 600 in
module.ts, 350 inkernel.tsand 200 inlist.ts. A static run starts each test of the lane. - LANE.PARTIAL3 tests pass A part that reaches its stop gives the partial score of the mutants that ended, with a mark. A partial score is not a score: the gate reads the part as no read, and the job fails.
13. The query entry
Section titled “13. The query entry”The entry @mark1russell7/vex/query holds a query model of flat records, for a page that searches, filters and sorts a collection. A view is data: each control of the page changes one field of it. The entry compiles a view to one Vex program, and evaluates it at each record of a space of kind record.
- QUERY.ENTRY2 tests pass The entry imports only the core. The programs use the ops
lower,contains,eqandepochMillisof the domains of the caller, for exampleTextDomain. They also useandandincludesof the kernel. - QUERY.CATALOG3 tests pass
fieldCatalog(records)gives one row for each field with a value in a record, by the name of the field. The id is not a row, and the optionskipnames the fields that it leaves out. A name that a reference cannot read is not a row (REF.FORBIDDEN). A row has the type, the count of the records with a value and the count of the different values. A number that is not finite is no value. A number, a time and a date field have their smallest and largest value. Times and dates compare as texts. - QUERY.CATALOG.TYPE2 tests pass The type of a field comes from the forms of its values. A time has the form that
epochMillisreads, withZor an offset. A date isYYYY-MM-DD. A field with times and dates is a time field. A field with values of two other types is a text field. The type does not depend on the clock or on the time zone of the computer. - QUERY.CATALOG.FACET2 tests pass A text, a boolean or a date field with at most
maxFacetdifferent values is a facet. The default is 12. A facet has its values, the most frequent first, then by value. A text field that is not a facet is a field of the search. - QUERY.COMPILE3 tests pass
compileView(view, catalog)gives one program that givestrueat each record that matches. The terms make oneand: the search words, then the facets by name, then the formula. A view with no search word, no value of a facet and no formula givesnull. The sort, the group, the show and the box do not change the program. - QUERY.COMPILE.SEARCH1 tests pass The search words are the text in lower case, split at the white space, with no repeat. Each word gives
contains(lower(search), word), so each word must be in the search field. - QUERY.COMPILE.FACET2 tests pass One value of a field gives
eq(field, value). Two or more values giveincludes(values, field), so the values are alternatives. A value of a boolean or a number field in the catalog becomes a boolean or a number. A dot in the name of a field does not split it. - QUERY.MATCH4 tests pass
matchView(view, records, { domains })gives the ids of the matches, in the order of the records. A record matches when each program givestruethere. An error or another value does not match, so a record with no value in the field of a facet does not match. A view with no filter matches each record. - QUERY.MATCH.COUNTS1 tests pass For each facet,
matchViewgives the count of each value in the records that agree with each other term of the view. Thus a chosen value does not hide the other values of its facet. - QUERY.SORT4 tests pass
sortIds(ids, records, sort, { domains })gives the ids in the order of the sort. The key of a time or a date field isepochMillis(field), so a time with an offset takes its place. The key of another field is its value. Numbers compare by value, and texts compare in the order of words, with the numbers in them by value and no case. A record with no key, or with an error as its key, comes last in each direction. A tie keeps the order of the ids. - QUERY.LINK17 tests pass
viewToQuery(view)gives the query of a link:q, the facets by name,sort,group,show,boxandvex, in this order. The different values of a facet are joined with commas, and a comma in a value is encoded. A facet with an empty name, the name of a key or a name that starts withf.gets the keyf.<name>. The sort is the field, with-before it for the directiondesc. A-at the start of the field is encoded. An empty text, sort field, group or box is not in the link. - QUERY.LINK.READ19 tests pass
viewFromQuery(query, facets)gives the view, the rest and the problems. For each view and rest,viewFromQueryofviewToQuerygives them back, with each name and value. A#ends the query. An empty value of a facet is a value, as inURLSearchParams. A key that is not of the view goes into the rest with no change. Thus a newer link keeps its keys in an older page. A part with a bad value is a problem, and the view does not get it. - QUERY.LINK.FORMULA2 tests pass The formula goes into the link as
vex: the text fromserialize, encoded byencodeURIComponent.parsereads it back. A formula with no JSON form makesviewToQuerythrow aTypeError. A text with a lone surrogate has no form in a link, soencodeURIComponentthrows aURIError. A formula thatparserefuses, or a value that does not decode, is a problem. - QUERY.SAME2 tests pass
sameFilter(a, b)tells if two views have the same filter and order. The search words, the formula and the sort must be the same. The values of each field must be the same, in any order. The group, the show and the box do not count. A view with no sort has the sortdefaultSort.