re: DOLIST as DO

Liste des GroupesRevenir à cl lisp 
Sujet : re: DOLIST as DO
De : No_spamming (at) *nospam* noWhere_7073.org (B. Pym)
Groupes : comp.lang.lisp
Date : 03. Jul 2024, 10:08:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v630ta$23smc$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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 ...)]))

Date Sujet#  Auteur
3 Jul 24 o Re: DOLIST as DO1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal