[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dolist



   From: pg@das.harvard.edu

   I agree in that this code
   
   (let ((x 1))
     (let ((f #'(lambda () x)))
       (setq x 2)
       (funcall f)))
   
   should return 2.  The question is, should dolist be understood as
   creating one variable (as it would if it expanded into a tagbody
   with a setq) or a different variable on each iteration (as it would
   if it expanded into a recursive function).  I believe that the
   standard is vague here...

If by "the standard" you meand the ANSI Standard for CL, then it is
not at all vague.  The dictionary entry for DOLIST in Chapter 6 says:

 It is implementation-dependent whether DOLIST establishes a new
 binding of VAR on each iteration or whether it establishes a binding
 for VAR once at the beginning and then assigns it on any subsequent
 iterations.

This is hardly vague.  Rather, portable code is prohibited from
depending on this detail of behavior.  Implementations may vary, and
even a single implementation is allowed to handle it in different ways
in differeent circumstances.