Deutsch   English   Français   Italiano  
<v630ta$23smc$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <No_spamming@noWhere_7073.org>
Newsgroups: comp.lang.lisp
Subject: re: DOLIST as DO
Date: Wed, 3 Jul 2024 08:08:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <v630ta$23smc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Wed, 03 Jul 2024 10:08:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="09575532b4412fb0bf784ec91fca00be";
	logging-data="2224844"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18fg2OcT/WB5aCSvVb9oO4A"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:4NB3H7CLmNBGeIiWyULrTIYm/8U=
Bytes: 1869

Barry Margolin wrote:

> In article <2...@esosun.UUCP> jack...@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.

Scheme

(define-syntax dolist
  (syntax-rules ()
    [(dolist (var list result-form ...) expr ...)
     (do ((listvar list (cdr listvar))
          (var #f))
       ((null? listvar) result-form ...)
       (set! var (car listvar))
       expr ...)]))