Re: switch statement and numeric constants
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: switch statement and numeric constants

From: Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
Date: Fri May 27 2005 - 12:20:55 CEST

Klaus wrote:
> switch -regexp expr( x & VAL_A|VAL_C) \
> $VAL_A { } \
> $VAL_C|$VAL_C {} \

You probably want something like this:

   switch -exact -- [expr {$x & ($VAL_A|$VAL_C)}] \
         $VAL_A { ... } \
         [expr {$VAL_A|$VAL_C}] { ... }

The next level of thought is to disconnect from representing things as
integers in the first place and instead look at other representations
that take advantage of the fact that strings are *the* fundamental
datatype of Tcl (by contrast, in C it's really the machine-word). That's
quite a change though, and probably requires a lot of reworking of the
rest of your program too.

Donal.
Received on Thu Sep 29 14:19:27 2005