Created
May 27, 2017 12:33
-
-
Save fmnoise/9fcc77cc65779f079078a2ab4d084943 to your computer and use it in GitHub Desktop.
Moore machine using atom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn make-transitions [& states] | |
(let [statemap | |
(zipmap | |
(map str states) | |
(rest (conj (vec states) (first states))))] | |
(fn [state] (statemap (str state))))) | |
(def moore-machine (atom :stopped)) | |
(def transitions (make-transitions :starting :started :stopping :stopped)) | |
(swap! moore-machine transitions) ;; :starting | |
(swap! moore-machine transitions) ;; :started | |
(swap! moore-machine transitions) ;; :stopping | |
(swap! moore-machine transitions) ;; :stopped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment