A machine consists of
- A current set of bindings,
- The name of current node, and
- A (pointer to a) machine specification.
The top-level function (run
) takes a machine and a message as inputs
and outputs
- A new set of bindings,
- A new node name, and
- Zero or more messages as output.
-
A type name is a symbol representing a type. In this document a type name is a capitalized symbol formatted like
This
. -
An all-uppercase symbol represents a type variable. For example,
TYPE
represents any given type. -
The type
Nothing
is hard to define but it somehow means what it says. -
A type variable of the form
TYPE?
represents the type that's eitherTYPE
orNothing
. -
A
List<TYPE>
is an ordered finite set of elements of typeTYPE
. -
Set<TYPE>
is the type of a set that contains elements of typeTYPE
. -
Cross<TYPE1,...,TYPEN>
is the cross product of those types. -
A
Pair<LEFT,RIGHT>
is aCROSS<LEFT,RIGHT>
. The left side of a pair is called a key, and the right side is called a value. Wild, I know. -
A
Map<KEYTYPE,VALTYPE>
is aSet<Pair<KEYTYPE,VALTYPE>>
such that each key is unique. -
To specify a structure, we use the following representation:
{key1: TYPE1, ..., keyn: TYPEN}
with the obvious interpretation. A
key:TYPE
in a structure is called a component. A key is represented as a lower-case symbol likethis
.
-
Number
represents a number. -
String
represents a string. -
A
Expression
is either aNumber
,String
,Map<String,Expression>
, or aSet
of one of those types. -
A
Variable
is aString
. (In practice, by convention aVariable
is a string that starts with the character?
.) -
A
Message
is either aNumber
,String
,Map<String,Message>
, or aSet
of one of those types. -
A
Pattern
is either aVariable
,Number
,String
,Map<Variable,Pattern>
, or aSet
of one of those types. -
A
Bindings
is aMap<String,Message>
.
ToDo.
match
is a function from Cross<Pattern,Message,Bindings>
to
Set<Bindings>
.
ToDo.
Say we have a function bind
from Cross<Pattern,Bindings>
to
Pattern
, and this function replaces variables with their bindings.
If a Pattern p
's variables are all bound by some Bindings bs
, then
we say that "p
is bound by bs
" (bound(p,bs)↦true
).
The function match
has the following property (among others):
foreach p:Pattern
foreach m:Message
foreach bs in match(p,m,[]):
let bp = bind(p,b):
bound(bp) and match(bp,m,nil) != []
ToDo.
-
A
Specification
is a structure with the following components:name: String nodes: Map<NodeName,Node>
-
A
NodeName
is a string. -
A
Node
is a structure will the following components:type: Nodetype? action: Action? branching: Branching?
type
defaults to"bindings"
-
Nodetype
is either the literal"message"
or"bindings"
. -
An
Action
is a structure with the following components:interpreter: Interpreter source: Source
Technically the type
Source
depends on the typeInterpreter
, but we'll not head that way (for now).Practically speaking, an
Interpreter
is often just a string (perhaps a URL) that can be resolved to something that knows how to compile (optionally) and execute someSource
that's just aString
.Also in practice, an
Action
might have other components that theInterpreter
knows how to use. -
An
Interpreter
is a function fromSource
toExecution
. -
An
Execution
is a structure that contains at least the following components:bindings: Bindings emitted: Set<Message>
-
A
Branching
is aList<Branch>
. -
A
Branch
is a structure with the following components:pattern: Pattern? guard: Guard? target: NodeName
-
A
Guard
is (for now) anAction
that does not emit any messages (Execution.emitted
) when executed.
-
A
Machine
is a structure with the following components:nodeName: NodeName bindings: Bindings spec: Spec
In practice, the
spec
is a string that can be resolved to aSpec
or a pointer to aSpec
.
run
is a function from Cross<Machine,Message>
to Ran
.
-
Ran
is a structure with (at least) the following components:nodeName: NodeName bindings: Bindings emitted: Set<Message>
In practice, this structure can include other data such as trace records that include intermediate states.
Constraints ToDo!
-
run
can also include aControl
argument. -
Control
is a structure with the following components:stepLimit: NaturalNumber
More ToDo.