Tail recursion (87)

18 Name: #!/usr/bin/anon 2006-02-24 19:25 ID:Gi6DzwCb

>>17
Functional programming languages don't insist that. Common Lisp has its loop macro, Scheme has iterative "do" syntax, and in Haskell the way you'd define factorial in practice is

fac n = product [1..n]

although you can do it iteratively too, if you must:

fac n = result (for init next done)
where init = (0,1)
next (i,m) = (i+1, m * (i+1))
done (i,_) = i==n
result (_,m) = m
for i n d = until d n i

Iteration is available in all these languages. It's just not the best tool for the job as often as you'd think.

This thread has been closed. You cannot post in this thread any longer.