Thursday, January 29, 2009

Ch3, Ex9

declare Append
local IterReverse MyAppend in
fun {MyAppend L1 L2}
case L1 of nil then L2
[] X|Y then {MyAppend Y X|L2}
end
end
fun {IterReverse X Y}
case X of nil then Y
[] X1|X2 then {IterReverse X2 X1|Y}
end
end
fun{Append Xs Ys}
%{Browse {IterReverse Xs nil}}
{MyAppend {IterReverse Xs nil} Ys}
end
end
%Test
{Browse {Append [1 2 5 6 7] [3 4]}}

No comments:

Post a Comment