Essentials of Programming Languages (EOPL): Section 4.5 and Section 5.1.
You may work singly or in pairs on this assignment.
Be sure you mark (via comments) each change you make
to the interpreter files.
(See the Homework Policy
for more details.)
For Problems 1 and 2 below, assume that we are using lexical scoping.
Also assume that print is a
primitive that prints its arguments values on a line of output.
You do not have to supply pictures or traces to support your answers, but they sure will help in figuring out the answers.
Something like these questions will be showing up on the April 16 Quiz. So while you may want to confirm your answers with the EOPL interpreters, you need practice working out such things by hand.
set-expression always returns the
value 23.
let a = 3
b = 6
c = 9
in
let f = proc(w,x,y,z)
begin
set y = 1;
set b = 0;
set a = +(91,c);
set w = +(a,x);
print(w,x,z)
end
in begin
(f b +(b,c) c +(a,a));
print(a,b,c)
end
Fill in the following table with the values printed under each of the listed parameter-passing schemes.
print(w,x,z) from f
|
print(a,b,c) from the main begin-end |
|
| (a) Call-by-value | ||
| (b) Call-by-reference | ||
| (c) Call-by-name | ||
| (d) Call-by-need | ||
| (e) Call-by-value-result |
let x = 10
y = 20
z = 0
in
let g = proc(a,b,c)
begin
set y = +(b,c);
set b = +(a,c)
print(a,b,c)
end
in begin
(g y x +(y,z));
print(x,y,z)
end
Fill in the following table with the values printed under each of the listed parameter-passing schemes.
print(a,b,c) from g
|
print(x,y,z) from the main begin-end |
|
| (a) Call-by-value | ||
| (b) Call-by-reference | ||
| (c) Call-by-name | ||
| (d) Call-by-need | ||
| (e) Call-by-value-result |
EOPL Exercise 5.8.
Revised hint. Consider changing
rator-cont and rand-cont parts
of the continuation datatype along the lines of:
(rator-cont
(rands (list-of expression?)) ;; the list of operand expressions
(saved-env environment?)
(saved-cont continuation?))
(rand-cont
(pval expval?) ;; value of the operator
(vals (list-of expval?)) ;; list of values of operands
;; so far evaluated
(rands (list-of expression?)) ;; list of operand expressions
;; not yet evaluated
(saved-env environment?)
(saved-cont continuation?))
In the rator-cont case of
apply-cont test if there are any rands to evaluate.
If there are none, then life is simple. If there are some, then
evaluate the first operand expression and use the
continuation
(rand-cont val () (cdr rands) saved-env saved-cont)
The rand-cont case of
apply-cont can look something like:
(rand-cont (pval vals rands saved-env saved-cont) ;; Changed for HW 9
(if (null? rands)
...set up to the application...
...save the value work on the next item in rands))
Note that there is a list you might have to reverse at some point.
I will post answers to the first two Problems the evening of April 14.
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.