(define test-1 (lambda () (equal? 6 (eval '((lambda (x) (+ x x)) (let ((y 1) (z 2)) (if (number? y) (+ y z) 9))))))) (define test-2 ; check for lexical scoping (lambda () (equal? 1 (eval '(let* ((x 0) (f (lambda (y) (+ 1 x))) (x 2)) (f 0)))))) (define test-3 (lambda () (equal? 6 (eval '((lambda (x) (+ x x)) (let ((y 1) (z 2)) (let* ((y (- y 1)) (y (+ y 1))) (if (number? y) (+ y z) 9)))))))) (define test-4 (lambda () (equal? 6 (eval '((lambda (x) (+ x x)) (let ((y 1) (z 2)) (if (number? y) (+ y z) 9))))))) (define test-5 (lambda () (equal? 6 (eval '((lambda (x) (+ x x)) (let ((y 1) (z 2)) (let* ((y (- y 1)) (y (+ y 1))) (if (number? y) (+ y z) 9)))))))) (define test-6 (lambda () (equal? 120 (eval '(letrec ((fact (lambda (n) (if (= 0 n) 1 (* n (fact (- n 1))))))) (fact 5)))))) (define test-7 (lambda () (equal? #t (eval '(letrec ((oddl (lambda (l) (if (not (pair? l)) #f (evenl (cdr l))))) (evenl (lambda (l) (if (not (pair? l)) #t (oddl (cdr l)))))) (oddl (cons 1 (cons 'a (cons 3 ()))))))))) (define test-8 (lambda () (equal? 4 (eval '(let* ((x 1) (y (set! x (+ x 3)))) x))))) (define test-9 (lambda () (equal? 0 (eval '(letrec ((Pi (lambda (l) (let/cc stop (if (null? l) 1 (if (zero? (car l)) (stop 0) (* (car l) (Pi (cdr l))))))))) (Pi (cons 1 (cons 2 (cons 0 (cons 3 (cons 4 ()))))))))))) (define test-10 (lambda () (eval '(letrec ((f (lambda () (f)))) (f))))) (define testit (lambda () (printf "1: ~a " (test-1)) (flush-output) (printf "2: ~a " (test-2)) (flush-output) (printf "3: ~a " (test-3)) (flush-output) (printf "4: ~a " (test-4)) (flush-output) (printf "5: ~a " (test-5)) (flush-output) (printf "6: ~a " (test-6)) (flush-output) (printf "7: ~a " (test-7)) (flush-output) (printf "8: ~a " (test-8)) (flush-output) (printf "9: ~a " (test-9)) (flush-output) (test-10) (printf "~%") (flush-output))) ;(testit) ;(exit)