% $Id: ByNeedTest.oz,v 1.1 2007/11/02 17:54:16 leavens Exp leavens $ local Q in {ByNeed proc {$ ?R} R=3 end Q} {Browse Q} end local Q in {ByNeed proc {$ ?R} R=3 end Q} thread {Browse Q} end {Delay 2000} {Browse Q+7} end declare X thread X={ByNeed fun {$} 3 end} end {Browse X+7} Y=local R in thread R=3 end R end {Browse Y+8} Z=fun lazy {$} 3 end {Browse {Z}+9} % p. 283 of CTM declare X Y Z thread X = {ByNeed fun {$} 3 end} end thread Y = {ByNeed fun {$} 4 end} end thread Z = X+Y end {Browse Z} % The following gives an error (and should) % declare X Z % thread X = {ByNeed fun {$} 3 end} end % thread X = 2 end % thread Z = X+4 end % {Browse Z} declare X Y Z thread X = {ByNeed fun {$} 3 end} end thread X = Y end thread if X==Y then Z=10 end end {Browse output(x: X y: Y z: Z)} declare X Y Z % thread X = {ByNeed fun {$} 3 end} end thread X = Y end thread if X==Y then Z=10 end end {Browse output(x: X y: Y z: Z)} declare X Y Z thread X = {ByNeed fun {$} 3 end} end thread if X==3 then Z=10 end end {Browse output(x: X y: Y z: Z)} declare X Y Z X = {ByNeed fun {$} 3 end} Y = {ByNeed fun {$} 4 end} thread Z = X+Y end {Browse Z} declare X Y Z X = Y thread if X==Y then Z=10 end end {Browse output(x: X y: Y z: Z)}