ikarus/other-libs/test-match.ss

29 lines
728 B
Scheme
Raw Normal View History

2007-12-11 17:41:48 -05:00
#!/usr/bin/env scheme-script
(import (ikarus) (match))
(define (constant? x)
(or (number? x) (char? x) (string? x) (boolean? x)))
(define (ee x)
(define (ee x env)
(trace-match foo x
[,c (guard (constant? c)) c]
[,x (guard (symbol? x))
(cond
((assq x env) => cdr)
(else (error 'ee "unbound variable" x)))]
;[(let ([,x* ,v*] ...) ,b)
; (ee b (append (map cons x* (map (lambda (x) (ee x env)) v*)) env))]
[(let ([,x* ,[v*]] ...) ,b)
(ee b (append (map cons x* v*) env))]
[(+ ,[x] ,[y]) (+ x y)]
[,others (error 'ee "invalid expression" others)]))
(ee x '()))
(pretty-print
(ee '(let ((x 5)) (let ((y (+ x x))) (+ y x)))))
;(new-cafe ee)