Created
August 1, 2013 17:40
-
-
Save brianru/6133553 to your computer and use it in GitHub Desktop.
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
; call: (mktransition '(a more) | |
; expansion: | |
; (a (more (cdr str))) | |
(def mktransition (tn) (list (car tn) (list (last tn) '(cdr str)))) | |
; call: | |
; (mktransitions '((a more) | |
; (d more) | |
; (r end))) | |
; expansion: | |
; (a (more (cdr str)) | |
; d (more (cdr str)) | |
; r (end (cdr str))) | |
(def mktransitions (ts) | |
(accum accfn ; accum helps splice the result of mktransition | |
(each x (map1 mktransition ts) | |
(accfn (car x)) | |
(accfn (last x))))) | |
; call: | |
; (mkrule '(more (a more) (d more) (r end))) | |
; expansion: | |
; more (fn (str) | |
; (if (empty str) | |
; t | |
; (case (car str) | |
; a (more (cdr str)) | |
; d (more (cdr str)) | |
; r (end (cdr str))))) | |
(mac mkrule (r) | |
(let i r | |
`(list (car ,i) (fn (str) | |
(if (empty str) t | |
(case (car str) | |
,@(mktransitions (cdr i)))))))) | |
; example call: | |
; (automaton 'init | |
; '((init (c more)) | |
; (more (a more) | |
; (d more) | |
; (r end)) | |
; (end))) | |
(mac automaton (i r) `(withr/p ,(map1 [mkrule _] r) ,i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment