Due: Tuesday, Dec 13th by 11:59 PM

Your Task

Do the following two exercises from the textbook:

  • Exercise 4.20 (on page 121): use lecture22.scm as a starting point
  • Exercise 5.8 (on page 153): use lecture23.scm as a starting point see below

Here is a head start on Exercise 5.8: a version of the continuation-passing interpreter which

  • accepts procedures with multiple parameters
  • accepts procedure applications with multiple arguments
  • has support for evaluating multiple argument expressions and binding them to parameters, but only evaluates and passes the result of the first argument expression

lecture23-improved.scm

Hints/Testing

Testing for exercise 4.20:

% result should be 5
letmutable x = 4
  in begin
       set x = 5;
       x
     end
% should fail with an error (assignment to immutable variable)
let x = 4
  in begin
       set x = 5;
       x
     end

Testing for exercise 5.8:

% result should be 5
let f = proc(x, y)
          -(x, -(0, y))
  in (f 2 3)

You can add the following procedures to your programs to simplify testing:

(define expval->schemeval
  (lambda (result)
    (cases expval result
      (num-val (n) n)
      (bool-val (b) b)
      (proc-val (p) p))))

(define exec
  (lambda (progtext)
    (let* ((prog (parser progtext))
           (result (value-of-program prog (empty-env))))
      (expval->schemeval result))))

Use the exec procedure as follows:

(exec "
program
")

For example:

(exec "
let f = proc(x, y)
          -(x, -(0, y))
  in (f 2 3)
")

should produce the result 5 when run using the finished interpreter for exercise 5.8.

Grading

  • Exercise 4.20 - 50%
  • Exercise 5.8 - 50%

Submitting

Submit a zip file containing two Scheme files, one for exercise 4.20 and another for exercise 5.8.

Submit the zip file to Marmoset as assign7:

https://cs.ycp.edu:8443/

IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct file(s). You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.