CIS 352   —   SPRING 2009

Homework 9 — Revision 1

Problems 1 and 2 have been simplified.


Coverage

This homework covers material in

Logistics


PROBLEMS


PROBLEM 1   (30 points)

Consider the following code:
  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


PROBLEM 2   (30 points)

Consider the following code:
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


PROBLEM 3   (40 points)

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.

Notes


What to Turn in:

How to turn in your work:

  1. If you have more than one file to submit, bundle them into a zip or tar archive.

  2. 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.

Back to the CIS 352 Homepage
Jim Royer /