X-Git-Url: https://git.rkrishnan.org/?p=sicp.git;a=blobdiff_plain;f=src%2Fsicp%2Fex4_28.rkt;fp=src%2Fsicp%2Fex4_28.rkt;h=c241853c121e6ea619242bd35655efeff3879bbb;hp=0000000000000000000000000000000000000000;hb=c6a6e187ad34b393587f51d181e2751f82f41aff;hpb=185aeca90595562fd31b2cdb730a12488d155348 diff --git a/src/sicp/ex4_28.rkt b/src/sicp/ex4_28.rkt new file mode 100644 index 0000000..c241853 --- /dev/null +++ b/src/sicp/ex4_28.rkt @@ -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