functional programming

Steve Holden sholden at bellatlantic.net
Fri Feb 25 12:05:15 EST 2000


Moshe Zadka wrote:
> 
> > [Steve Holden's remarks about tail recursion]
> 
> Yes: the definition of "full dynamic context".
> You're not objecting that in
> 
> for i in range(10):
>         if i>8:
>                 raise ValueError()
> 
> The dynamic context does not include the context for i=0,...,8
> 
> But you do claim that in
> 
> def tail(n):
>         if n>8:
>                 raise ValueError
>         if n==10:
>                 return
>         return tail(n+1)
> tail(0)
> 
> The dynamic context includes that for i=0,...,8
> 
> Why?

Probably because I find it easier to mentally unfold iterations
than recursions when decoding a traceback.  Point taken.

> 
> I will repeat my claim, that no one except someone expecting
> tail-optimization does "return f(x)".
> 
Well, I *might* infer from this you are trying to claim that
everyone who writes "return f(x)" expects tail-optimization,
whereas I suspect many people who write that aren't even aware
that such a thing exists :-)

Still, as long as it's only an optimization, and thus doesn't
occur unless the optimizer comes into play I don't see much to
disagree about.

> but-it-doesn't-mean-it's-worth-it-ly y'rs, Z.
> --
> Moshe Zadka <mzadka at geocities.com>.
> INTERNET: Learn what you know.
> Share what you don't.

thinking-maybe-I've-followed-Z's-sig-too-closely-ly y'rs - Steve
--
"If computing ever stops being fun, I'll stop doing it"



More information about the Python-list mailing list