Finite State Machines for Chicken Scheme
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Bowuigi 2a0600e299
Fixed macro not working
3 months ago
tests Uploaded to git 3 months ago
.gitignore Uploaded to git 3 months ago
README.md Uploaded to git 3 months ago
states.egg Uploaded to git 3 months ago
states.release-info Uploaded to git 3 months ago
states.scm Fixed macro not working 3 months ago
states.wiki Fixed wiki markup 3 months ago

README.md

States

Description

Simple Finite State Machine library.

State machines are a simple way to express the flow of a program through states and transitions, those, in turn, are defined in terms of easy rules, which typically include "where you can go to" and "is it ok to terminate the FSM here?". States currently only supports the first of those two, but may support the other one eventually.

GraphViz rendering may be supported eventually as well.

Author

Bowuigi

Repository

This egg is hosted on Codeberg:

https://codeberg.org/Bowuigi/States

Requirements

advice

Documentation

[syntax] (state-machine INITIAL (TRIGGER ! STATE -> POSSIBLE-TRANSITIONS ...) ...)

Creates a new state machine whose initial state is INITIAL, each TRIGGER is a procedure that will be injected the state change (set the current state to STATE) / validation (check if STATE is in previous state's POSSIBLE-TRANSITIONS), thus working like a transition callback. INITIAL, STATE and POSSIBLE-TRANSITIONS must be symbols, and there must be a POSSIBLE-TRANSITIONS definition for INITIAL so transitioning is possible.

Transitions (via triggers) should be done in tail call position as to not overflow the stack and also to avoid incorrect-state bugs.

[procedure] (machine-state MACHINE)

Retrieves the current state of MACHINE, mostly useful when a trigger is used for multiple states.

Example

Simple Cyclic state machine, included inside the test suite:

(import states)

(define (a) (print "In state A"))
(define (b) (print "In state B"))
(define (c) (print "In state C"))

(state-machine
  A
  (a ! A -> B)
  (b ! B -> C)
  (c ! C -> A))

(b) ; A -> B
(c) ; B -> C
(a) ; C -> A

License

Public Domain.

The code was written by Bowuigi and placed in the Public Domain. All warranties are disclaimed.