CS 3520 Homework 8 - Due October 25
Exercise 8.1, Parameter-Passing Variations
Given the following expression in the interpreter language from class:
let x = 0
f = proc(y) set y=+(y,y)
in let z = { set x=+(x,1) ; x }
in { (f z) ; z }
what does the expression produce in the following configurations of the interpreter?- All procedure arguments are call-by-value.
- All procedure arguments are call-by-reference (even without the &).
- All procedure arguments and let bindings are call-by-name.
- All procedure arguments and let bindings are call-by-need.
- All procedure arguments and let bindings are both call-by-name and call-by-reference (a bizarre combination).
Your task: Express your answer as a function named answer-for-8.1 that returns a list of five numbers, one for each part above (in order). Include the function with the modified interpreter for 8.2.Check: The sum of the numbers in the list should be 11.Exercise 8.2, Parameter-Passing Variations in an Interpreter
Start with this code, which defines a call-by-need interpreter like the most recent one in class.
In addition to the interpreter, the starting code defines four boolean variables:- call-by-value?
- call-by-name?
- call-by-need?
- call-by-reference?
Only one of the first three can be #t at any time, but the fourth is independent of the others.Your task: Modify the interpreter so that its behavior depends on the configuration of the four boolean variables:- When call-by-value? is #t, procedure arguments should be passed by value (just as for part 1 of 8.1).
- When call-by-name? is #t, procedure arguments and let bindings should be evaluated by name (just as for parts 3 and 5 of 8.1).
- When call-by-need? is #t, procedure arguments and let bindings should be evaluated by need (just as for part 4 of 8.1).
- When call-by-reference? is #t, procedure arguments should be passed by reference, even if the variable has no & (just as for parts 2 and 5 of 8.1).
For example, you will need to modify eval-let-rands as follows:
(define eval-let-rands
(lambda (rands env)
(map (lambda (x) (if call-by-value?
(evaluate-expression x env)
(thunkify-expression x env)))
rands)))
The code in 8.1 provides a useful test case for your modified interpreterWhen you hand in the code, the values of the boolean variables do not matter. We will set the variables when testing your interpreter.
Last update: Thursday, October 19th, 2000mflatt@cs.utah.edu |