Skip to content

Instantly share code, notes, and snippets.

@jgarte
Forked from wasamasa/traffic-lights.el
Created May 19, 2021 06:47
Show Gist options
  • Save jgarte/f407a632649d1653d6f44510a49ce41a to your computer and use it in GitHub Desktop.
Save jgarte/f407a632649d1653d6f44510a49ce41a 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