[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] case - should that even work?
From: |
Thomas Chust |
Subject: |
Re: [Chicken-users] case - should that even work? |
Date: |
Sun, 15 Jul 2018 20:50:39 +0200 |
On Sun, 15 Jul 2018 20:36:41 +0200 Martin Schneeweis <address@hidden> wrote:
> [...]
> please can someone explain to me why the following even works?
>
> (define sym 'b)
>
> (case sym
> ('a "an 'a'")
> ('b "a 'b'")
> ('c "a 'c'")
> (else "something else")) ; -> a 'b'
> [...]
> I know the r5rs document just says "Each <clause> _should_ have the
> form ((<datum1> ...) <expression1> <expression2> ...)
> [...]
Hello,
contrary to what you assume, these clauses *are* actually in the form specified
by the standard :-D
The apostrophe is a *reader* macro, so before the compiler or interpreter ever
gets to see that code, 'a is transformed to (quote a), 'b to (quote b) and 'c
to (quote c). These three forms are obviously lists with two elements and
represent case descriptors matching the symbols quote or a, quote or b and
quote or c respectively.
Try setting sym to 'quote and see what happens!
Ciao,
Thomas
--
The greatest victory is that which requires no battle.
-- Sun Tzu, "The Art of War"