Skip to content

Instantly share code, notes, and snippets.

@et4te
Created June 2, 2011 13:37
Show Gist options
  • Save et4te/1004437 to your computer and use it in GitHub Desktop.
Save et4te/1004437 to your computer and use it in GitHub Desktop.
macros
;;-- 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