site.fabricate.prototype.fsm Namespace

Namespace for defining finite schema machines. A finite schema machine is a method of organizing the functions to be called in a program by the state of the data passing through the program. Those states are defined using malli schemas.

It is similar in concept to the idea of a state-action behavior in Leslie Lamport's 2008 paper 'Computation and State Machines', but the formalism is not as rigorous.

For background on the concepts informing this design, please see Organizing Computation With Finite Schema Machines.

Functions


complete
Description
Completes the fsm by advancing through states until the same value is produced twice.
Arguments
  • [fsm-map value & args]
advance
Description
Takes a value, matches it against the schema keys defined in the input state-action map, and calls the appropriate function to advance the value to the next state. Additional arguments to the function can be supplied via & args; they will be appended to the arguments passed to the matched function via apply. Errors in function execution will be printed and the input value will be returned.
Arguments
  • [fsm-map value & args]
fsm-value-map?
Description
Predicate indicating whether the given value defines a finite schema machine.
Arguments


    Constants


    fsm-value-map
    Description
    Malli schema for maps defining finite schema machines.
    Type
    :malli.core/schema
    state-action-map
    Description
    Malli schema for the map where each entry is a ⟨s,α⟩ tuple, "where s is a state states and α is an action." The action performs the transition from s to a target state specified by the signature of α. In this implementation, states are defined by a malli schema. See Lamport [2008] - "Computation and State Machines"
    Type
    :malli.core/schema