Jump to page: 1 2 3
Thread overview
Select statement?
May 19, 2004
Lev Elbert
May 19, 2004
Stewart Gordon
May 21, 2004
Lev Elbert
May 21, 2004
Stewart Gordon
May 21, 2004
Lev Elbert
May 24, 2004
Stewart Gordon
May 24, 2004
Mike Swieton
May 24, 2004
J Anderson
May 25, 2004
Stewart Gordon
May 25, 2004
Stewart Gordon
May 19, 2004
Andy Friesen
May 19, 2004
h3r3tic
May 19, 2004
Juan C
May 19, 2004
Roel Mathys
May 19, 2004
Juan C
May 19, 2004
Roel Mathys
Simple text replacement, was Re: Select statement?
May 19, 2004
Juan C
May 20, 2004
Roel Mathys
May 20, 2004
James McComb
May 20, 2004
Ant
May 20, 2004
Stewart Gordon
May 19, 2004
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
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 :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
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
>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:

>>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
>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
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
« First   ‹ Prev
1 2 3