Last active
November 1, 2021 14:26
-
-
Save GlassGhost/3d90c9818546fa985d3d6e876bac8ea1 to your computer and use it in GitHub Desktop.
gsi v4.9.3 owner@localhost:~/sync/Scripts/Lambda$ gsi ./automaton.scm *** ERROR IN "automaton.scm"@21.30 -- Ill-formed selector list
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
;#!/usr/bin/env scheme-r5rs | |
;https://github.com/carld/automata-via-macros | |
(define-syntax automaton ;https://cs.brown.edu/~sk/Publications/Talks/SwineBeforePerl/ | |
(syntax-rules (:) | |
[(_ init-state | |
(state : response ...) ...) | |
(let-syntax | |
([process-state | |
(syntax-rules (accept ->) | |
[(_ accept) | |
(lambda (stream) | |
(cond | |
[(null? stream) #t] | |
[else #f]))] | |
[(_ (label -> target) (... ...)) | |
(lambda (stream) | |
(cond | |
[(null? stream) #f] | |
[else (case (car stream) | |
[(label) (target (cdr stream))] | |
(... ...) | |
[else #f])]))])]) | |
(letrec ([state (process-state response ...)] ...) | |
init-state))])) | |
(define m2 | |
(automaton init | |
[init : (c -> more)] | |
[more : (a -> more) | |
(d -> more) | |
(r -> end)] | |
[end : accept])) | |
(define-syntax test | |
(syntax-rules() | |
((_ expression expectation) | |
(cond | |
((equal? expression expectation) | |
(display "TEST OK" )(newline)) | |
(else (error "Unexpected result " expression)))))) | |
(test (m2 `(c a d r)) #t) | |
(test (m2 `(c d a a d r)) #t) | |
(test (m2 `(r)) #f) | |
(test (m2 `(i)) #f) | |
(test (m2 `(a)) #f) | |
(test (m2 `(c)) #f) | |
(test (m2 `(c a r)) #t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment