```------art_12914_23737615.1135366588960
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

ah, but to me that isn't completely iterative.... iterative is using a loop
within a function to make sure it and all functions it calls do not call
back up the tree...

hence:

# yes assumptions about positive integer numbers...
# complete recursive:

def factorial( x )
return 0 if x < 1
x * factorial( x - 1 )
end

# tail-recursive:

def factorial( x, sum = 1 )
return 0 if x < 1
factorial( ( x - 1 ), ( sum * x ) )
end

# iterative:

def factorial( x )
sum = 1
for i in (1..x).to_a
sum *= i
end
end

... anyways.

j.

On 12/23/05, Christian Neukirchen <chneukirchen / gmail.com> wrote:
>
> Jeff Wood <jeff.darklight / gmail.com> writes:
>
> > ... I believe the question was in regards to implementing factorial in a
> > tail-recursive manner.
> >
> > I believe the statement was:
> >
> > "I'm a complete newb to lisp, I've been reading Practical Common Lisp &
> On
> > Lisp.  I've also been working through "The little schemer" and SICP...
> I'm
> > running CMUCL under SLIME & Emacs (v21.4). ( phew ) ... I've written an
> > iterative & a normally recursive version of factorial ... Now I'm trying
> to
> > figure out how to implement it in a tail-recursive fashion ... can
> anybody
> > help me write a tail-recursive version ?? I'm not familiar with the call
> > pattern yet." ...
>
> I see, the iterative version at
>   http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html#%_thm_3.9
> actually is the tail-recursive version. :-)
>
> They could have told you that, of course.
>
> > or something like that ...
> >
> > Jeff Wood
> --
> Christian Neukirchen  <chneukirchen / gmail.com>  http://chneukirchen.org
>
>

--
"Remember. Understand. Believe. Yield! -> http://ruby-lang.org"

Jeff Wood

------art_12914_23737615.1135366588960--

```