Subject: Re: That result arg to dolist and dotimes...
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 25 Mar 2001 04:11:43 GMT
Newsgroups: comp.lang.lisp
Message-ID: <99jr5v$3l3ci$1@fido.engr.sgi.com>
Kent M Pitman  <pitman@world.std.com> wrote:
+---------------
| Since we've been discussing style, I want to take this opportunity to
| risk controversy by suggesting that I personally have adopted a style
| rule that any use of the third (result) argument in the DOLIST and
| DOTIMES iteration spec is bad style.
...
| Useful as it is, and I admit it is, I think the result form is in a 
| syntactically terrible place that makes it easy to overlook or to get 
| confused with the iteration quantity.
+---------------

I agree, for additional reasons: When one uses a variable name as the
result, one then has the problem that [unlike DO/DO*], DOLIST & DOTIMES
provide no way to bind that variable to an initial value, which means
that one must wrap the iteration in some outer binding form [unless
it's a global, ugh!!]. Given that, why not just return the variable
in the outer form?

	(let ((result '()))
	  (dolist (num nums)
	    (when (oddp num)
	      (push (+ num 1) result)))
	  result)

More verbose, yes, but to me the intention is clearer than (say):

	(let (result)
	  (dolist (num nums result)
	    (when (oddp num)
	      (push (+ num 1) result))))


-Rob

-----
Rob Warnock, 31-2-510		rpw3@sgi.com
SGI Network Engineering		<URL:http://reality.sgi.com/rpw3/>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA