Peter,

I wrote my program off the top of my head, when I didn't have access to an
interpreter. But, hopefully, you could figure out how to fix it. ;)

Here's the corrected version:

fun {FactLoop I N Acc}
    if I==N
    then Acc
    else {FactLoop I+1 N (I+1)*Acc.1|Acc}
    end
end

fun {Fact N}
    {FactLoop 1 N [1]}
end

You could also, as Waclaw points out, bury the FactLoop definition inside
Fact:

fun {Fact N}
    fun {Loop I N Acc}
        if I==N
        then Acc
        else {Loop I+1 N (I+1)*Acc.1|Acc}
        end
    end
in
        {Loop 1 N [1]}
end

- Lyle
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to