CIS 352   —   SPRING 2008

Homework 9


Coverage

This homework covers material in Chapter 3 of Essentials of Programming Languages (EOPL).

Logistics

This homework is due in the bin in CST 3-212 by noon on Friday, April 11.

You may work singly or in pairs on this assignment.


EXERCISES


EXERCISE 1   (30 points)

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


EXERCISE 2   (30 points)

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


Back to the CIS 352 Homepage
Jim Royer /