Subject: Re: Looking for examples of lisp-2's expressiveness
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 13 Aug 2003 09:19:13 -0500
Newsgroups: comp.lang.lisp
Message-ID: <5tmdnRfsPaB81aeiXTWc-g@speakeasy.net>
Kent M Pitman  <pitman@world.std.com> wrote:
+---------------
| Although it's valid to do so, I consider it poor style to have two
| functions use the same internal function name.  That is, I wouldn't do
|  (defun foo1 ()
|    (flet ((bar ...))
|      ...))
|  (defun foo2 ()
|    (flet ((bar ...))
|      ...))
+---------------

Though, actually, there's one pattern in which I *do* re-use the same
internal function name a lot, and that's when the internal function
is some sort of recursive (especially tree-walking) function, though
to be sure in, that case it's a LABELS instead of an FLET. The name
that gets (re)used [by me, at least] is most commonly AUX [yes, an
unfortunate name I got used to using in Scheme long before I knew
about CL's &AUX, FWIW], so that I do tend to see this kind of thing
fairly often in my code:

   (defun foo1 ()
     (labels ((aux ...))
       ...))

   (defun foo2 ()
     (labels ((aux ...))
       ...))

The bodies of fooN generally set up some initial stuff, and then make
one call to AUX, returning whatever it returns.

Hmmm... Looking at some of my old Scheme code, I see that one of the
more common patterns was converting a call with spread arguments into
a call with a single list arg, in CL:

   (defun foo (a b &rest rest)
     (labels ((aux (list)
		...))
       (aux rest)))

Another common pattern involved the outer function initializing one
or more accumulators, which the inner then passed around to itself
(possibly along with other args), e.g., a function which takes a bunch
of arguments and separates them out into separate categories might
look like:

   (defun foo (&rest rest)
     (labels ((aux (remaining accum1 accum2)
		...))
       (aux rest '() '())))

[Yes, I now know that LOOP can handle many of these cases.]


-Rob

-----
Rob Warnock, PP-ASEL-IA		<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607