# SICP Solutions

### Chapter 4, Metalinguistic Abstraction

#### Exercise 4.31

It’s an interesting exercise.

I just change make-procedure to contain params-types list too. for eg: if there is a procedure (define (proc (a lazy) b (c lazy-memo)) (+ a b c)), then params-types is a list '(lazy () lazy-memo).

Similar to procedure list-of-delayed-args, I implemented list-of-customized-args which just calls customize-it instead of delay-it.

customize-it is similar to delay-it except that it takes an extra argument for param-type and add tag 'lazy-thunk or 'memo-thunk depending if param-type is lazy or lazy-memo.

Apart from this there are cases added in force-it where memo-thunk case is handled as it was in book’s version.

Well thats it!

The code which contains the changes is below:

#### Output/Testing

First I tested with a small code:

Then, I tested it using ex-4.27 code.

Testing each version separately, normal, lazy and memoized by defining argument to procedure id in ex-4.27, as normal, lazy and lazy-memo.

Note there is a difference in how values of count changes between each version.

Without lazy or lazy-memo

With lazy argument

With memo-lazy:

#### Complete Code:

I have added changed in this file provided by mit.

Note: Sometimes this code: (ge (make-top-level-environment)) at the top does not correctly clear the environment. So, I executed this directly in scheme repl before loading the file.(I am using emacs). I wasted some time in it believing that there is a bug in code but the actual problem was this :(