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

Re: Flush COMPILER-LET?



I think the intended use is slightly different from the example you gave.
Here's what I think of as a prototypical example...

 (DEFVAR *LOCAL-TYPE-DECLARATIONS* '())
 
 (DEFMACRO LOCAL-TYPE-DECLARE (DECLARATIONS &BODY FORMS)
   `(COMPILER-LET ((*LOCAL-TYPE-DECLARATIONS* 
		     (APPEND ',DECLARATIONS *LOCAL-TYPE-DECLARATIONS*)))
      ,@FORMS))
 
 (DEFMACRO TYPED-VAR (VAR)
   (LET ((TYPE (ASSOC VAR *LOCAL-TYPE-DECLARATIONS*)))
     (IF TYPE `(THE ,(CADR TYPE) ,VAR) VAR)))
 
 (DEFUN F (X Y)
   (LOCAL-TYPE-DECLARE ((X FIXNUM) (Y FLOAT))
     (+ (TYPED-VAR X) (TYPED-VAR Y))))
 
is equivalent to

 (DEFUN F (X Y) (+ (THE FIXNUM X) (THE FIXNUM Y)))

You can do the same thing with MACROLET, but it feels quite awkward.

 (DEFMACRO LOCAL-TYPE-DECLARATIONS () '())
 
 (DEFMACRO LOCAL-TYPE-DECLARE (DECLARATIONS &BODY FORMS &ENVIRONMENT ENV)
   `(MACROLET ((LOCAL-TYPE-DECLARATIONS ()
		 ',(APPEND DECLARATIONS 
			   (MACROEXPAND '(LOCAL-TYPE-DECLARATIONS) ENV))))
      ,@FORMS))
 
 (DEFMACRO TYPED-VAR (VAR &ENVIRONMENT ENV)
   (LET ((TYPE (ASSOC VAR (MACROEXPAND '(LOCAL-TYPE-DECLARATIONS) ENV))))
     (IF TYPE `(THE ,(CADR TYPE) ,VAR) VAR)))
 
 (DEFUN F (X Y)
   (LOCAL-TYPE-DECLARE ((X FIXNUM) (Y FLOAT))
     (+ (TYPED-VAR X) (TYPED-VAR Y))))
 
In my opinion, the only thing that makes COMPILER-LET feel bad is the
stubborn refusal for interpreted-only implementations to do a semantic
prepass. This is what forces you to do a special-bind at runtime. If
COMPILER-LET did a special-bind only at conceptual compile time (i.e.,
semantic pre-pass for interpreted code), it would not seem nearly so
nasty because it wouldn't interfere unpredictably with runtime bindings.