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

LET-CONSTANT [or "Anonymous Constants"]



A compiler can figure out that a local variable isn't being setq'd, and 
hence can propogate through the binding as a constant literal *providing*
that it can determine that the form it is being bound to is a constant.

Admittedly, that seems to be the thrust of the messages so far -- does
common lisp need a local constant declaration for variables -- and I 
think the answer is, as you phrase it, "no, because any information that 
such a declaration provides can equally well be discerned mechanically
by the compiler."  

But I see the need for a local constant declaration for random expressions 
apart from the issue of properties of program variables.  "Anonymous
Constants", if you will.  Consider for example Interlisp's [special-form] 
function CONSTANT:

   (let ((x (constant `(JonL-phone-no ,(call-up-bell-tel-co)))))
     (check-phone-book x) 
     (broadcast-to-friends x (constant (figger-out-broadcast-routing)))
     x)

Without the very-local "declaration" provided by 'constant', the compiler
would be obliged NOT to propogate the binding value of x, and not to
elide the runtim calls to 'call-up-bell-tel-co', 'list', and the totally
random 'figger-out-broadcast-routing'.  [And also not to create the list in
a static, or read-only area, etc.]

Using 'constant' rather than #. is more of an issue in Interlisp style 
-- the "residential" style as opposed to the EMACS style -- but I don't
think it should be ignored in CL.  In fact, a later addition to Interlisp 
was 'loadtimeconstant', which is a functionality that has been under active 
discussion on this mailing list in recent weeks.

-- JonL --