Can you declare the type of a symbol-macro? Here is an example:
(defun foo ()
(symbol-macrolet ((x (+ y 1)))
(declare (type integer x))
(let ((y 3))
(* x y))))
(compile 'foo)
(foo)
=> 12
This doesn't make a lot of sense to me, but I happened to notice that
one of my macros generated code like this, and Allegro compiled it
without complaint. Should I work hard to make sure my macro doesn't do
this any more, in order to avoid problems when porting to other Lisp
dialects?
-- Drew McDermott
Drew McDermott wrote:
> Can you declare the type of a symbol-macro?
I don't think so. Declarations are described (section 3.3.4) as applying to bindings
of variables or functions, and symbol macros are not variables:
3.1.2.1.1: "If a form is a symbol, then it is either a symbol macro or a variable."
Paul
Drew McDermott <··················@at.yale.dot.edu> wrote in message news:<············@news.wss.yale.edu>...
> Can you declare the type of a symbol-macro? Here is an example:
>
> (defun foo ()
> (symbol-macrolet ((x (+ y 1)))
> (declare (type integer x))
> (let ((y 3))
> (* x y))))
Yes, you can. CLHS, description of TYPE declaration:
CLHS> A type declaration of a symbol defined by symbol-macrolet is
CLHS> equivalent to wrapping a the expression around the expansion of that
CLHS> symbol, although the symbol's macro expansion is not actually
CLHS> affected.
--
Regards,
Alexey Dejneka
Alexey Dejneka wrote:
> CLHS> A type declaration of a symbol defined by symbol-macrolet is
> CLHS> equivalent to wrapping a the expression around the expansion of that
> CLHS> symbol, although the symbol's macro expansion is not actually
> CLHS> affected.
Wow. I did not see that.
Paul
"Paul F. Dietz" <·····@dls.net> writes:
> Alexey Dejneka wrote:
>
> > CLHS> A type declaration of a symbol defined by symbol-macrolet is
> > CLHS> equivalent to wrapping a the expression around the expansion of that
> > CLHS> symbol, although the symbol's macro expansion is not actually
> > CLHS> affected.
>
> Wow. I did not see that.
Note, of course, that it's allowable for an implementation to ignore THE,
so an implementation is not required to take any special action--it just
has to not grump at you for having tried.
Drew McDermott <··················@at.yale.dot.edu> writes:
>
> Can you declare the type of a symbol-macro? Here is an example:
>
> (defun foo ()
> (symbol-macrolet ((x (+ y 1)))
> (declare (type integer x))
> (let ((y 3))
> (* x y))))
...
> This doesn't make a lot of sense to me, but I happened to notice that
> one of my macros generated code like this, and Allegro compiled it
> without complaint. Should I work hard to make sure my macro doesn't do
> this any more, in order to avoid problems when porting to other Lisp
> dialects?
>
> -- Drew McDermott
While not definitive, Steele's CLTL2 (p. 216) has this to say about declarations
inside symbol-macrolet:
There are certain aspects peculiar to [declarations inside]
SYMBOL-MACROLET ... An error is signaled if a name defined by
SYMBOL-MACROLET is declared special, and a type declaration of a name
defined by symbol macrolet is equivalent in effect to wrapping a THE
form mentioning the type around the expansion of the defined symbol.
That certain sanctions the use of type declarations for the symbols
introduced by the macrolet. It also points up the alternative if you
are feeling nervous about relying on this:
(symbol-macrolet ((x (the integer (+ y 1))))
(let ((y 3))
(* x y)))
--
Thomas A. Russ, USC/Information Sciences Institute