CSSE 304 Exam 2 Part 2 10/16/2018 (day 26.5) Name_____________________ Section (circle one): 01(9:00) 02 (9:55) 03 (10:50)
Problem
Possible
Earned
Comments
1
20
Unless you have an accommodation in writing, you may not use email, IM, cell phone, PDA, headphones, earbuds, or any other communication Efficiency and elegance will not affect you score, provided that I can understand your code.
Part 2 Enhance your interpreter (paper) For this part, the only resource you are allowed to use is your interpreter printout. Write a page number at the bottom of each page of your printout. Then write the code changes and/or additional code for this
problem at the appropriate places in the printout.
When you have finished, please show in the table below the pages of your printout in which you have modified or added code. If you did not change one or more of the listed parts of the code, write ¡°NONE¡± for each of them.
> (list
(eval-one-exp ‘
(let ([a 3] [b (list 4)])
(when (< a 5)
(set-car! b (+ (car b) a))
(set-car! b (+ (car b) a)))
b))
(eval-one-exp '
(let ([a 3] [b (list 3)])
(when (> a 5)
(set-car! b (+ (car b) a))
(set-car! b (+ (car b) a)))
b)))
((10) (3))
> (list
(eval-one-exp ‘
(let ([a 3] [b (list 4 5)])
(when (< a 5)
(set-car! (cdr b) (+ (car b) a))
(set-car! b (+ (car b) a)))
(set-car! b (+ (car (cdr b)) a))
b))
(eval-one-exp '
(let ([a 3] [b (list 3 4)])
(when (> a 5)
(set-car! (cdr b) b (+ (car b) a))
(set-car! b (+ (car b) a)))
b)))
((10 7) (3 4))
Additions/changes to
Page number(s) (or NONE)
expression datatype
other datatype(s)
parse-exp and procedures that it calls
syntax-expand and other procedures that it calls
apply-env
eval-exp
apply-proc
other
1. (20 points) Enhance your interpreter so that it implements Chez Scheme’s when syntax. Here is the description of when from The Chez Scheme User’s Guide:
syntax: (when test-expr expr1 expr2 …)
Instructor¡¯s Note: to get that unspecified behavior, you may simply use Scheme¡¯s “one-armed ¡° if (no else part) in your
implementation of when.
See the above examples in the transcript.
Since this should be an easy problem for students who understand the interpreter, I plan to grade it fairly strictly. Please write clearly.
If test-expr evaluates to a true value, the
expressions expr1 expr2 … are evaluated in sequence, and the value of the last expression is returned.
If test-expr evaluates to false, none of the other expressions are evaluated, and the value of when is unspecified.