CS 3520 Homework 7   - Due October 25

Exercise 7.1, An Absurd Language

The interpreter similar to the one from the end of the October 18 lecture is in hw7.scm. It implements call-by-need procedures and well as lazy bindings (``let-by-need''), and it porvides call-by-reference arguments.

Your task is to modify the interpreter's language so that it supports call-by-value and call-by-name procedures, and also provides let-by-value and let-by-name local bindings. In particular,Hint: To implement both by-name and by-need forms, you will need to modify the implementation of environments to indicate whether a lazy binding in the environment should be updated with a forced value. The closure reprsentation is already modified to contain a kind field; you may also find that the provided closure-kind function is useful.

Examples:

let f = proc(x) +(x, x)
 in let y = 0
     in (f {set y = +(y, 1); y})
-> 2


let f = proc/name(x) +(x, x)
 in let y = 0
     in (f {set y = +(y, 1); y})
-> 3


let f = proc/need(x) +(x, x)
 in let y = 0
     in (f {set y = +(y, 1); y})
-> 2


let f = proc/name(x) +(x, x)
 in let y = 0
     in let z = {set y = +(y, 1); y}
         in (f z)
-> 2


let f = proc/name(x) +(x, x)
 in let y = 0
     in let/name z = {set y = +(y, 1); y}
         in (f z)
-> 3


let f = proc(x, w) +(x, w)
 in let y = 0
     in let z = {set y = +(y, 1); y}
         in (f z  z)
-> 2


let f = proc(x, w) +(x, w)
 in let y = 0
     in let/name z = {set y = +(y, 1); y}
         in (f z  z)
-> 3


let f = proc(w, x) +(x, x)
 in let y = 0
     in (f set y = 8  {set y = +(y, 1); y})
-> 18


let f = proc/name(w, x) +(x, x)
 in let y = 0
     in (f set y = 8  {set y = +(y, 1); y})
-> 3


let f = proc/need(w, x) +(x, x)
 in let y = 0
     in (f set y = 8  {set y = +(y, 1); y})
-> 2


let f = proc(&x) set x = +(x, 1)
  in let y = 10
      in { (f y) ; y }
-> 11


let f = proc(y, &x) { set x = *(x, 3); +(x, +(y, y)) }
  in let y = 10
      in (f { set y = +(y, 3); 7 } y)
-> 53


let f = proc(y, &x) { set x = *(x, 3); +(+(y, y), x) }
  in let y = 10
      in (f { set y = +(y, 3); 7 } y)
-> 53


let f = proc/name(y, &x) { set x = *(x, 3); +(x, +(y, y)) }
  in let y = 10
      in (f { set y = +(y, 3); 7 } y)
-> 44


let f = proc/name(y, &x) { set x = *(x, 3); +(+(y, y), x) }
  in let y = 10
      in (f { set y = +(y, 3); 7 } y)
-> 50


let f = proc/need(y, &x) { set x = *(x, 3); +(x, +(y, y)) }
  in let y = 10
      in (f { set y = +(y, 3); 7 } y)
-> 44


let f = proc/need(y, &x) { set x = *(x, 3); +(+(y, y), x) }
  in let y = 10
      in (f { set y = +(y, 3); 7 } y)
-> 47


Last update: Thursday, October 18th, 2001
mflatt@cs.utah.edu