digitalmars.D - Select statement?
- Lev Elbert (22/22) May 19 2004 I have a suggestion: let's include in D a select statement with non-stat...
- Stewart Gordon (21/31) May 19 2004 Not quite sure how that would be.
- Lev Elbert (29/60) May 21 2004 Stewart!
- Stewart Gordon (10/24) May 21 2004 What would that achieve? Besides a little syntax error?
- Lev Elbert (15/16) May 21 2004 1. (Sorry for error).
- Stewart Gordon (48/56) May 24 2004 What order of checking would the rest of the terms have? Start at the
- Mike Swieton (13/38) May 24 2004 I dislike your style blocks because:
- J Anderson (15/51) May 24 2004 How? Remember his version doesn't have a colon. Also I don't think
-
Stewart Gordon
(11/24)
May 25 2004
- Stewart Gordon (16/22) May 25 2004 Confusing - not sure.
- Andy Friesen (5/14) May 19 2004 There's not much point in this because it doesn't really affect what D
- h3r3tic (2/13) May 19 2004 or just add 'elif' for lazy ppl :P
- Juan C (2/3) May 19 2004 Lazy is right, I never saw any need for elif; "else if" works just fin...
- Roel Mathys (6/13) May 19 2004 yeah, but elif is 4 letters, else if is 6 letters and a space, that's
- Juan C (7/10) May 19 2004 Well, no, a disk storage (and network transfer) savings of 43%. And I've...
- Roel Mathys (5/21) May 19 2004 this could be "the" ultimate reason to add a preprocessor to D,
- Juan C (8/10) May 19 2004 Not a full-blown preprocessor, just a simple one. Or allow "C preprocess...
- Roel Mathys (10/12) May 20 2004 I don't agree, I've seen enough so-called 4th generation language tools,...
- James McComb (3/5) May 19 2004 Yeah, Walter, let's see your fancy mixins do this! ;)
- Ant (17/39) May 19 2004 No this is the job of your IDE.
- Stewart Gordon (13/26) May 20 2004 As if
I have a suggestion: let's include in D a select statement with non-static conditions: seclect () { case a < b: .... break; case sin(k) < cos(b): .... break; case str == "12345": .... break; case default: .... break; } which is equivalent to if - else if - else block, but in some cases more compact and understandable. I would not mind if instead of select another keyword would be used and maybe case is not needed. Regards.
May 19 2004
Lev Elbert wrote:I have a suggestion: let's include in D a select statement with non-static conditions: seclect () { case a < b: .... break;<snip>which is equivalent to if - else if - else block, but in some cases more compact and understandable.Not quite sure how that would be. if (a < b) { .... } else if (sin(k) < cos(b)) { .... } else if (str == "12345") { .... } else { .... } That's compact. I'd have no trouble understanding it. It's even cleanly structured compared to switch. Indeed, I proposed a cleanly structured switch syntax a while back.... http://www.digitalmars.com/drn-bin/wwwnews?D/22722 Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 19 2004
Stewart! if (a < b) { .... } else if (sin(k) < cos(b)) { .... } else { } isn't a bad substitute for: select { case a < b: ..... break; case (sin(k) < cos(b): ..... break; default: ..... break; } but try to express: select { default: ..... break; case a < b: ..... break; case (sin(k) < cos(b): ..... break; } Based on the results of the discussion bellow, I can tell that most of the programmers do not need extra expression power. OK! It was just a suggestion :) I read your proposal. It is good, but static. "select" covers both static and non static and optimization is up to compiler. "Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:c8fmuu$20co$1 digitaldaemon.com...Lev Elbert wrote:non-staticI have a suggestion: let's include in D a select statement withconditions: seclect () { case a < b: .... break;<snip>which is equivalent to if - else if - else block, but in some cases more compact and understandable.Not quite sure how that would be. if (a < b) { .... } else if (sin(k) < cos(b)) { .... } else if (str == "12345") { .... } else { .... } That's compact. I'd have no trouble understanding it. It's even cleanly structured compared to switch. Indeed, I proposed a cleanly structured switch syntax a while back.... http://www.digitalmars.com/drn-bin/wwwnews?D/22722 Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 21 2004
Lev Elbert wrote: <snip>but try to express: select { default: ..... break; case a < b: ..... break; case (sin(k) < cos(b): ..... break; }What would that achieve? Besides a little syntax error?Based on the results of the discussion bellow, I can tell that most of the programmers do not need extra expression power. OK! It was just a suggestion :) I read your proposal. It is good, but static. "select" covers both static and non static and optimization is up to compiler.<snip top of upside-down reply> It is perectly orthogonal to your idea AFAICS. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 21 2004
What would that achieve? Besides a little syntax error?1. (Sorry for error). 2. In if-else if-else terms: else first. In some cases - more understandable. Sure, all what can be expressed by select can be expressed by if-elseif-else. This is the matter of taste. I just do not like extra "distracting" words. In the case if (...) { } else if (.....) { } else { } the conditions are hidden in "else ifs". In short: program with select() would be more compact and understandable then if-else if. But discussion is immatereal - nobody wants to implement it :)
May 21 2004
Lev Elbert wrote:What order of checking would the rest of the terms have? Start at the bottom and work up? <snip>What would that achieve? Besides a little syntax error?1. (Sorry for error). 2. In if-else if-else terms: else first. In some cases - more understandable.In short: program with select() would be more compact and understandable then if-else if.<snip> More compact? select { case ...: ... break; case ...: ... break; default: ... } versus if (...) { ... } else if (...) { ... } else { ... } OTOH, if my suggested syntax is extended to this, we'd have select { case ... { ... } else case ... { ... } else { ... } } if select/break block select Lines (as shown) 7 10 9 Tokens 14 13 13 Chars (as shown) 39 63 57 Chars (squashed up) 23 31 38 (The token and char counts exclude the dots.) OK, so it saves a token in this example, but that's about all it saves. As for more understandable, maybe. But as you rightly say, it's a matter of style. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 24 2004
On Mon, 24 May 2004 10:43:11 +0100, Stewart Gordon wrote:OTOH, if my suggested syntax is extended to this, we'd have select { case ... { ... } else case ... { ... } else { ... } } if select/break block select Lines (as shown) 7 10 9 Tokens 14 13 13 Chars (as shown) 39 63 57 Chars (squashed up) 23 31 38 (The token and char counts exclude the dots.) OK, so it saves a token in this example, but that's about all it saves. As for more understandable, maybe. But as you rightly say, it's a matter of style. Stewart.I dislike your style blocks because: - it appears that they would make case fallthrough be confusing or impossible. - they differ from existing standards, and I don't feel they add enough to justify the difference. - a change would break existing code. I don't think the advantages outweight the disadvantages. Mike Swieton __ It's so simple to be wise. Just think of something stupid to say and then don't say it. - Sam Levenson
May 24 2004
Mike Swieton wrote:On Mon, 24 May 2004 10:43:11 +0100, Stewart Gordon wrote:How? Remember his version doesn't have a colon. Also I don't think there's a need for the else part. Something like: switch (...) { case ... { } case ... { } } Fall through is a big problem for many programmers. -- -Anderson: http://badmama.com.au/~anderson/OTOH, if my suggested syntax is extended to this, we'd have select { case ... { ... } else case ... { ... } else { ... } } if select/break block select Lines (as shown) 7 10 9 Tokens 14 13 13 Chars (as shown) 39 63 57 Chars (squashed up) 23 31 38 (The token and char counts exclude the dots.) OK, so it saves a token in this example, but that's about all it saves. As for more understandable, maybe. But as you rightly say, it's a matter of style. Stewart.I dislike your style blocks because: - it appears that they would make case fallthrough be confusing or impossible. - they differ from existing standards, and I don't feel they add enough to justify the difference. - a change would break existing code.
May 24 2004
J Anderson wrote: <snip>Also I don't think there's a need for the else part. Something like: switch (...) { case ... { } case ... { } }<snip> That would cause the second part to be executed if its case matched, even if the first case also matched. Of course, in the one I gave, the final else could otherwise be default. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 25 2004
Mike Swieton wrote: <snip>I dislike your style blocks because: - it appears that they would make case fallthrough be confusing or impossible.Confusing - not sure. Impossible - only if the condition has a side effect. Otherwise, you can do it by nesting cases. Of course, you would need to repeat the condition to be fallen through from, but considering that fall-through is a bit of a dirty trick anyway....- they differ from existing standards, and I don't feel they add enough to justify the difference.No more than the very invention of a select statement would in the first place. If a specification were set in so much stone that it couldn't even be added to, you wouldn't- a change would break existing code.How? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 25 2004
Lev Elbert wrote:I have a suggestion: let's include in D a select statement with non-static conditions: which is equivalent to if - else if - else block, but in some cases more compact and understandable. I would not mind if instead of select another keyword would be used and maybe case is not needed. Regards.There's not much point in this because it doesn't really affect what D can express, nor does it save a huge amount of effort when one is trying to express any particular idea. -- andy
May 19 2004
In article <c8fk6j$1s53$1 digitaldaemon.com>, Lev Elbert says...seclect () { case a < b: .... break; case sin(k) < cos(b): .... break; (...) which is equivalent to if - else if - else block, but in some cases more compact and understandable.or just add 'elif' for lazy ppl :P
May 19 2004
or just add 'elif' for lazy ppl :PLazy is right, I never saw any need for elif; "else if" works just fine, is easier to read, etc. etc. etc...
May 19 2004
Juan C wrote:yeah, but elif is 4 letters, else if is 6 letters and a space, that's upto 75% more, so adding elif would mean an increase in productivity of almost 43% :-) roelor just add 'elif' for lazy ppl :PLazy is right, I never saw any need for elif; "else if" works just fine, is easier to read, etc. etc. etc...
May 19 2004
yeah, but elif is 4 letters, else if is 6 letters and a space, that's upto 75% more, so adding elif would mean an increase in productivity of almost 43%Well, no, a disk storage (and network transfer) savings of 43%. And I've only got 75GB of free space on my disk! I'd better watch out. One of my Perl books around here states (jokingly I hope) that Perl doesn't have "elif" because it's "file" spelled backward. Who am I to argue with that? (Oy!) More seriously: if "elif" is added simply to take the place of "else if", I would hope that "else if" becomes illegal. On the other hand you can write "elif" and have a text replacement utility replace it with "else if".
May 19 2004
Juan C wrote:this could be "the" ultimate reason to add a preprocessor to D, replace all "elif" with "else if" <g> bye, roelyeah, but elif is 4 letters, else if is 6 letters and a space, that's upto 75% more, so adding elif would mean an increase in productivity of almost 43%Well, no, a disk storage (and network transfer) savings of 43%. And I've only got 75GB of free space on my disk! I'd better watch out. One of my Perl books around here states (jokingly I hope) that Perl doesn't have "elif" because it's "file" spelled backward. Who am I to argue with that? (Oy!) More seriously: if "elif" is added simply to take the place of "else if", I would hope that "else if" becomes illegal. On the other hand you can write "elif" and have a text replacement utility replace it with "else if".
May 19 2004
this could be "the" ultimate reason to add a preprocessor to D, replace all "elif" with "else if" <g>Not a full-blown preprocessor, just a simple one. Or allow "C preprocessor" output to be piped into the compiler, of course that's up to the compiler writer, not the language. If there were several competing D compilers (and there will be) features like this could be deciding factors in choosing one. (Can you say "non-portable"?) Barring that, the community ought to agree on one text replacement utility to use. And if that were the C preprocessor it would be abused I'm sure. Oh, I keep forgetting to see if I could use HTML for text replacement!
May 19 2004
Juan C wrote:If there were several competing D compilers (and there will be) features like this could be deciding factors in choosing one. (Can you say "non-portable"?)I don't agree, I've seen enough so-called 4th generation language tools, this would be one more. code containing the elif is not D, as long as the specification does not allow it. It's best to put in the specs (before 1.0 is released) how vendor-specific extension can be but into the language. C++ has something like that, don't recall exactly what it is, but MS used it to define some extra's into their Managed C++. bye, roel
May 20 2004
Roel Mathys wrote:this could be "the" ultimate reason to add a preprocessor to D, replace all "elif" with "else if" <g>Yeah, Walter, let's see your fancy mixins do this! ;) James McComb
May 19 2004
On Wed, 19 May 2004 23:19:26 +0200, Roel Mathys wrote:Juan C wrote:No this is the job of your IDE. in leds you can define any identifier to expande to any text you can have gpl expanded to the gpl common header with the project name inserted. you can define "ei" to expande to" if ( $cursor ) { } else if ( ) { } else { } any minimal code editor should be able to do that. Antthis could be "the" ultimate reason to add a preprocessor to D, replace all "elif" with "else if" <g>yeah, but elif is 4 letters, else if is 6 letters and a space, that's upto 75% more, so adding elif would mean an increase in productivity of almost 43%Well, no, a disk storage (and network transfer) savings of 43%. And I've only got 75GB of free space on my disk! I'd better watch out. One of my Perl books around here states (jokingly I hope) that Perl doesn't have "elif" because it's "file" spelled backward. Who am I to argue with that? (Oy!) More seriously: if "elif" is added simply to take the place of "else if", I would hope that "else if" becomes illegal. On the other hand you can write "elif" and have a text replacement utility replace it with "else if".
May 19 2004
Juan C wrote:As if else ifelse ifelse ifelse ifelse ifelse ifelse ifelse ifelse if were a valid program....yeah, but elif is 4 letters, else if is 6 letters and a space, that's upto 75% more, so adding elif would mean an increase in productivity of almost 43%Well, no, a disk storage (and network transfer) savings of 43%. And I've only got 75GB of free space on my disk! I'd better watch out.One of my Perl books around here states (jokingly I hope) that Perl doesn't have "elif" because it's "file" spelled backward. Who am I to argue with that? (Oy!)Maybe you should use lreP then....More seriously: if "elif" is added simply to take the place of "else if", I would hope that "else if" becomes illegal.What would that achieve?On the other hand you can write "elif" and have a text replacement utility replace it with "else if".You could do all kinds of text replacements to translate an ad-hoc language into D. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 20 2004