]> git.rkrishnan.org Git - sicp.git/blobdiff - src/sicp/ex4_28.rkt
Solutions to 4.27, 4.28 and 4.29.
[sicp.git] / src / sicp / ex4_28.rkt
diff --git a/src/sicp/ex4_28.rkt b/src/sicp/ex4_28.rkt
new file mode 100644 (file)
index 0000000..c241853
--- /dev/null
@@ -0,0 +1,18 @@
+#lang racket
+
+(require "metacircular2-lazy.rkt")
+
+#|
+Forcing is needed for any higher order procedure. An example is map. If you evaluate the following 
+code with `actual-value' instead of `eval' of operator, it executes fine but if not, then eval gets
+a thunk object (the two operands) for evaluation and when it reaches `apply' inside the `cons' it 
+will fail as `apply' does not know about thunk objects.
+|#
+
+(define env1 (make-environment))
+(eval '(define (map f xs)
+         (if (null? xs)
+             '()
+             (cons (f (car xs)) (map f (cdr xs)))))
+      env1)
+(eval '(map (lambda(x) (* x x)) '(1 2 3)) env1)
\ No newline at end of file