Thursday, February 5, 2009

Ch6, Ex10

Swap code impl with call by need:
declare
proc {Swap X Y}
Xarg = {X}
Yarg = {Y}
T = {NewCell @Xarg}
in
Xarg:=@Yarg
Yarg:=@T
end

Counterintuitive behavior does not occur with this version.

Sqr code call by need impl with using laziness:
declare
proc {Sqr A}
B={A}
in
B:=@B*@B
end

local C={NewCell 0} in
C:=25
%made the argument function lazy
{Sqr fun lazy {$} C end}
{Browse @C}
end

No comments:

Post a Comment