Skip to content

Effects

Some kinds change the world: log writes a line, and write writes a value to the store. These kinds are on the run side. Their cards have a magenta edge. Each effect becomes a numbered ticket in the world, in the order of the effects.

The glyphs so far: 16, 3 new on this page
  • 42Data: a value without a type
  • number
    42
    A document: the tab is its type
  • number
    42
    A dashed tab: the container declares the type
  • add
    number
    1
    number
    2
    Parts: a card inside a card
  • kindA kind: a document of type kind
  • OKDA rung: own, kind or default
  • 3A port: the result of a document
  • 0A sealed part: an evaluator cannot read it
  • #NAME?An error value, in a red port
  • numbera
    3
    A name tag: a binding for later steps
  • ref
    namesa
    A reference: a path from a root of the context
  • A dashed blue arrow: from a reference back to the step with its name
  • if
    test
    bool
    true
    true
    then
    text
    “yes”
    “yes”
    else
    text
    “no”
    not evaluated
    “yes”
    Not evaluated: a part that its parent did not need
  • ▸log
    text
    “hi”
    “hi”
    “hi”
    The run side: a magenta edge, and an effectnew
  • 1log“hi”An effect: a numbered ticket in the worldnew
  • logA capability: an effect that a term can causenew
Open in the playground

Nothing started yet. Select Next or Play.

seq
  1. 1
    ▸log
    text
    “start”
  2. 2
    ▸writetotal
    datakey“total”
    value
    add
    number
    2
    number
    3
  3. 3
    ▸log
    ref
    namestotal
The world: the effects, in orderNo effect yet.
The result shows at the end of the evaluation.
The first log, the write and the last log happen in the written order. The tickets show the order. The write gives its value to the name total, and the last log reads it.

Only the effects have numbers. For pure parts, the order of the evaluation does not change a result. For effects, the order is the meaning.

A term can cause an effect only when its context has the capability for that effect. A construct gives its parts the same capabilities or fewer. The kind pure gives its part no capability. Thus an effect inside pure fails with #CAP!, and the world does not change.

The contract of a kind declares what it gives its parts. The kernel narrows the context of each part by that contract. check reads the same contract, thus it finds the #CAP! before a run.

Open in the playground

The evaluation of pure ends with the error #CAP!: The context has no capability for the effect log.

pure
▸log
text
“hello”
“hello”
#CAP!
#CAP!
The result of the document: #CAP!
The root has the capabilities log and write. The kind pure gives its part none. The log asks for its effect and gets #CAP!.

Select the log card, and look at the panel. Its context has no capability. The capability is a part of the context, as a name is.

A capability also permits the kinds of its namespace. The capability store permits the effects store.update and store.remove.

The pictures on this page are evaluations. An evaluation records each effect, and it does none. A run is the same evaluation, but the host does each effect and gives back its result. Thus a step can read the result of the step before as last.

A test can give an evaluation a mock perform. Its answer becomes the result of the effect, without a promise. Each effect keeps a fixed address and its outcome, thus a host can record a run and replay it (decision D19).

A kind that holds effects has a runner. The same runner serves the evaluation and the run, thus the picture of an evaluation shows exactly what a run does. A run waits only when the host waits. Before that, it goes on at once.

A runner can wait for the host only when its parent can wait. In a run, an effect under a parent that cannot wait does not go to the host (decision D91). The effect keeps the outcome #CALC!, and the runner gives #CALC!. Pick a program and a host. The kernel does a run of the program, and the diagram shows each call of perform.

Program
Host

The runner log is a part of add. The evaluator add cannot wait, thus the host does not get the effect. The function perform gives a promise of 2.

addevaluator1logrunner"x"Hostperform…gives a promise of 2
EffectPayloadHost got itOutcome
The run goes on.
runner can wait for the host. evaluator cannot wait. A solid arrow is a call of perform. A dashed arrow that ends at a bar is an effect that the run held. The host does not get it, and the effect keeps #CALC!. The two hosts give the same facts.

The kind handle answers the effects of its body with its own clauses. The host does not get these effects. Thus a mock, a log or a retry is a document, and the body stays the same.

{
"type": "handle",
"value": {
"with": [{ "op": ["log"], "do": { "type": "ref", "value": ["names", "payload"] } }],
"body": { "type": "log", "value": [1] }
}
}
  • A clause do gives the result of the effect, and it reads names.payload.
  • A clause abort stops the body, and its result is the result of handle.
  • The field return changes the result of the body, and it reads names.result.

A clause has the capabilities of the handle document. An effect of a clause goes to the next handle out, and then to the host. A pure part under handle still causes no effect.