>>107076001
I like this style using functions
(define (dfa string)
(letrec
([s0 (state accept (0 -> s0) (1 -> s1))]
[s1 (state reject (0 -> s2) (1 -> s0))]
[s2 (state reject (0 -> s1) (1 -> s2))])
(s0 string)))
(dfa '(1 0 0 1)) => accept
(dfa '(0 1 0 1)) => reject
(define-syntax state
(syntax-rules (->)
[(_ a/r (s -> d) ...)
(lambda (a)
(cond
[(null? a) 'a/r]
[else
(case (car a)
[(s) (d (cdr a))]
...)]))]))
I used this for reading key sequences by adding a case that calls d with read-char