Thread overview | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 19, 2004 Select statement? | ||||
---|---|---|---|---|
| ||||
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 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lev Elbert | 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 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lev Elbert | 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 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lev Elbert | 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 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to h3r3tic | >or just add 'elif' for lazy ppl :P
Lazy is right, I never saw any need for elif; "else if" works just fine, is easier to read, etc. etc. etc...
|
May 19, 2004 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juan C | Juan C wrote:
>>or just add 'elif' for lazy ppl :P
>
>
> Lazy is right, I never saw any need for elif; "else if" works just fine, is
> easier to read, etc. etc. etc...
>
>
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%
:-)
roel
|
May 19, 2004 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roel Mathys | >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 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juan C | 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%
>
>
> 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".
>
>
this could be "the" ultimate reason to add a preprocessor to D,
replace all "elif" with "else if" <g>
bye,
roel
|
May 19, 2004 Simple text replacement, was Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roel Mathys |
>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 20, 2004 Re: Select statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roel Mathys | 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
|
Copyright © 1999-2021 by the D Language Foundation