| 1 |
#!/usr/bin/env scheme-script |
| 2 |
|
| 3 |
(import (ikarus) (match)) |
| 4 |
|
| 5 |
(define (constant? x) |
| 6 |
(or (number? x) (char? x) (string? x) (boolean? x))) |
| 7 |
|
| 8 |
(define (ee x) |
| 9 |
(define (ee x env) |
| 10 |
(trace-match foo x |
| 11 |
[,c (guard (constant? c)) c] |
| 12 |
[,x (guard (symbol? x)) |
| 13 |
(cond |
| 14 |
((assq x env) => cdr) |
| 15 |
(else (error 'ee "unbound variable" x)))] |
| 16 |
[(let ([,x* ,[v*]] ...) ,b) |
| 17 |
(ee b (append (map cons x* v*) env))] |
| 18 |
[(+ ,[x] ,[y]) (+ x y)] |
| 19 |
[,others (error 'ee "invalid expression" others)])) |
| 20 |
(ee x '())) |
| 21 |
|
| 22 |
(pretty-print |
| 23 |
(ee '(let ((x 5)) (let ((y (+ x x))) (+ y x))))) |
| 24 |
|
| 25 |
;(new-cafe ee) |
| 26 |
|