Skip to content

Instantly share code, notes, and snippets.

@wasamasa
Created March 30, 2016 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wasamasa/72628e9a724e97bc82971ef86081cc24 to your computer and use it in GitHub Desktop.
Save wasamasa/72628e9a724e97bc82971ef86081cc24 to your computer and use it in GitHub Desktop.
Finite state machine
(defun traffic-lights ()
(let ((state 'red))
(while t
(cond
((eq state 'red)
(message "Red")
(sleep-for 1)
(setq state 'red+yellow))
((eq state 'red+yellow)
(message "Red+Yellow")
(sleep-for 0.5)
(setq state 'green))
((eq state 'green)
(message "Green")
(sleep-for 1)
(setq state 'yellow))
((eq state 'yellow)
(message "Yellow")
(sleep-for 1)
(setq state 'red))))))
(traffic-lights)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment