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
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.
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
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]-+