From: Jeff
Subject: Putting evaluated constants in a CASE
Date: 
Message-ID: <Vx9Wc.301360$%_6.223773@attbi_s01>
Is there any way to do this?

(defconstant *X* 10)
(case 10 (*X* t)) ==> NIL

It would be really nice to use CASE with constants of some kind. I
could always fall back on COND or IF's, and that isn't a problem. But
if I'm missing a simple backquote operation or syntax construct, I'd
like to learn it ;)

Jeff

From: ·········@random-state.net
Subject: Re: Putting evaluated constants in a CASE
Date: 
Message-ID: <cgb9dd$6ha1n$1@midnight.cs.hut.fi>
Jeff <···@nospam.insightbb.com> wrote:
> Is there any way to do this?

> (defconstant *X* 10)
> (case 10 (*X* t)) ==> NIL

(case 10 (#.*x* t)) => T

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."
From: Svein Ove Aas
Subject: Re: Putting evaluated constants in a CASE
Date: 
Message-ID: <cgc9vu$rrj$1@services.kq.no>
·········@random-state.net wrote:

> Jeff <···@nospam.insightbb.com> wrote:
>> Is there any way to do this?
> 
>> (defconstant *X* 10)
>> (case 10 (*X* t)) ==> NIL
> 
> (case 10 (#.*x* t)) => T
> 
Well, only if *x* never changes - which I suppose it wouldn't, being a
constant and all. Just so you know, the case statement won't change just
because *x* does.
From: Svein Ove Aas
Subject: Re: Putting evaluated constants in a CASE
Date: 
Message-ID: <cgb9av$9uk$1@services.kq.no>
Jeff wrote:

> Is there any way to do this?
> 
> (defconstant *X* 10)
> (case 10 (*X* t)) ==> NIL
> 
> It would be really nice to use CASE with constants of some kind. I
> could always fall back on COND or IF's, and that isn't a problem. But
> if I'm missing a simple backquote operation or syntax construct, I'd
> like to learn it ;)
> 
It's late, but take a look at the macro-expansion of that case statement.
It quotes *X*, so your answer appears to be "no".

There should be a version that doesn't... somewhere... but in any case,
the macro you want would be ten minutes' work.
From: Stefan Scholl
Subject: Re: Putting evaluated constants in a CASE
Date: 
Message-ID: <1gus3ic8n78uv.dlg@parsec.no-spoon.de>
On 2004-08-23 00:57:57, Jeff wrote:

> Is there any way to do this?
> 
> (defconstant *X* 10)
> (case 10 (*X* t)) ==> NIL
> 
> It would be really nice to use CASE with constants of some kind.

(case 10 (#.*X* t)) ==> t
From: Martin Ginkel
Subject: Re: Putting evaluated constants in a CASE
Date: 
Message-ID: <cgfmu5$ocl$1@gwdu112.gwdg.de>
Jeff wrote:
> Is there any way to do this?
> 
> (defconstant *X* 10)
> (case 10 (*X* t)) ==> NIL
> 
> It would be really nice to use CASE with constants of some kind. I
> could always fall back on COND or IF's, and that isn't a problem. But
> if I'm missing a simple backquote operation or syntax construct, I'd
> like to learn it ;)

Had this problem some time ago; the constants must be defined before the
loading/compilation of the form. If they change, the form must be 
reloaded/compiled. I used it for casing on the enum-integer constants of
a ffi-ed C-Library, which can not change without recompile anyways.

(defmacro const-case (testform &body clauses)
   "this is like a case, but it evaluates all clause-heads at compile-time"
   `(case ,testform
      ,@(mapcar #'(lambda (clause)
		   (cons (eval (car clause)) (cdr clause))
		   )
	       clauses)
      )
   )
	CU
	Martin

-- 
+-[Martin Ginkel]-------------[mailto:mginkel(at)mpi-magdeburg.mpg.de]-+
| MPI Magdeburg, Zi S2.09    Sandtorstr. 1, D-39106 Magdeburg, Germany |
| A list is only as strong as its weakest link. -- Donald K.           |
|                                                                      |
+-[tel/fax: +49 391 6110 482/529]----[http://www.mpi-magdeburg.mpg.de]-+