086-pmatch-basic.scm (691B)
1 ; Basic pmatch — literal-symbol head dispatch + simple binder + else. 2 ; The compiler will use this exact shape for form dispatch, so getting 3 ; it green is the smallest useful step. 4 5 (define e '(if a b c)) 6 7 (if (= 7 8 (pmatch e 9 ((quote ,x) (sys-exit 91)) 10 ((if ,t ,a ,b) 7) 11 (else (sys-exit 92)))) 12 0 (sys-exit 1)) 13 14 ;; Trailing else clause matches when nothing else does. 15 (if (= 11 16 (pmatch 42 17 ((1) (sys-exit 93)) 18 (else 11))) 19 0 (sys-exit 2)) 20 21 ;; Literal-integer pattern matches integers by =. 22 (if (= 99 23 (pmatch 5 24 (4 (sys-exit 94)) 25 (5 99) 26 (else (sys-exit 95)))) 27 0 (sys-exit 3)) 28 29 (sys-exit 0)