From: Wolfhard Buß
Subject: dolist
Date: 
Message-ID: <m31y23f8dg.fsf@buss-14250.user.cis.dfn.de>
What is the value of

 (flet ((foo ()
          (declare (special *i*))
          (if (boundp '*i*) *i* 42)))
   (dolist (*i* '() (foo))
     (declare (special *i*))))

according to our fine Standard.

-- 
"Hurry if you still want to see something. Everything is vanishing."
                                       --  Paul C�zanne (1839-1906)

From: Nils Goesche
Subject: Re: dolist
Date: 
Message-ID: <lyheazdshw.fsf@cartan.de>
·····@gmx.net (Wolfhard Bu�) writes:

> What is the value of
> 
>  (flet ((foo ()
>           (declare (special *i*))
>           (if (boundp '*i*) *i* 42)))
>    (dolist (*i* '() (foo))
>      (declare (special *i*))))
> 
> according to our fine Standard.

The dictionary entry for DOLIST says

# At the time result-form is processed, var is bound to nil. 

So, I'd say this should return NIL.

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Nils Goesche
Subject: Re: dolist
Date: 
Message-ID: <lyd6lnds3n.fsf@cartan.de>
I <······@cartan.de> wrote:

> ·····@gmx.net (Wolfhard Bu�) writes:
> 
> > What is the value of
> > 
> >  (flet ((foo ()
> >           (declare (special *i*))
> >           (if (boundp '*i*) *i* 42)))
> >    (dolist (*i* '() (foo))
> >      (declare (special *i*))))
> > 
> > according to our fine Standard.
> 
> The dictionary entry for DOLIST says
> 
> # At the time result-form is processed, var is bound to nil. 
> 
> So, I'd say this should return NIL.

And if anybody doubts that the SPECIAL declaration has effect even
when the result form is evaluated, he should have a look at the last
paragraph of 3.3.4 Declaration Scope:

# Some iteration forms include step, end-test, or result subforms that
# are also included in the scope of declarations that appear in the
# iteration form.  Specifically, the iteration forms and subforms
# involved are:
#
#     do, do*: step-forms, end-test-form, and result-forms. 
#     dolist, dotimes: result-form 
#     do-all-symbols, do-external-symbols, do-symbols: result-form 

And 3.3.4.1 contains the example

#  (let ((x  1))                     ;[1]
#    (declare (special x))           ;[2]
#      (let ((x 2))                  ;[3]
#        (dotimes (i x x)            ;[4]
#          (declare (special x)))))  ;[5]
# =>  1

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Wolfhard Buß
Subject: Re: dolist
Date: 
Message-ID: <m3wujvdl5q.fsf@buss-14250.user.cis.dfn.de>
Nils Goesche cited CLHS 3.3.4:
> 
> # Some iteration forms include step, end-test, or result subforms that
> # are also included in the scope of declarations that appear in the
> # iteration form.  Specifically, the iteration forms and subforms
> # involved are:
> #
> #     do, do*: step-forms, end-test-form, and result-forms. 
> #     dolist, dotimes: result-form 
> #     do-all-symbols, do-external-symbols, do-symbols: result-form 

Thanks. So the value of

 (flet ((foo ()
	  (declare (special *i*))
	  (if (boundp '*i*) *i* 42)))
   (dolist (*i* '() (foo))
     (declare (special *i*))))

is *not* 42. Remarkable!

-- 
"Hurry if you still want to see something. Everything is vanishing."
                                       --  Paul C�zanne (1839-1906)
From: Steven M. Haflich
Subject: Re: dolist
Date: 
Message-ID: <3E55B250.6010808@alum.mit.edu>
Nils Goesche wrote:

> And if anybody doubts that the SPECIAL declaration has effect even
> when the result form is evaluated, he should have a look at the last
> paragraph of 3.3.4 Declaration Scope: ...

  (flet ((foo ()
           (declare (special *i*))
           (if (boundp '*i*) *i* 42)))
    (dolist (*i* '() (foo))
      (declare (special *i*))))

I agree with your conclusion that *i* is bound as a special to nil
during the execution of the result form (foo), but this has nothing
to do with whether the form (foo) is within the scope of the
special declaration.  If *i* appeared as a variable in that form,
then the declaration would affect the meaning of the variable *i*.
But I see no occurrence of *i* lexically inside the form (foo).
It is important to remember that even a special declaration, like any
other declaration, applies only to the lexical scopu of the declaration.
It is not and cannot be pervasive to code dynamically called from that
extent.
From: Nils Goesche
Subject: Re: dolist
Date: 
Message-ID: <lywujtbtkw.fsf@cartan.de>
"Steven M. Haflich" <·················@alum.mit.edu> writes:

> Nils Goesche wrote:
> 
> > And if anybody doubts that the SPECIAL declaration has effect even
> > when the result form is evaluated, he should have a look at the
> > last paragraph of 3.3.4 Declaration Scope: ...
> 
>   (flet ((foo ()
>            (declare (special *i*))
>            (if (boundp '*i*) *i* 42)))
>     (dolist (*i* '() (foo))
>       (declare (special *i*))))
> 
> I agree with your conclusion that *i* is bound as a special to nil
> during the execution of the result form (foo), but this has nothing
> to do with whether the form (foo) is within the scope of the special
> declaration.

> If *i* appeared as a variable in that form, then the declaration
> would affect the meaning of the variable *i*.  But I see no
> occurrence of *i* lexically inside the form (foo).  It is important
> to remember that even a special declaration, like any other
> declaration, applies only to the lexical scopu of the declaration.
> It is not and cannot be pervasive to code dynamically called from
> that extent.


The reason I think it has to do with (lexical) scope, too, is that the
dictionary entry for DOLIST explicitly 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.

Now, whether this new binding is established in the dynamic
environment would depend on whether the SPECIAL declaration has effect
or not, which depends on... its lexical scope.  From 3.3.4 again:

# The scope of a bound declaration is the same as the lexical scope of
# the binding to which it applies; for special variables, this means
# the scope that the binding would have had had it been a lexical
# binding.

Also, 3.1.2.1.1.2 Dynamic Variables says

# The effect of binding a dynamic variable is to create a new binding
# to which all references to that dynamic variable in any program
# refer for the duration of the evaluation of the form that creates
# the dynamic binding.

So, it is immaterial whether *I* is referenced inside the form (FOO),
but it is nevertheless important that *I* is bound in the dynamic
environment during the evaluation of (FOO).  And whether it is or
isn't is determined by the lexical scope of the SPECIAL declaration.
(I think).

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0