Recursively traverse linked list -- help!

Paul Rubin phr-n2002a at nightsong.com
Wed Feb 20 18:37:18 EST 2002


"Jason Orendorff" <jason at jorendorff.com> writes:
> > > def f(val):
> > >   global f
> > >   f = val and f1 or f2
> > >   return f(val)
> > 
> > This is not tail recursion.  The "global f" declaration shadows
> > the "f" that names the function.
> 
> That's not true.  The f that names the function is global anyway.
> It's the assignment that causes the problem.

Oh yes, you're correct.  However, the tail call should still be
optimized, compiled as an indirect jump to f.



More information about the Python-list mailing list