Path: utzoo!attcan!uunet!seismo!esosun!kobryn
From: kobryn@esosun.UUCP (Cris Kobryn)
Newsgroups: comp.lang.lisp
Subject: Re: DOLIST as DO
Message-ID: <231@balder.esosun.UUCP>
Date: 17 Jul 88 20:09:04 GMT
References: <327@soi.UUCP> <228@esosun.UUCP> <169@quintus.UUCP>
Organization: SAIC, San Diego
Lines: 50
In-reply-to: ok@quintus.uucp's message of 15 Jul 88 22:08:39 GMT

In article <169@quintus.UUCP> ok@quintus.uucp (Richard A. O'Keefe) writes:
>In article <228@esosun.UUCP> jackson@esosun.UUCP (Jerry Jackson) writes:
>>In article <327@soi.UUCP> alex@soi.UUCP (Alex Zatsman) writes:
>>   Anybody knows an elegant way of representing DOLIST construct
>>   through DO ?  How about DO* ?
>>How about...
>>
>>(defmacro dolist ((var list &optional result-form) &rest body)
>>  (let ((listvar (gensym)))
>>    `(do* ((,listvar ,list (cdr ,listvar))
>>	  (,var (car ,list) (car ,listvar)))
>>	 ((null ,listvar) ,result-form)
>>	 ,@body)))
>
>That's not going to work too well when the list happens to be empty,
>is it?  A small change fixes that:
>
>(defmacro dolist ((var list &optional result-form) &rest body)
>    (let ((listvar (gensym)))
>       `(do ((,listvar ,list (cdr ,listvar)))
>	    ((null ,listvar) ,result-form)
>	    (let ((,var (car ,listvar)))
>		,@body))))

Mr. Jackson's version works well in Allegro CL when the LIST arg is NIL.  
Consider the following  Allegro CL dribble-file, in which Mr. Jackson's 
DOLIST has been renamed DOLIST2 to distinguish it from the Allegro version:

	dribbling to file "/u3/kobryn/temp/dolist2.dribble"
 
	NIL 
	 (dolist (i nil) (print i))

	NIL 
	 (dolist2 (i nil) (print i))
	
	NIL 
	 (dribble)

Perhaps you are unaware that according to CLtL (p. 262) (CAR NIL) => NIL?

-- Cris Kobryn

+----------------------------------------------------------------------------+
|   Cris Kobryn                         UUCP:  seismo!esosun!kobryn          |
|   Geophysics Division, MS/12          ARPA:  esosun!kobryn@seismo.css.gov  |
|   SAIC                                SOUND: (619)458-2697                 |
|   10210 Campus Point Drive                                                 |
|   San Diego, CA  92121                                                     |
+----------------------------------------------------------------------------+