Concrete Proposal: while ... and while ...

Michael Vanier mvanier at bbb.caltech.edu
Fri May 21 00:28:35 EDT 1999


quinn at krone.ugcs.caltech.edu (Quinn Dunkan) writes:

> On 20 May 1999 18:42:08 GMT, Graham Matthews <graham at sloth.math.uga.edu> wrote:
> >Michael P. Reilly (arcege at shore.net) wrote:
> >: Seriously, a very well-defined, simple concept for iteration is
> >: recursion: in some form most any application for a loop can be
> >: expressed as some form of recursion (except in Fortran ;).  In many of
> >: the right applications, recursion is easy-to-follow, intuitive and more
> >: efficient.  Recursion (usually) requires no change in the language to
> >: impliment.  Why don't we use recursion more often?  I think when people
> >: answer that question themselves, they'll probably understand my point.
> >
> >People don't use recursion much because most people are taught iteration
> >before recursion and hence find recursion somewhat unnatural. Those who
> >learnt recursion first find iteration to be clunky (for example recursion
> >is much more amenable to proof, and recursion corresponds more naturally
> >with sub-problem decomposition). 
> 
> I belong to the latter group, but I think another reason why non-functional
> programmers don't use much recursion is that non-functional languages don't
> optimize it to be efficient.  I used to use recursion in Python all the time,
> but then I started getting 'Maximum recusion depth exceeded', recoded with
> loops, and suddenly things were a lot faster too :)  Tail-recursion would be
> nice, but python is so dynamic I don't know if it would be possible.  Dylan
> seems to get it in there somehow, though, so maybe it is possible?


Huh?  Scheme is explicitly tail-recursive by definition, and I don't know of
any way that python is "more dynamic" than scheme.  I don't think dynamism is
the issue.  What did you have in mind?

As for which is more natural, I think it also depends a lot on the problem in
question as well as early experience, variations in individuals' brain
chemistry etc. :-)  Personally, I'd resist using recursion where an iterative
construct will work just as well, just to save a couple of brain calories.
However, if I were trying to prove a function correct, I might choose
recursion instead.

tail-recursion-is-just-goto-on-steroids-ly y'rs,

Mike



-------------------------------------------------------------------------
Mike Vanier	mvanier at bbb.caltech.edu
Department of Computation and Neural Systems, Caltech 216-76
Will optimize nonlinear functions with complex parameter spaces for food.




More information about the Python-list mailing list