Disclaimer I do not know if this is really the answer to the question. Comments and changes are welcome.
Open problem
As Dirk said in a comment, in Common Lisp, the Language says that (section on declare form ( link )):
There are certain aspects specific to symbol-macrolet . [..] type declaration of a certain name by symbol-macrolet equivalent to an effect for wrapping the form in which it is indicated that the type around is an extension of a certain symbol.
As far as I can tell, the problem is somewhat controversial, for example. This is an open question . Mandatory or not? Read here:
SYMBOL-MACROLET-TYPE-DECLARATION Recording Problem
[..] should (or can) return the value MACROEXPAND or MACROEXPAND-1 includes the form if there are type declarations that apply to the macro character extension?
There are four sentences: YES , NO , MAYBE and PROBABLY . Read about them in the article that was given above. Each of the four sentences has a rationale.
SBCL does this. I think this is the choice of developers.
Why? Well, the rationale for YES gives cause.
There are some advantages (?)
For example, code optimization may be somewhat βeasierβ for the compiler. Check this.
No ads, no the in the extension:
Take this:
(SB-CLTL2:MACROEXPAND-ALL '(LAMBDA (AB) (+ AB (SYMBOL-MACROLET ((A 1) (B 2)) (+ AB)))))
the result is simple:
(LAMBDA (AB) (+ AB (SYMBOL-MACROLET ((A 1) (B 2)) (+ 1 2))))
if you put the latter in the file you want to optimize, say something like this:
(declaim (optimize (speed 3) (debug 0) (safety 0)))
and you compile it, SBCL will give you a bunch of warnings like this:
; note: forced to do GENERIC-+ (cost 10) ; unable to do inline fixnum arithmetic (cost 1) because: ; The first argument is a NUMBER, not a FIXNUM. ; The result is a (VALUES NUMBER &OPTIONAL), not a (VALUES FIXNUM &REST T). ; unable to do inline fixnum arithmetic (cost 2) because: ; The first argument is a NUMBER, not a FIXNUM. ; The result is a (VALUES NUMBER &OPTIONAL), not a (VALUES FIXNUM &REST T). ; etc.
With an SBCL declaration, put the in the extension:
Now try the following:
(SB-CLTL2:MACROEXPAND-ALL '(LAMBDA (AB) (DECLARE ((SIGNED-BYTE 4) A)) (declare ((signed-byte 4) B)) (+ AB (SYMBOL-MACROLET ((A 1) (B 2)) (+ AB)))))
this decomposition:
(LAMBDA (AB) (DECLARE ((SIGNED-BYTE 4) A)) (DECLARE ((SIGNED-BYTE 4) B)) (+ AB (SYMBOL-MACROLET ((A 1) (B 2)) (+ (THE (SIGNED-BYTE 4) 1) (THE (SIGNED-BYTE 4) 2)))))
Put the latter in the file, place the declaration for optimization, compile. Guess what? No. SBCL no longer complains that it will not be able to perform some stiffness optimization for your code. He can do it. Due to part (THE (SIGNED-BYTE 4) 1) .
Read more about the special form
So, maybe this is a way to ensure that your type declaration will affect the variables in the form of a macro, also check the type checking and make it possible for the compiler to optimize the code?