digitalmars.D.learn - case statements
- Ellery Newcomer (14/14) Oct 10 2009 This is probably a bad idea, but from my readings of the dmd source, I
- Jeremie Pelletier (8/28) Oct 10 2009 D supports case ranges:
- Jarrett Billingsley (8/22) Oct 10 2009 A single string mixin must consist of an entire, fully-formed
- Ellery Newcomer (10/21) Oct 10 2009 Yeah they do. Ever wonder why you can do things like duff's device? Or
- Christopher Wright (3/12) Oct 10 2009 No, you can put multiple case labels together. A case "statement" is
- Ellery Newcomer (4/17) Oct 10 2009 We're probably thinking on different levels. I'm down on the syntactic
This is probably a bad idea, but from my readings of the dmd source, I noticed some preprocessor defines that looked useful, along the lines of #define CASES case A:case B: (etc) I'd kinda like something similar in D, but a naive attempt with mixins doesn't work, e.g. immutable string cases = "case 1: case 2:"; //my d2fu sucks .. switch(x){ mixin(cases); dosomething(); default: dosomething(); } Any ideas (not including concatenating cases with body of case)?
Oct 10 2009
Ellery Newcomer wrote:This is probably a bad idea, but from my readings of the dmd source, I noticed some preprocessor defines that looked useful, along the lines of #define CASES case A:case B: (etc) I'd kinda like something similar in D, but a naive attempt with mixins doesn't work, e.g. immutable string cases = "case 1: case 2:"; //my d2fu sucks .. switch(x){ mixin(cases); dosomething(); default: dosomething(); } Any ideas (not including concatenating cases with body of case)?D supports case ranges: switch(x) { case 1: .. case 10: doSomething(); default: doSomething(); }
Oct 10 2009
On Sat, Oct 10, 2009 at 8:45 PM, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:This is probably a bad idea, but from my readings of the dmd source, I noticed some preprocessor defines that looked useful, along the lines of #define CASES case A:case B: (etc) I'd kinda like something similar in D, but a naive attempt with mixins doesn't work, e.g. immutable string cases =3D "case 1: case 2:"; //my d2fu sucks .. switch(x){ =A0 =A0mixin(cases); =A0 =A0 =A0dosomething(); =A0 =A0default: =A0 =A0 =A0dosomething(); } Any ideas (not including concatenating cases with body of case)?A single string mixin must consist of an entire, fully-formed statement, expression, or declaration (depending on where it's used). Case labels do not, on their own, count as a statement. In addition, there is a bug that prevents you from string-mixing-in cases inside a switch. For some reason you have to mix in the entire switch statement.
Oct 10 2009
Jarrett Billingsley wrote:On Sat, Oct 10, 2009 at 8:45 PM, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:Yeah they do. Ever wonder why you can do things like duff's device? Or case 1: case 2: or switch(x){ case 3: }This is probably a bad ideaA single string mixin must consist of an entire, fully-formed statement, expression, or declaration (depending on where it's used). Case labels do not, on their own, count as a statement.In addition, there is a bug that prevents you from string-mixing-in cases inside a switch. For some reason you have to mix in the entire switch statement.http://d.puremagic.com/issues/show_bug.cgi?id=1534 Hey! there's even a patch for it! And it works! Rainier, you da man!
Oct 10 2009
Ellery Newcomer wrote:Jarrett Billingsley wrote:No, you can put multiple case labels together. A case "statement" is just a special category of label.On Sat, Oct 10, 2009 at 8:45 PM, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:Yeah they do. Ever wonder why you can do things like duff's device? OrThis is probably a bad ideaA single string mixin must consist of an entire, fully-formed statement, expression, or declaration (depending on where it's used). Case labels do not, on their own, count as a statement.
Oct 10 2009
Christopher Wright wrote:Ellery Newcomer wrote:We're probably thinking on different levels. I'm down on the syntactic level. parseStatement(flag) can parse 'case x:' and nothing more if there's nothing more.Jarrett Billingsley wrote:No, you can put multiple case labels together. A case "statement" is just a special category of label.On Sat, Oct 10, 2009 at 8:45 PM, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:Yeah they do. Ever wonder why you can do things like duff's device? OrThis is probably a bad ideaA single string mixin must consist of an entire, fully-formed statement, expression, or declaration (depending on where it's used). Case labels do not, on their own, count as a statement.
Oct 10 2009