This is work in progress
A Deterministic Finite State Machine for Common Lisp and Parenscript.
Parenscript brings Lisp macros to front-end web development.
- Macro
defsm
- Function
apply-input
In a todo list, let us assume each task can have the following states:
- to-be-done
- in-progress
- in-review
- complete
A state machine accepts an input in order to change its state.
We can apply the following inputs only if that input is valid for the current state of the task.
- begin-work
- abort-work
- request-review
- accept
- reject
This library provides defsm
and defstates
to define the above FSM.
(defparameter *fsm*
(defsm
(defstates
(to-be-done
:transit-to (:begin-work in-progress))
(in-progress
:on-entry (notify-team) :transit-to (:request-review in-review)
(:abort-work to-be-done))
(in-review
:transit-to (:accept complete) (:reject in-progress))
(complete
:on-entry (notify-others-about-task-complete)
(move-item-from-todo-list-to-archive)))))
This library provides apply-input
to change the input of an fsm.
(apply-input *fsm* :begin-work)
(apply-input *fsm* :request-review)
(apply-input *fsm* :accept)
If an input cannot be applied in a particular state, an error condition is signalled.
- Remove the need for
defstates
becausedefsm
should suffice. defsm
should accept :on-exit forms.defsm
should maybe accept :on-transition forms.- Evaluate use cases and usefulness of nested states if they are useful.