digitalmars.D - 'in' keyword, anyone?
- Sam (27/27) May 26 2005 I need an 'in' keyword that behaves like the following:
- Brad Beveridge (3/4) May 26 2005 http://digitalmars.com/d/arrays.html
- Derek Parnell (11/14) May 26 2005 int[char[]] theList;
- Chris Sauls (8/9) May 26 2005 Or even just this:
- Derek Parnell (13/23) May 26 2005 I'm quite pedantic with my bools and I don't like to implicitly convert
- Hasan Aljudy (3/44) May 26 2005 There IS an "in" keyword ...
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
Sam wrote:I need an 'in' keyword that behaves like the following:http://digitalmars.com/d/arrays.html Brad
May 26 2005
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
Derek Parnell wrote:bool b = a in theList ? true : false;Or even just this: 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: -- Chris Sauls
May 26 2005
On Thu, 26 May 2005 21:13:41 -0500, Chris Sauls wrote:Derek Parnell wrote:I'm quite pedantic with my bools and I don't like to implicitly convert integers to bools. Just a thing I have... ;-)bool b = a in theList ? true : false;Or even just this: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: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
May 26 2005
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 26 2005