Created
March 30, 2016 07:54
-
-
Save wasamasa/72628e9a724e97bc82971ef86081cc24 to your computer and use it in GitHub Desktop.
Finite state machine
This file contains hidden or 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
(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