]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex4_28.rkt
Solutions to 4.27, 4.28 and 4.29.
[sicp.git] / src / sicp / ex4_28.rkt
1 #lang racket
2
3 (require "metacircular2-lazy.rkt")
4
5 #|
6 Forcing is needed for any higher order procedure. An example is map. If you evaluate the following 
7 code with `actual-value' instead of `eval' of operator, it executes fine but if not, then eval gets
8 a thunk object (the two operands) for evaluation and when it reaches `apply' inside the `cons' it 
9 will fail as `apply' does not know about thunk objects.
10 |#
11
12 (define env1 (make-environment))
13 (eval '(define (map f xs)
14          (if (null? xs)
15              '()
16              (cons (f (car xs)) (map f (cdr xs)))))
17       env1)
18 (eval '(map (lambda(x) (* x x)) '(1 2 3)) env1)