This homework is due in the bin in CST 3-212 by
You may work singly or in pairs on this assignment.
For both problems below, assume that we are using lexical scoping.
Also assume that write is a
primitive that prints its arguments values on a line of output.
You do not have to supply pictures to support your answers, but they sure will help in figuring out the answers.
Something like these questions will be showing up on Exam 3. 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 1.
let a = 3
b = 6
c = 9
in
let f = proc(w,t,s,r)
begin
set s = 1;
set w = *(2,t);
set b = 0;
set a = *(10,c);
set w = +(a,t);
write(w,t,r)
end
in begin
(f b +(b,c) c *(a,2));
write(a,b,c)
end
Fill in the following table with the values printed under each of the listed parameter-passing schemes.
write(w,t,r) from f
|
write(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 m = 5
n = 7
p = 13
in
let g = proc(x,y)
begin
set m = y;
+(x,3)
end
in
let h = proc(a,b,c,d)
begin
set a = c;
set p = +(a,c);
set d = +(d,p);
set a = add1(a);
write(a,b,d)
end
in begin
(h m +(m,p) (g n p) p);
write(m,n,p)
end
Fill in the following table with the values printed under each of the listed parameter-passing schemes.
write(a,b,d) from h
|
write(m,n,p) 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 |