Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: DOLIST as DO Message-ID: <24054@think.UUCP> Date: 17 Jul 88 05:16:17 GMT References: <327@soi.UUCP> <228@esosun.UUCP> Sender: usenet@think.UUCP Reply-To: barmar@kulla.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 21 In article <228@esosun.UUCP> jackson@esosun.UUCP (Jerry Jackson) writes: >(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))) Both versions of your macro have a bug: they have ",list" in two places in the expansion. This will cause the list expression to be evaluated twice, which could cause problems if it has side effects. In the above case, both the second line of the DO* form should be (,var (car ,listvar) (car ,listvar)) Fixing the DO version is slightly more complicated. Barry Margolin Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar