Essentials of Programming Languages (EOPL): Sections 3.1 and 3.2.
You may work singly or in pairs on this assignment.
Be sure you mark (via comments) each change you make
to the LET interpreter files.
(See the Homework Policy
for more details.)
A copy of the source code of each file modified.
DO NOT turn in the source code from files you did not modify.
A run of your code that verifies that it passes all the tests in your test harness.
If you have more than one file to submit, bundle them into a zip or tar archive.
Click on
this
electronic-submission link,
and use your NetID and password for authorization.
Important: Make sure you select CIS 352 as the course
for which you're submitting.
For the following, build on the extensions you did for Lab 5.
(33 points) EOPL Exercise 3.8.
(34 points) EOPL Exercise 3.12.
(33 points) EOPL Exercise 3.15.
For Exercise 3.12, add the following to the-grammar
in lang.scm:
(expression
("cond" (arbno expression "==>" expression) "end")
cond-exp)
A cond-exp has two components,
The code you add to value-of for this exercise
will look like:
(cond-exp (tests results)
(if (null? tests)
(eopl:error "value-of: no clause of cond held")
(let ((test1 (car tests))
(result1 (car results)))
...)
))
If test1 fails to evaluate to true,
then you will have to do a recursion that looks like:
(value-of (cond-exp (cdr tests) (cdr results)) env)
Here are some tests for your implementation of cond:
;; Homework 4, problem 2 tests (cond-1 "cond zero?(0) ==> 1 zero?(17) ==> 2 end" 1) (cond-2 "cond zero?(17) ==> 1 zero?(0) ==> 2 end" 2) (cond-3 "cond zero?(1) ==> 1 zero?(2) ==> 2 zero?(0) ==> 3 end" 3) (cond-4 "cond zero?(17) ==> 1 zero?(17) ==> 2 end" error) (cond-5 "cond end" error)
For Exercise 3.15, recall that the body's of
lets can have a sequence of
expressions, the value of the last one
is returned. For example, try evaluating:
(let ((val1 (+ 9 23))
(val2 (- 100 3)))
(display val1)
(display "\n")
(display val2)
(display "\n")
'all-done)
run-all can occasionally
be misleading. If you get an error report that does not make
sense, try running that case via run. For example,
I had the test
(div-2 "/(4,2)" 2)and got the report
test: div-5 /(4,2) correct outcome: 2 actual outcome: 2 incorrectWhen I ran
(run "/(4,2)") what came back
was 2
and of course what should have come back was
#(struct:num-val 2). When I added the call to
num-val to the div-case, the interpreter then
passed all tests.