[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Flush COMPILER-LET?
- To: sandra%defun@cs.utah.edu
- Subject: Re: Flush COMPILER-LET?
- From: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM>
- Date: Mon, 26 Sep 88 16:48 EDT
- Cc: jeff%aiai.edinburgh.ac.uk@nss.cs.ucl.ac.uk, cl-compiler@sail.stanford.edu
- In-reply-to: <8809261827.AA05299@defun.utah.edu>
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.