From: Jeff M.
Subject: LOOP question
Date: 
Message-ID: <21738146-4d39-41da-8041-ff069a0d01de@17g2000hsk.googlegroups.com>
I don't know if the implementation of LOOP is standard across
implementations, and I'm wondering about possible dynamic scoping
issues across implementations. Given the following example:

(defparameter *foo* nil)

(defun print-foo ()
  (print *foo*))

(defun test ()
  (loop for *foo* from 1 to 10 do (print-foo)))

In LispWorks this does exactly what I'd expect: print 1 .. 10. But is
this guaranteed to be the case across all implementations? I'd imagine
so, but would just like to make sure. ;-)

Thanks!

Jeff M.

From: Chris Barts
Subject: Re: LOOP question
Date: 
Message-ID: <87bpxrk8ax.fsf@chbarts.motzarella.org>
"Jeff M." <·······@gmail.com> writes:

> I don't know if the implementation of LOOP is standard across
> implementations, 

Yes, LOOP is part of the ANSI standard. If you are ever unsure about
what is or is not standard, look in the Common Lisp HyperSpec (CLHS)
available online here:
<http://www.lispworks.com/documentation/HyperSpec/Front/index.htm>

It technically isn't the standard but it is more than close enough for
most people to write conformant code.

> and I'm wondering about possible dynamic scoping
> issues across implementations. Given the following example:

From <http://www.lispworks.com/documentation/HyperSpec/Body/06_aba.htm>:

<< A variable binding has lexical scope unless it is proclaimed
   special; thus, by default, the variable can be accessed only by
   forms that lie textually within the loop.
>>

Since you used DEFPARAMETER as a top-level form, *FOO* is indeed
special. From
<http://www.lispworks.com/documentation/HyperSpec/Body/m_defpar.htm#defparameter>:

<< If a defvar or defparameter form appears as a top level form, the
   compiler must recognize that the name has been proclaimed special.
>>

>
> (defparameter *foo* nil)
>
> (defun print-foo ()
>   (print *foo*))
>
> (defun test ()
>   (loop for *foo* from 1 to 10 do (print-foo)))
>
> In LispWorks this does exactly what I'd expect: print 1 .. 10. But is
> this guaranteed to be the case across all implementations? I'd imagine
> so, but would just like to make sure. ;-)

Yes, that appears to be what should happen from a plain reading of the
CLHS. I'm not a language lawyer, however. ;)
From: Kenny
Subject: Re: LOOP question
Date: 
Message-ID: <48f0399b$0$4976$607ed4bc@cv.net>
Jeff M. wrote:
> I don't know if the implementation of LOOP is standard across
> implementations, and I'm wondering about possible dynamic scoping
> issues across implementations. Given the following example:
> 
> (defparameter *foo* nil)
> 
> (defun print-foo ()
>   (print *foo*))
> 
> (defun test ()
>   (loop for *foo* from 1 to 10 do (print-foo)))
> 
> In LispWorks this does exactly what I'd expect: print 1 .. 10. But is
> this guaranteed to be the case across all implementations? I'd imagine
> so, but would just like to make sure. ;-)

6.1.2.1 Iteration Control offers: "A variable binding has lexical scope 
unless it is proclaimed special;..."

Relevant?

hth,kzo