Subject: Re: That result arg to dolist and dotimes...
From: (Rob Warnock)
Date: 25 Mar 2001 04:11:43 GMT
Newsgroups: comp.lang.lisp
Message-ID: <99jr5v$3l3ci$>
Kent M Pitman  <> 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)))

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 Warnock, 31-2-510
SGI Network Engineering		<URL:>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA