"STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS This exercise covers"
LABORATORY3: STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS This exercise covers Chapter 3.5‐5. Solutions to the problems should be handed in to before March 31. The solutions should be accompanied by Scheme code. The problems should be solved individually. This laboratory is substantially more complex than the two previous. The reason for this is 1) that the material in Chapter 4‐5 is more complicated and 2) that this laboratory replaces the final project assignment that I previously had plans for. All code examples from the book are available at http://mitpress.mit.edu/sicp/code/index.html . In this way you do not have to type everything in yourself. However, remember that certain things are different between, e.g., DR Scheme and the Scheme code in SICP. For example the Boolean literals are #t and #f rather than true and false. Hence, it is quite convenient with to define these to be the same, e.g., (define true #t). In order to be able to create streams (Chapter 3.5) in DrScheme you first have to define cons‐stream as (define‐syntax cons‐stream (syntax‐rules () ((cons‐stream head tail) (cons head (delay tail))))) You also have to add the following definitions: (define the‐empty‐stream ‘()) (define stream‐null? null?) 1. Solve Exercise 3.50 in SICP 2. Solve Exercise 3.54 in SICP 3. Solve Exercise 3.59 & 3.60 in SICP 4. Solve Exercise 3.73 in SICP 5. Solve Exercise 3.74 in SICP 6. Solve Exercise 3.78 in SICP 7. Solve Exercise 4.4 in SICP 8. Solve Exercise 4.6 in SICP 9. Consider the following procedure definitions: (define (square f) (lambda (x) (* (f x) (f x)))) (define (f n) (expt 2 n)) What is the value of ((square inc) 3) in a statically bound Lisp? What is the value in a dynamically bound Lisp? A meta‐circular evaluator with dynamic binding is obtained if the definitions of eval and apply from pg 365‐366 are changed as follows: (define (eval exp env) (cond ((self‐evaluationg? exp) exp) ((variable? exp) (lookup‐variable‐value exp env)) ((quoted? exp) (text‐of‐quotation exp)) ((assignment? exp) (eval‐assignment exp env)) ((definition? exp) (eval‐definition exp env)) ((if? exp) (eval‐if exp env)) ((lambda? exp) (make‐procedure (lambda‐parameters exp) (lambda‐body exp) env)) ((begin? exp) (eval‐sequence (begin‐actions exp) env)) ((cond? exp) (eval (cond‐>if exp) env)) ((application? exp) (apply (eval (operator exp) env) (list‐of‐values (operands exp) env) env)) ; CHANGED (else (error “Unknown expression type – EVAL” exp)))) (define (apply procedure arguments env) ; CHANGED (cond ((primitive‐procedure? procedure) (apply‐primitive‐procedure procedure arguments)) ((compound‐procedure? procedure) (eval‐sequence (procedure‐body procedure) (extend‐environment (procedure‐parameters procedure) arguments env))) ; CHANGED (else (error “Unknown procedure type – APPLY” procedure)))) In order to understand the difference between the different binding types you may need to study video lecture 7b once more. You can of course also run the evaluator as a program in the same way as in the text book 10. Solve Exercise 4.27 in SICP 11. Solve Exercise 4.59 in SICP 12. Solve Exercise 4.75 in SICP 13. Solve Exercise 5.1 and 5.2 in SICP 14. Solve Exercise 5.24 in SICP 15. Solve Exercise 5.33 and 5.34 in SICP