On Wed, 18 May 2011 07:19:08 +0200, Pascal J. Bourguignon wrote: > Roland Hutchinson <my.spamt...@verizon.net> writes: > >> Sorry to have to contradict you, > > Don't be sorry. > > >> but it really is a textbook example of recursion. Try this psuedo-code >> on for size: >> >> FUNCTION DIR-DELETE (directory) >> FOR EACH entry IN directory >> IF entry IS-A-DIRECTORY THEN DIR-DELETE (entry). >> >> Well, now that's not just recursion; it's tail recursion. > > It's not tail recursion. If you had indented your code properly, you'd > see why it's not: > > (defun dir-delete (directory) > (loop for entry in directory > do (if (is-a-directory entry) > (dir-delete entry)))) >
You are right, of course. Thanks for the correction. > (I put parentheses, so my editor knows what I mean and can do the > indentation for me). My editor would have done that, too--if I had bothered to be thinking clearly. > That's why walking a directory is done with a recursive procedure, > instead of an iterative one: it's much simplier. To implement an > iterative procedure, you would have to manage a stack yourself, instead > of using the implicit stack of the recursive procedure. Got it! Thanks again. -- Roland Hutchinson He calls himself "the Garden State's leading violist da gamba," ... comparable to being ruler of an exceptionally small duchy. --Newark (NJ) Star Ledger ( http://tinyurl.com/RolandIsNJ ) -- http://mail.python.org/mailman/listinfo/python-list