Last active
May 19, 2019 22:55
-
-
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
This file contains hidden or 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
(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)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context: https://www.youtube.com/watch?v=yrf1AYtrKm0