... and you can further 'optimize' it by avoiding allocation of the
unbound tail variable in the base case:
declare
Factorial =
local
fun {Factorial N I Head Tail Last}
if I>N
then Tail=nil Head
else NewLast=I*Last NewTail in
Tail=NewLast|NewTail
{Factorial N I+1 Head NewTail NewLast} end end in
fun {$ N}
if N==0
then [1]
else Tail in {Factorial N 1 1|Tail Tail 1} end end end
{Browse {Factorial 5}}
% [1 1 2 6 24 120]
vQ
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users