Another tail recursion example
Ian Kelly
ian.g.kelly at gmail.com
Tue Jul 28 18:06:23 EDT 2015
On Jul 28, 2015 1:36 PM, "Paul Rubin" <no.email at nospam.invalid> wrote:
>
> Paul Rubin <no.email at nospam.invalid> writes:
> > Chris Angelico was asking for examples of tail recursion that didn't
> > have obvious looping equivalents. Here's an Euler problem solution
> > using memoization and (except that Python doesn't implement it) tail
> > recursion with an accumulator.
>
> Actually that's wrong, it's not really tail recursive because of the
> addition in the memo combinator, whoops ;-).
Not just the addition, but the setdefault call as well. Without the
addition that call could be tail-call optimized, but that's not the
recursive call; the call to func is.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150728/546997da/attachment.html>
More information about the Python-list
mailing list