From: Joerg Hoehle
Subject: Re: constants in functions
Date: 
Message-ID: <6eurik$dm0@omega.gmd.de>
Sam Steingold (···@usa.net) wrote:
: (defun note-add (obj new)
:   (setf (slot-value 'note obj)
: 	(concatenate 'string (slot-value 'note obj) (string #\newline) new)))

: I don't want each call to note-add to re-compute (string #\newline).
: Is there a way to avoid this? (Of course, a good compiler should do that
: for me, but it dosn't look like CLISP does it).
: Will macro be considered to be a clean solution?
Please define clean :-)

The cleanest (least visual clutter) way would be to rely on the
compiler to do constant folding.  Visually cluttered is the solution
with a DEFUN inside a LET, and some systems also give you lesser
information by DESCRIBE on closures than top-level functions.

Two other solutions come to mind, although I don't like any of them.

1. Use #.xyz.  The problem here is that the compiler may not be able
to write a readable form of the object xyz produces into its binary
file, but that's more a general problem not pertaining to your case.

2. Use LOAD-TIME-VALUE.  However this defeats type inference done by
the compiler (at least for CMUCL, CLISP does nothing like that).  You
could add (THE ...) but the compiler may then choose to add a run-time
test against the type (probably depending on your SAFETY setting)
every time the function is called, a load-time test would have sufficed.

Better solutions appreciated,
	Jo"rg Ho"hle.
············@gmd.de		http://zeus.gmd.de/~hoehle/amiga.html