Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!news.cis.ohio-state.edu!math.ohio-state.edu!uwm.edu!spool.mu.edu!usenet.eel.ufl.edu!news.mathworks.com!enews.sgi.com!EU.net!usenet2.news.uk.psi.net!uknet!usenet1.news.uk.psi.net!uknet!uknet!newsfeed.ed.ac.uk!edcogsci!jeff
From: jeff@cogsci.ed.ac.uk (Jeff Dalton)
Subject: Re: Undeclared specials [was EVAL Implementations]
X-Nntp-Posting-Host: pitcairn
Message-ID: <DwuwC6.6BM@cogsci.ed.ac.uk>
Sender: cnews@cogsci.ed.ac.uk (C News Software)
Organization: HCRC, University of Edinburgh
References: <3049754333170201@arcana.naggum.no> <DwrDLA.26q@cogsci.ed.ac.uk> <32231138.31DFF4F5@elwoodcorp.com>
Date: Wed, 28 Aug 1996 16:26:29 GMT
Lines: 116

In article <32231138.31DFF4F5@elwoodcorp.com> "Howard R. Stearns" <howard@elwoodcorp.com> writes:
>I have included, below, Jeff's excellent listing of ANSI statements
>regarding variables which are neither declared special nor have a clear
>lexical binding.  I wish to:
> 1. Sumarize my understanding of the position.
> 2. Add one other reference, for the record, and ask a question about
>one of Jeff's references.
> 3. Raise two issues which all this still leaves me confused about.
>
>1. Summary:
>
>  It is an error for a variable which does not have a lexical binding to 
>  not be explicitly declared special in some way (such as a declamation 
>  or local declaration). 

No way.  I've seen nothing that says or implies that it is an error,
and it's odd that you regard this paragraph of yours as a summary.  It
certainly doesn't reflect the discussion *I've* seen.

> "It is an error" has the usual meaning that 
>  the behavior is not defined.

But people have been using that the other way around, as if "not
explicitly defined anywhere" meant "is an error".

>  In this particular case, this means 
>  that implementations may or may not signal warnings or errors at 
>  either compile or run time.

I have seen no justification for signalling an error.  I'm not sure in
what cases warnings are permitted, but in practice they certainly
include cases that are allowed in conforming code and that are not
"an error".

>  No conforming program can rely on 
>  undeclared variables being special.

Why not?  For instance, this should work:

1.  (setf (symbol-value 'x) 100) => 100
2.  (locally (declare (special x)) x) => 100

It's arguable that x has been declared special in line 2,
but it certainly hasn't been in line 1, and I've never seen
even a warning (not even in CMUCL) for such things as line 1.
Yet it's clear from the HyperSpec and CLtL that symbol-value
reads and writes the value of the dynamic (ie, special) variable.
So x must have been special before any declaration or proclamation
had occurred.  (And line 2 is relying on this.)

>It is acknowledged that this makes it difficult to use free variables in
>the interpreter.

It is?  By?

>  Because of this, all current implementations happen to
>treat undeclared free variables as special, at least in the interpreter.

Can you tell me one that doesn't do this in the compiler?  At most,
there's a warning when the code is compiled (so far as I've seen).

>At least one major implementation, CMUCL, make a global special
>declamation for all free variables, whether compiled or interpreted.

Humm.  It shouldn't do that.

>2. References:
>
>Section 3.2.2.3 Semantic Constraints, says:
>
>  All conforming programs must obey the following constraints, which are
>designed to minimize the observable differences between compiled and   
>  interpreted programs: 
>  ...
>  Special proclamations for dynamic variables must be made in the   
>  compilation environment. Any binding for which there is no special  
>  declaration or proclamation in the compilation environment is treated 
>  by the compiler as a lexical binding. 
>
>At first glance, one might think this contradicts the above, but I
>interpret this is specifying that the compiler must assume the variable
>is lexical and look for a lexical binding.  It is then, presumably, "an
>error", when a compiler tries to look up a lexical binding and doesn't
>find one.

Note that it says "any _binding_" (emphasis added) and not "any
reference".  So if the compiler sees

  (let ((x 1))
    ...)

and there's no special declaration/proclamation in the compilation
env, the x is bound as a lexical variable.

>Question:  Jeff quoted an X3J13 issue called "PROCLAIM LEXICAL", noting
>that the wording of the issue was changed over time.  I cannot find an
>issue with this name in Kent's excellent HyperSpec.  Is it there?  Can
>someone give me a pointer to it?

It wasn't passed, hence isn't in the HyperSpec.  But that doesn't
invalidate its description of the problem and the proposals.

>3. Outstanding issues:
>
> I. Once a variable has been declaimed special, how does one make it
>unspecial?   (Do I need to clarify why I think this is important?)

There's no standard way to do so.

> II. Consider the following:
>   (let ((x 1)) (compile 'foo '(lambda () x)))

Let's please not get into a discussion of COMPILE.  It will complicate
everything for little gain.

-- jd
