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

Re: DECLARE SPECIAL Considered Confusing



	
    Date: Sun, 20 Jul 86 17:11:53 EDT
    From: Alan Bawden <ALAN@AI.AI.MIT.EDU>
    To: Common-Lisp@SU-AI.ARPA
    Subject:  DECLARE SPECIAL Considered Confusing
    In-Reply-To: Msg of 19 Jul 1986 17:17-EDT from NGALL at G.BBN.COM
    Message-ID: <[AI.AI.MIT.EDU].73028.860720.ALAN>
    
    Nobody has yet pointed out that changing the rules for (DECLARE (SPECIAL
    ...)) to follow the scoping of the variables involved does make it harder
    for people to write certain macros that bind variables.  For example,
    consider trying to write LET*; you have to grovel through the declarations
    in the body in order to distribute the SPECIAL declarations properly.
    
    The old rule (which I have always found appalling -- I'm not trying to
    defend it) did have the advantage that you can always extract the
    declarations from the body of a macro form and just wrap the entire
    expansion in a LOCALLY.
    
I don't think the old rule did make
(LET* (...) (declare ...) ...) equivalent to
(locally (declare ...) {some expansion for LET*})

For example,
(let* ((x 1) (y (1+ x))) (declare (special x)) ...)
is not equivalent to
(locally (declare (special x))
  (let ((x 1))
    (let ((y (1+ x)))
      ...)
Since the declaration only affects the reference to x in (1+ x); the
outer LET incorrectly binds the lexical variable x.

The use of LOCALLY as you suggest, only works for pervasive
declarations, and the only purely pervasive declaration in CLtL is
OPTIMIZE.

As I said in my previous letter, I don't think FTYPE or INLINE are
purely pervasive.  E.g.,

(flet ((foo (...) ...(foo...)...))
  (declare (ftype (function...) foo))
  (foo...)
  ...)
is not equivalent to
(locally (declare (ftype (function...) foo))
  (flet ((foo (...) ...(foo...)...))
    (foo...)
    ...))
since the declaration in the first form would affect only the second
call to foo and the decl. in the second form would affect only the
first call to foo.

    If we really intend to open this whole can of worms, it might also be a
    good idea for someone to remind us all of the arguments for the concept of
    "pervasive declarations".
    
	      --------------------
		
I think the can is already open in the case of FTYPE and INLINE, since
CLtL is certainly muddled about whether they are simply pervasive
declarations or declarations that concern bindings and only the
references within the scope of the those bindings.

-- Nick