[REBOL] Re: Tail end recursion
From: maarten:vrijheid at: 9-Oct-2003 17:23
> so basically its like using recursion to do a loop?
>
Nope.
> something: does [print "."]
>
> forever [
> do something
> ]
>
> is somewhat equivalent to?:
>
> something: does [
> something
> ]
>
> in F: func [x][x: x + 1 print x f x]
>
> but how does tail-end recursion stop?
>
> how does F ever end?
F: tail-func [x][if x > 1000 [ return x ] x: x + 1 print x f x]
Which shows the difference with your example.
I use tail-func to recursively traverse a tree structure that is mapped
to a table in a relational database, updating the number of leafs per
node. So I traverse the tree passing in the tree, updating the counters,
and then calling itself with the rest of the tree (subtree).
--Maarten