Skip to content

Instantly share code, notes, and snippets.

@danielsz
Last active May 19, 2019 22:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsz/0cab5dabfd4bfe4f3eb6f3f6fcd1c9d1 to your computer and use it in GitHub Desktop.
Save danielsz/0cab5dabfd4bfe4f3eb6f3f6fcd1c9d1 to your computer and use it in GitHub Desktop.
Refactoring of William Byrd's higher-order implementation of a finite state machine with driver
(define fsm-ho2
(lambda (str)
(letrec ([S0 (lambda (b)
(case b
[(0) S0]
[(1) S1]
[else #t]))]
[S1 (lambda (b)
(case b
[(0) S2]
[(1) S0]
[else #f]))]
[S2 (lambda (b)
(case b
[(0) S1]
[(1) S2]
[else #f]))]
[driver (lambda (str state)
(cond
[(null? str) (state #f)]
[else (driver (cdr str) (state (car str)))]))])
(driver str S0))))
@danielsz
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment