[REBOL] Re: How can one use named constants in switch?
From: joel:neely:fedex at: 25-Oct-2001 14:48
Hi, Gregg,
OUTSTANDING!
Gregg Irwin wrote:
> First, you could set MsgType to be the literal word matching
> the case you want:
>
> case_a: 1
> case_b: 2
>
> msgType: 'case_b
>
> switch msgType [
> case_a [print "msgA" ]
> case_b [print "msgB" ]
> ]
>
> Now, of course, that obviates the need for defining the case
> words! I don't know the best way to emulate enums, for those
> of us accustomed to using them, and I don't know that we need to...
>
You are *SO* right. The whole origin of "enums" was a way to
give a meaningful name to a concept in program text (although
the primitive language underneath required/preferred that the
actual data be numbers).
The main advantage to using words as names for code numbers
is that the data become portable across programs, languages,
machines, etc. However, the I/O translation routines could
be the place where those issues are encapsulated.
-jn-
--
This sentence contradicts itself -- no actually it doesn't.
-- Doug Hofstadter
joel<dot>neely<at>fedex<dot>com