From: Florian Weimer
Subject: Saving values at compile time
Date: 
Message-ID: <87isvlooto.fsf@deneb.enyo.de>
I've finally decided to learn some real Lisp and stumbled across a few
issues which I couldn't resolve by browsing a few manuals.

I want to do some extensive computation (say, populate a hash table
from an external file) during compilation and store the result in a
constant which can be used at run time.  Basically, I need the
following:

(defconstant foo <insert value here>)

Currently, I define a macro which generates the appropriate
defconstant form, but this looks a bit ugly for my taste.  Is there
some kind of idiom for this task which I could use, or even a language
feature?
From: Steven M. Haflich
Subject: Re: Saving values at compile time
Date: 
Message-ID: <3E4E517B.80407@alum.mit.edu>
Florian Weimer wrote:

> Currently, I define a macro which generates the appropriate
> defconstant form, but this looks a bit ugly for my taste.

This is indeed the correct and idiomatic way to accomplish this.
Compilation semantics guarantee that macros are executed at
compile time, so that is the way to get computation performed
at compile time.  The only other way is to use a top-level
eval-when, storing the result somewhere, and inserting it into
code using reader macrology such as #. .  Ugly in every way.

On the ugliness of "defining a macro" you might consider using
a macrolet instead of a global macro, assuming the macro really
is only needed once.  E.g.:

(defconstant *digit-alist*
     (macrolet ((dig ()
		 `',(loop for i below 10
			collect (cons i
				      (format nil "~r" i)))))
       (dig)))

The macrolet has no effect on the global namespace.