From: Ramakrishnan Muthukrishnan Date: Mon, 2 Jan 2012 15:14:55 +0000 (+0530) Subject: test for internal definition and letrec X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/about/(%5B%5E?a=commitdiff_plain;h=96cdf5478550693d1e236a53e3390e2d59d59940;p=sicp.git test for internal definition and letrec --- diff --git a/src/sicp/metacircular2-test.rkt b/src/sicp/metacircular2-test.rkt index 563b0ec..a4c23ea 100644 --- a/src/sicp/metacircular2-test.rkt +++ b/src/sicp/metacircular2-test.rkt @@ -34,7 +34,35 @@ (* x z)) env1) 39 - "let* test")))) + "let* test") + (eval '(define (f x) + (define (even? n) + (if (= n 0) + true + (odd? (- n 1)))) + (define (odd? n) + (if (= n 0) + false + (even? (- n 1)))) + (odd? x)) + env1) + (check-equal? (eval '(f 2) env1) false "internal definitions") + (check-equal? (eval '(f 3) env1) true "internal definitions") + (eval '(define (f1 x) + (letrec ((even? + (lambda (n) + (if (= n 0) + true + (odd? (- n 1))))) + (odd? + (lambda (n) + (if (= n 0) + false + (even? (- n 1)))))) + (even? x))) + env1) + (check-equal? (eval '(f1 2) env1) true "internal definitions") + (check-equal? (eval '(f1 3) env1) false "internal definitions")))) (run-tests metacircular2-tests) \ No newline at end of file