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

Re: Declare Special



	
    Date:     Mon, 21 Jul 86 10:33 EST
    From:     ELIOT%cs.umass.edu@CSNET-RELAY.ARPA
    To:       Common-Lisp@SU-AI.ARPA
    Subject:  Declare Special
    
    I think the basic idea of putting the declaration inside the form it
    is trying to affect is inherently un-lispish and will always be
    confusing.  I think that we should define a set of special forms
    that syntactically enclose the body they apply to and supply the
    needed functionality.  Maybe in CL-2000 these can be made the standard.

The best place to put a decl is adjacent to the entity it refers to (a
la Ada).  I don't know of any language that puts declarations for
function parameters BEFORE the parameters (do you); those that don't
put them adjacent to the parameters (e.g., C) put them 'inside the
body'.  I think that is a pretty good reason for CL to do the same.
    
    Locally is a good start.  I have a question about its semantics, though.
    Consider:
	    (locally (declare (special foo))
	       (let ((foo <something>))
		    (print foo)))
    I cannot figure out what this does from CLtL.  Probably the binding is
    not affected by locally, (even though the declaration is pervasive)
    so in fact the binding *cannot* be referenced.  The reference to foo
    is (presumably) affected by a pervasive declaration, so this code
    fragment does something unpredictable.
You figured it out.  A good compiler will warn you that the lexical
variable foo is never referenced.  The fragment's behavior is quite
predicatable: it will print the value of the special variable foo.
    
    I think two additional special forms would be helpful.  One would be
    exactly like locally, except that it would pervasively affect bindings
    as well as references to variables.  In other words, this would be
    a lexically scoped version of proclaim.  (Perhaps call it proclaim-locally).
Could you give some examples of how proclaim-locally would be helpful?
It sounds relatively useless to me.
    
    The last special form needed would supply the standard lexically
    scoped declarations.  Hopefully this is not too confusing.
    The syntax would again be identical to locally, but the scope would
    be everything through the scope of the next enclosing binding.
    (For variable declarations of course.)  For example:
	    (lexical-locally (declare (special x))
	      ;; x special here.
	      (let ((x 3))	;binds x specially.
		;; x special here (and = 3)
		(let ((x 4))	;Binds x lexically.
		   ....)))
All I can say is that I prefer my decls as close to their entities as
possible, and you are suggesting a syntax that would allow them to be
moved arbitrarily far away, and to affect unrelated references, i.e.,
what has the x outside the outer LET got to do with the x bound in the
outer LET?  Why should they share a decl?
    
    People probably wouldn't want to use these at top-level, so there is
    still a need for something like Pavel's suggestion.  Elsewhere these
    forms would usually be clearer.
Having two different declaration styles is bound to be more confusing
than one.

-- Nick