Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 26, 2005 'in' keyword, anyone? | ||||
---|---|---|---|---|
| ||||
I need an 'in' keyword that behaves like the following: bool b = a in {"AAAA", "BB", "CCCCCC", "Lemon"}; -or- bool b = a in CollectionObject; b = a in ArrayObject; Where the above statement is the same as: bool b; switch(a) { case "AAAA": b = 1 // true!! break; case "BB": b = 1; break; case "CCCCCC": b = 1; break; case "Lemon": b = 1; break; case else: b = 0; // false!! I refuse to use keywords imposed by the MAN! break; } Maybe I use too much SQL, but 'in' used in this fashion would be nice! See? I'm not against ALL keywords!! (-; |
May 26, 2005 Re: 'in' keyword, anyone? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam | Sam wrote: > I need an 'in' keyword that behaves like the following: http://digitalmars.com/d/arrays.html Brad |
May 26, 2005 Re: 'in' keyword, anyone? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam | On Thu, 26 May 2005 18:52:52 +0000 (UTC), Sam wrote: > I need an 'in' keyword that behaves like the following: > > bool b = a in {"AAAA", "BB", "CCCCCC", "Lemon"}; int[char[]] theList; theList["AAAA"] = 1; theList["BB"] = 2; theList["CCCCCC"] = 3; theList["Lemon"] = 4; bool b = a in theList ? true : false; -- Derek Parnell Melbourne, Australia 27/05/2005 6:10:49 AM |
May 26, 2005 Re: 'in' keyword, anyone? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam | Sam wrote:
> I need an 'in' keyword that behaves like the following:
>
> bool b = a in {"AAAA", "BB", "CCCCCC", "Lemon"};
>
> -or-
>
> bool b = a in CollectionObject;
> b = a in ArrayObject;
>
> Where the above statement is the same as:
>
> bool b;
>
> switch(a)
> {
> case "AAAA":
> b = 1 // true!!
> break;
>
> case "BB":
> b = 1;
> break;
>
> case "CCCCCC":
> b = 1;
> break;
>
> case "Lemon":
> b = 1;
> break;
>
> case else:
> b = 0; // false!! I refuse to use keywords imposed by the MAN!
> break;
> }
>
> Maybe I use too much SQL, but 'in' used in this fashion would be nice!
>
> See? I'm not against ALL keywords!! (-;
>
>
There IS an "in" keyword ...
But I just don't know how to use it.
|
May 27, 2005 Re: 'in' keyword, anyone? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> bool b = a in theList ? true : false;
Or even just this:
# bool b = (a in theList) == null;
Except he says he doesn't like the 'null' keyword. And I wonder, would a null pointer implicity cast to a 'false' and a valid pointer implicitly cast to a 'true'? Then you could just do:
# bool b = a in theList;
-- Chris Sauls
|
May 27, 2005 Re: 'in' keyword, anyone? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sauls | On Thu, 26 May 2005 21:13:41 -0500, Chris Sauls wrote: > Derek Parnell wrote: >> bool b = a in theList ? true : false; I'm quite pedantic with my bools and I don't like to implicitly convert integers to bools. Just a thing I have... ;-) > Or even just this: > > # bool b = (a in theList) == null; Or more like this ... bool b = (a in theList) != null; > Except he says he doesn't like the 'null' keyword. And I wonder, would a null pointer implicity cast to a 'false' and a valid pointer implicitly cast to a 'true'? Then you could just do: > > # bool b = a in theList; Nup, D is smart enough to realize that pointers are not integers so an implicit conversion doesn't fly. Though this (ugly construct) is possible ... bool b = !!(a in theList); -- Derek Melbourne, Australia 27/05/2005 12:22:31 PM |
Copyright © 1999-2021 by the D Language Foundation