https://github.com/fbeline/fsm-clj
A Clojure library designed to create deterministic finite state machines.
https://github.com/fbeline/fsm-clj
Last synced: about 1 year ago
JSON representation
A Clojure library designed to create deterministic finite state machines.
- Host: GitHub
- URL: https://github.com/fbeline/fsm-clj
- Owner: fbeline
- License: epl-1.0
- Created: 2018-09-21T04:23:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-21T23:25:15.000Z (over 7 years ago)
- Last Synced: 2025-04-20T19:38:51.683Z (about 1 year ago)
- Language: Clojure
- Size: 53.7 KB
- Stars: 36
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# fsm-clj
[](https://clojars.org/fsm-clj)
A Clojure library designed to create deterministic finite state machines.
- Easy to use flat one level state machine.
- Define state machines that can accumulate values.
- Transitions with actions and guards.
- Graphically visualize the resulting state machines.
Refer to the [documentation](doc/documentation.md) for more details.
## Quick Start
Require the fsm-clj core name space.
```clj
(:require [fsm-clj.core :refer :all])
```
Define a simple traffic light state machine.
```clj
(defsm traffic-light
[[:green -> :yellow when :to-yellow]
[:yellow -> :red when :to-red]
[:red -> :green when :to-green]])
```
Sending events.
```clj
(-> (traffic-light)
(send-event :to-yellow)
:state) ;; => :yellow
```
Graphically generate the State Machine (open a Swing viewer).
```clj
(show! (traffic-light))
```

## License
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.