Subject: Re: Q: example usage of EVAL-WHEN
From: Erik Naggum <>
Date: 30 Oct 2000 10:45:37 +0000
Newsgroups: comp.lang.lisp
Message-ID: <>

* (Xenophon Fenderson the Carbon(d)ated)
| I have text parsing code that looks something like the following:
|   (defparameter *the-default-macro-table* (make-hash-table))
|   ;; here is some code to initialize *the-default-macro-table*
|   (setf (gethash #\a *the-default-macro-table*) #'process-\a)
|   (setf (gethash #\b *the-default-macro-table*) #'process-\b)

  If these pieces of code are always executed together, it would
  perhaps look better if you did something like this:

(defparameter *the-default-macro-table*
    (let ((hash-table (make-hash-table)))
      (setf (gethash #\b hash-table) #'process-\b)
      (setf (gethash #\b hash-table) #'process-\b)

| I would like the hash table (along with its initial entries) to be
| re-created each time the file is loaded.

  This is what defparameter does.

| Do I have to use EVAL-WHEN to get the behavior I want?


| When should I use EVAL-WHEN?
| When shouldn't I use EVAL-WHEN?

  These are almost impossibly broad questions.

  You should use eval-when when evaluation is to occur at other times
  than the defaults.  You should not use eval-when when the default is
  sufficient or if you don't understand when to use eval-when...

  Does anyone remember where I parked Air Force One?
                                   -- George W. Bush