Skip to content

How a program runs

You have written programs now. This page says what happens to one, in enough detail to predict what the language will do and no more.

  1. source textwhat you wrote
  2. lexthe language's symbols
  3. tokenswords and symbols, no meaning yet
  4. parse
  5. raw programbindings and outputs, untyped
  6. composethe language and the port layers
  7. raw program + descriptorand everything it may use
  8. analyse
  9. core programtyped, checked, pruned
  10. evaluatethe input values
  11. valuesone per output

Five steps. Each takes what is on its left and produces what is on its right, and none of them can reach backwards.

The lexer cuts your text into names, numbers, strings and symbols. A string with no closing quote, or a character the language has no use for, is reported here, with a position. More on lexing.

The parser turns the tokens into bindings and outputs, and rewrites every symbol into the op it stands for as it reads: $price * $quantity leaves as Multiply($price, $quantity). It knows the shape of the language and nothing else, so a syntax error is reported here and a misspelled op name gets through. More on parsing.

Checking a program needs a list of everything it may use: the language’s ops and types, and the inputs and outputs your application declared, which arrive in layers. Composing joins the layers into one list. It reads what was declared, never what you wrote, so two layers claiming the same name are reported here, before your code is looked at. More on composing.

The analyser works out the type of every binding and checks every op call. Two things to rely on. Errors are collected, not thrown at the first one, so you get the full list at once. And soundness is per output: a broken output is dropped and the others still run, unless your application marked it required. More on analysis.

Outputs pull: asking for one walks only the nodes it depends on, so when an input changes, only the nodes that read it recompute (you saw this on Inputs). Two things to rely on. A binding is computed at most once per evaluation, however many names read it. And the last good program keeps running: while your text does not compile, the values on screen are the ones from the program that did, marked stale rather than hidden. More on evaluation.

You can write programs and predict what they do. Two ways on from here:

  • The standard library: every op, with its signature and a worked example, generated from the language itself.
  • How it works: the same chain again, one page per step, with the reasons. Learn told you what you can rely on; that section tells you why, and in what order.

And if you want the language inside an application of your own, Host developers starts there.