Created
June 2, 2011 13:37
-
-
Save et4te/1004437 to your computer and use it in GitHub Desktop.
macros
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
;;-- abstract state machine model | |
;; types | |
defclass state | |
defclass input | |
def transition (state input) | |
documentation: "Transition from a state to another state" | |
defmacro defstate { ?:name } => | |
`defclass ?name is state` | |
defmacro definput { ?:name } => | |
`defclass ?name is input` | |
defmacro deftransition { ?state-1 ?:input ?state-2 } => | |
`def transition (s is ?state-1, i is ?input) | |
?state-2()` | |
;; convert names to instances | |
def names-to-instances (names) | |
loop for name in names collect name() | |
;;-- tutorial state machine | |
;; states | |
defstate start | |
defstate room-1 | |
defstate room-2 | |
defstate room-3 | |
;; inputs | |
definput forward | |
definput back-to | |
;; transitions | |
deftransition start forward room-1 | |
deftransition room-1 back-to start | |
deftransition room-1 forward room-2 | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment