Re: Macros, declare, and locally

From: Kent M Pitman (pitman_at_nhplace.com)
Date: 03/10/05


Date: Thu, 10 Mar 2005 22:39:22 GMT

Kalle Olavi Niemitalo <kon@iki.fi> writes:

> Damien Kick <dkick1@email.mot.com> writes:
>
> > But if one can write a macro which expands into a LOCALLY form, does
> > this not mean that one must continue to call MACROEXPAND to find the
> > end of the declarations?
>
> No, it doesn't. A LOCALLY form terminates the list of local
> declarations, just like any other form would

True, but not the key issue.

 (defun foo (x)
   (declare (special x))
   x) ; <-- this x is special

 (defun foo (x)
   (locally (declare (special x)))
   x) <-- this x is NOT special

The scope of a locally is only its body. That is,

 (LOCALLY (DECLARE (SPECIAL X))
    ... this part is where X is special ...)

so

 (defun foo (x)
   (locally (declare (special x))
     ;; There's nothing in this LOCALLY body
   ) ;; <-- this closes the body of LOCALLY
   ;; This isn't in the LOCALLY body, which is now closed.
   x)

So you're right that LOCALLY stops the list of declarations at the
top of FOO, but the reason is that it's an exectuable form. Indeed,
in many implementations:

 (LOCALLY decls . forms)

expands into

 (LET () decls . forms)



Relevant Pages

  • One way CL doesnt suck (was Re: How Common Lisp sucks)
    ... CL-USER> (defun foo (x y) ... (declare (fixnum x y)) ... result of down to fixnum bits. ... Well, no, but that's because here your LOGAND doesn't do what I think ...
    (comp.lang.lisp)
  • Re: How Common Lisp sucks
    ... CL-USER> (defun foo (x y) ... (declare (fixnum x y)) ... CL-USER> ... result of down to fixnum bits. ...
    (comp.lang.lisp)
  • Re: One way CL doesnt suck
    ... (defun foo (x y z) ... (declare (optimize speed) ... (type ((unsigned-byte 32) ... summing (ash temp (random 32))))) ...
    (comp.lang.lisp)
  • Re: One way CL doesnt suck
    ... (defun foo (x y z) ... (declare (optimize speed) ... (type ((unsigned-byte 32) ... for temp = ...
    (comp.lang.lisp)
  • Re: Macros, declare, and locally
    ... (defun x () ... (locally (declare (optimize safety))) ... If you splice in the body of the LOCALLY form: ... Because cannot expand to a declaration, ...
    (comp.lang.lisp)