D - the switch statement with reference to strings and case sensitivity
- scott tara.mvdomain (Scott Robinson) (21/21) Aug 17 2001 The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": ...
- Russ Lewis (2/9) Aug 17 2001 Or, perhaps, regular expressions could be used. :)
- scott tara.mvdomain (Scott Robinson) (16/27) Aug 17 2001 Yikes! Are regular expressions, by default, in the language?
- Russ Lewis (4/8) Aug 17 2001 Yeah, they're pretty heavyweight for simple compares, but they allow unb...
- Dave Nebinger (6/15) Aug 17 2001 Guys, what's wrong with "switch (lower(s)){case 'hello':..."?
- Christophe de Dinechin (12/14) Aug 18 2001 I am a bit puzzled by how this would be implemented.
- Walter (2/23) Aug 18 2001
The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }") I believe is a great addition. However, that said, you haven't specified if the string matching is case sensitive. Reason suggests it is, and this doesn't make the new switch statement ability as useful as it could be. I wonder if there could be a possible inclusion of of something like switch (s) with (y), in that y is/can be strcmp or stricmp? The dealings of return values, loops, and sensitivity to the case contents are all issues which can be worked out simply - but specific implementatoin I leave to the actual designers. Scott. -- jabber:quad jabber.org - Universal ID (www.jabber.org) http://dsn.itgo.com/ - Personal webpage robhome.dyndns.org - Home firewall -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GAT dpu s: a--- C++ UL+++ P++ L+++ E- W++ N+ o+ K w O M V- PS+ PE Y+ PGP+++ t++ 5 X R tv b++++ DI++++ D++ G+ e+ h! r- y ------END GEEK CODE BLOCK------
Aug 17 2001
Scott Robinson wrote:The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }") I believe is a great addition. However, that said, you haven't specified if the string matching is case sensitive. Reason suggests it is, and this doesn't make the new switch statement ability as useful as it could be. I wonder if there could be a possible inclusion of of something like switch (s) with (y), in that y is/can be strcmp or stricmp?Or, perhaps, regular expressions could be used. :)
Aug 17 2001
Yikes! Are regular expressions, by default, in the language? Regular expressions certainly seem to defeat the idea of a readable language. ;-) Plus they're a bit heavy weight for a couple case insensitive string comparisons. Scott. In article <3B7D3B11.47C93DE deming-os.org>, Russ Lewis wrote:Scott Robinson wrote:-- jabber:quad jabber.org - Universal ID (www.jabber.org) http://dsn.itgo.com/ - Personal webpage robhome.dyndns.org - Home firewall -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GAT dpu s: a--- C++ UL+++ P++ L+++ E- W++ N+ o+ K w O M V- PS+ PE Y+ PGP+++ t++ 5 X R tv b++++ DI++++ D++ G+ e+ h! r- y ------END GEEK CODE BLOCK------The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }") I believe is a great addition. However, that said, you haven't specified if the string matching is case sensitive. Reason suggests it is, and this doesn't make the new switch statement ability as useful as it could be. I wonder if there could be a possible inclusion of of something like switch (s) with (y), in that y is/can be strcmp or stricmp?Or, perhaps, regular expressions could be used. :)
Aug 17 2001
Scott Robinson wrote:Yikes! Are regular expressions, by default, in the language? Regular expressions certainly seem to defeat the idea of a readable language. ;-) Plus they're a bit heavy weight for a couple case insensitive string comparisons.Yeah, they're pretty heavyweight for simple compares, but they allow unbelievable flexibility. Perhaps something analogous to grep, where you can do "simple" compares with a trivial syntax, and regular expressions if necessary.
Aug 17 2001
Guys, what's wrong with "switch (lower(s)){case 'hello':..."? "Russ Lewis" <russ deming-os.org> wrote in message news:3B7D4064.66FF69BC deming-os.org...Scott Robinson wrote:insensitiveYikes! Are regular expressions, by default, in the language? Regular expressions certainly seem to defeat the idea of a readable language. ;-) Plus they're a bit heavy weight for a couple caseunbelievablestring comparisons.Yeah, they're pretty heavyweight for simple compares, but they allowflexibility. Perhaps something analogous to grep, where you can do"simple"compares with a trivial syntax, and regular expressions if necessary.
Aug 17 2001
Scott Robinson wrote:The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }") I believe is a great addition.I am a bit puzzled by how this would be implemented. Case 1: strings are simiilar in internal structure to C strings (a pointer to bytes, possibly with a length). Then, are two strings with the same content but different values equal in a switch? Note that you can't easily guarantee that the pointers for identical strings will always be equal, at least in the case of shared libraries... Case 2: strings are more complex things (like a string token, an ID in a string table, an atom, call it what you want). In that case, identity is easier to define, BUT you pay a price on every string creation. Christophe PS: Maybe this is somehwere in the spec, but I did not see it.
Aug 18 2001
Yes, it's case sensitive. -Walter Scott Robinson wrote in message ...The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }") I believe is a great addition. However, that said, you haven't specified if the string matching is case sensitive. Reason suggests it is, and this doesn't make the new switch statement ability as useful as it could be. I wonder if there could be a possible inclusion of of something like switch (s) with (y), in that y is/can be strcmp or stricmp? The dealings of return values, loops, and sensitivity to the case contents are all issues which can be worked out simply - but specific implementatoin I leave to the actual designers. Scott. -- jabber:quad jabber.org - Universal ID (www.jabber.org) http://dsn.itgo.com/ - Personal webpage robhome.dyndns.org - Home firewall -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GAT dpu s: a--- C++ UL+++ P++ L+++ E- W++ N+ o+ K w O M V- PS+ PE Y+ PGP+++ t++ 5 X R tv b++++ DI++++ D++ G+ e+ h! r- y ------END GEEK CODE BLOCK------
Aug 18 2001