Re: How to use constants in a case key form ?



On Nov 23, 9:41 pm, Zach Beane <x...@xxxxxxxx> wrote:
Geoff Wozniak <geoff.wozn...@xxxxxxxxx> writes:
This assumes that the constants are available when the case form is
read. It also assumes you recompile the forms that depend on the
constants if you change the constants.

This is important to remember. I use the #.+FOO+ form all the time,
but CLISP needs an EVAL-WHEN around the defconstant form to ensure the
value is visible at compile-time.

This sounds wrong to me. The form prefixed by #. is evaluated at read
time, not compile time. If the constant's value should be known at
read time, the defconstant form must have been evaluated at read time
- and there is no eval-when clause for that.

I think the following is an appropriate way to define a constant and
use its value as case clause value, both in the same file:

(progn #.(progn #1=(defconstant +foo+ 1) nil) ;; declare constant at
read time; nil as harmless result
#1#) ;; also have the normal effect of defconstant

(defun f (x)
(case x
(#.+foo+ 42)))


- Willem
.