Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

A vivid and creative mind characterizes you.


comp / comp.lang.lisp / re: DOLIST as DO

SubjectAuthor
o re: DOLIST as DOB. Pym

1
Subject: re: DOLIST as DO
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 3 Jul 2024 08:08 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
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=
View all headers

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 ...)]))

1

rocksolid light 0.9.8
clearnet tor