Another tail recursion example
ian.g.kelly at gmail.com
Wed Jul 29 00:06:23 CEST 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...
More information about the Python-list