digitalmars.D - The X Macro
- Walter Bright (3/3) Jun 24 2010 http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html
- Yao G. (6/9) Jun 24 2010 http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/
- Walter Bright (2/5) Jun 24 2010 Autobanned again, sigh.
- Yao G. (5/9) Jun 24 2010 :'(
- Walter Bright (2/14) Jun 24 2010 Why don't we just give up on reddit and go with http://news.ycombinator....
- Bernard Helyer (4/20) Jun 24 2010 I prefer the reddit community, and the way reddit handles conversation
- Walter Bright (2/9) Jun 24 2010 I did - no reply.
- Walter Bright (3/4) Jun 24 2010 Even with it banned, it has gotten 5 downvotes, so it must be lurkers he...
- bearophile (5/7) Jun 25 2010 I don't know. Maybe they think C is not "cool". There is also this, they...
- Andrej Mitrovic (2/7) Jun 25 2010 I've upvoted. But I'm pretty sure you're supossed to use curly brackets ...
- Walter Bright (2/3) Jun 25 2010 Gaaah, how embarrassing! Fixed.
- Ellery Newcomer (3/5) Jun 24 2010 an example, taken to horrible extremes:
- bearophile (4/6) Jun 24 2010 Static introspection to the rescue! :-)
- MIURA Masahiro (13/14) Jun 24 2010 Interesting technique that I haven't heard of. However one of my
- Walter Bright (3/10) Jun 24 2010 It shouldn't. I wonder what they are doing, or if perhaps they just have...
- Jeff Merrick (6/6) Jun 25 2010 At the company I work for we call these "macro maps" and we always pass ...
- Justin Johansson (14/18) Jun 25 2010 Very cool article. Thanks Walter, I'll try to remember to pass that on
- Rory McGuire (5/23) Jun 25 2010 what processor/s are we talking about? I'm guessing ARM.
- Justin Johansson (8/42) Jun 25 2010 ARM is probably right. ARM, handhelds, mobile etc is where all the
- Rory McGuire (4/45) Jun 26 2010 found this about LDC. Do you know if there are plans for D2 on LLVM.
- Justin Johansson (5/58) Jun 26 2010 "Do you know if there are plans for D2 on LLVM?"
- BCS (7/12) Jun 26 2010 I did more or less the same thing to expand vector equations to there sc...
- KlausO (56/60) Jun 28 2010 I did something similar some time ago:
http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.
Jun 24 2010
http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/ I hope I don't screw up this time :D On Thu, 24 Jun 2010 17:10:35 -0500, Walter Bright <newshound2 digitalmars.com> wrote:http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jun 24 2010
Yao G. wrote:http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/ I hope I don't screw up this time :DAutobanned again, sigh.
Jun 24 2010
:'( On Thu, 24 Jun 2010 18:55:52 -0500, Walter Bright <newshound2 digitalmars.com> wrote:Yao G. wrote:-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/ I hope I don't screw up this time :DAutobanned again, sigh.
Jun 24 2010
Yao G. wrote::'( On Thu, 24 Jun 2010 18:55:52 -0500, Walter Bright <newshound2 digitalmars.com> wrote:Why don't we just give up on reddit and go with http://news.ycombinator.com/ ?Yao G. wrote:http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/ I hope I don't screw up this time :DAutobanned again, sigh.
Jun 24 2010
On Thu, 24 Jun 2010 19:09:36 -0700, Walter Bright wrote:Yao G. wrote:I prefer the reddit community, and the way reddit handles conversation threading. Perhaps you could email the Reddit guys and see why they keep getting autobanned?:'( On Thu, 24 Jun 2010 18:55:52 -0500, Walter Bright <newshound2 digitalmars.com> wrote:Why don't we just give up on reddit and go with http://news.ycombinator.com/ ?Yao G. wrote:http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/ I hope I don't screw up this time :DAutobanned again, sigh.
Jun 24 2010
Bernard Helyer wrote:On Thu, 24 Jun 2010 19:09:36 -0700, Walter Bright wrote:I did - no reply.Why don't we just give up on reddit and go with http://news.ycombinator.com/ ?I prefer the reddit community, and the way reddit handles conversation threading. Perhaps you could email the Reddit guys and see why they keep getting autobanned?
Jun 24 2010
Yao G. wrote:http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/Even with it banned, it has gotten 5 downvotes, so it must be lurkers here. Any downvoters care to say what's wrong with it?
Jun 24 2010
Walter Bright:Even with it banned, it has gotten 5 downvotes, so it must be lurkers here. Any downvoters care to say what's wrong with it?I don't know. Maybe they think C is not "cool". There is also this, they can be more interested: http://www.reddit.com/r/C_Programming/ Bye, bearophile
Jun 25 2010
Walter Bright Wrote:Yao G. wrote:I've upvoted. But I'm pretty sure you're supossed to use curly brackets when initializing that static char array there. ;)http://www.reddit.com/r/programming/comments/ciq5w/the_x_macro/Even with it banned, it has gotten 5 downvotes, so it must be lurkers here. Any downvoters care to say what's wrong with it?
Jun 25 2010
Andrej Mitrovic wrote:But I'm pretty sure you're supossed to use curly brackets when initializing that static char array there. ;)Gaaah, how embarrassing! Fixed.
Jun 25 2010
On 06/24/2010 05:10 PM, Walter Bright wrote:Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.an example, taken to horrible extremes: http://www.dsource.org/projects/dexcelapi/browser/trunk/src/dxl/biff/Enums.d
Jun 24 2010
Walter Bright:Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.Static introspection to the rescue! :-) Bye, bearophile
Jun 24 2010
On 06/25/2010 07:10 AM, Walter Bright wrote:http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.htmlInteresting technique that I haven't heard of. However one of my friends, a lead programmer at Sega, says they use similar technique extensively in C++; actually they avoid overusing it, as it slows down compilation considerably. And for this particular Color case, enum in D can have a base type: enum Color: string { RED = "red", GREEN = "green", BLUE = "blue", } writeln(Color.RED); // gives "red" so we don't have that maintainance problem :-)
Jun 24 2010
MIURA Masahiro wrote:On 06/25/2010 07:10 AM, Walter Bright wrote:It shouldn't. I wonder what they are doing, or if perhaps they just have a miserably slow macro processor.http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.htmlInteresting technique that I haven't heard of. However one of my friends, a lead programmer at Sega, says they use similar technique extensively in C++; actually they avoid overusing it, as it slows down compilation considerably.
Jun 24 2010
At the company I work for we call these "macro maps" and we always pass the X macro as a parameter. Macro maps are common knowledge here because they are used fairly extensively; in the filesystem alone I found 16 instances of the technique. The token pasting that's often used in conjunction with macro maps often makes it difficult to find the definition of the constructed token, but as far as keeping different tables and declarations in sync with one another, I've yet to find a good alternative in C.
Jun 25 2010
Walter Bright wrote:http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.Very cool article. Thanks Walter, I'll try to remember to pass that on to my grandkids :-) Also on that DDJ page I saw the ad for the Samsung Bada developer challenge. http://developer.bada.com/challenge/index.do There is some decent $prize money on offer here. Of course you have to use the Samsung Bada SDK which I understand is C++. Naturally we would all delight in one of the winning entires being some Bada app written in D. Now thinking about a killer app for D, me thinks it doesn't really matter what that app really does or if even it is really lame. The real kill would come from a D app winning a prize in the Bada Developer Challenge. So wadda you reckon?
Jun 25 2010
On Fri, 25 Jun 2010 15:11:53 +0200, Justin Johansson <no spam.com> wrote:Walter Bright wrote:what processor/s are we talking about? I'm guessing ARM. GDC is a bit out dated isn't it? (GDC being the only D compiler that might support ARM processors) -Roryhttp://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.Very cool article. Thanks Walter, I'll try to remember to pass that on to my grandkids :-) Also on that DDJ page I saw the ad for the Samsung Bada developer challenge. http://developer.bada.com/challenge/index.do There is some decent $prize money on offer here. Of course you have to use the Samsung Bada SDK which I understand is C++. Naturally we would all delight in one of the winning entires being some Bada app written in D. Now thinking about a killer app for D, me thinks it doesn't really matter what that app really does or if even it is really lame. The real kill would come from a D app winning a prize in the Bada Developer Challenge. So wadda you reckon?
Jun 25 2010
Rory McGuire wrote:On Fri, 25 Jun 2010 15:11:53 +0200, Justin Johansson <no spam.com> wrote:ARM is probably right. ARM, handhelds, mobile etc is where all the action is at the moment. You are dead right about GDC; it's dead and nowhere near D2. D (D2) needs a marketing and rollout plan. One good such plan would embrace ARM, handhelds, mobile etc. Hint, hint. Golden (marketing) opportunities like this do not come around very often.Walter Bright wrote:what processor/s are we talking about? I'm guessing ARM. GDC is a bit out dated isn't it? (GDC being the only D compiler that might support ARM processors) -Roryhttp://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.Very cool article. Thanks Walter, I'll try to remember to pass that on to my grandkids :-) Also on that DDJ page I saw the ad for the Samsung Bada developer challenge. http://developer.bada.com/challenge/index.do There is some decent $prize money on offer here. Of course you have to use the Samsung Bada SDK which I understand is C++. Naturally we would all delight in one of the winning entires being some Bada app written in D. Now thinking about a killer app for D, me thinks it doesn't really matter what that app really does or if even it is really lame. The real kill would come from a D app winning a prize in the Bada Developer Challenge. So wadda you reckon?
Jun 25 2010
On Fri, 25 Jun 2010 15:35:30 +0200, Justin Johansson <no spam.com> wrote:Rory McGuire wrote:found this about LDC. Do you know if there are plans for D2 on LLVM. http://comments.gmane.org/gmane.comp.compilers.llvm.ldc/1 -RoryOn Fri, 25 Jun 2010 15:11:53 +0200, Justin Johansson <no spam.com> wrote:ARM is probably right. ARM, handhelds, mobile etc is where all the action is at the moment. You are dead right about GDC; it's dead and nowhere near D2. D (D2) needs a marketing and rollout plan. One good such plan would embrace ARM, handhelds, mobile etc. Hint, hint. Golden (marketing) opportunities like this do not come around very often.Walter Bright wrote:what processor/s are we talking about? I'm guessing ARM. GDC is a bit out dated isn't it? (GDC being the only D compiler that might support ARM processors) -Roryhttp://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.Very cool article. Thanks Walter, I'll try to remember to pass that on to my grandkids :-) Also on that DDJ page I saw the ad for the Samsung Bada developer challenge. http://developer.bada.com/challenge/index.do There is some decent $prize money on offer here. Of course you have to use the Samsung Bada SDK which I understand is C++. Naturally we would all delight in one of the winning entires being some Bada app written in D. Now thinking about a killer app for D, me thinks it doesn't really matter what that app really does or if even it is really lame. The real kill would come from a D app winning a prize in the Bada Developer Challenge. So wadda you reckon?
Jun 26 2010
Rory McGuire wrote:On Fri, 25 Jun 2010 15:35:30 +0200, Justin Johansson <no spam.com> wrote:"Do you know if there are plans for D2 on LLVM?" I think others would know better than myself though I have previously surmised from this ng that D implementation for LLVM is waning at the moment.Rory McGuire wrote:found this about LDC. Do you know if there are plans for D2 on LLVM. http://comments.gmane.org/gmane.comp.compilers.llvm.ldc/1 -RoryOn Fri, 25 Jun 2010 15:11:53 +0200, Justin Johansson <no spam.com> wrote:ARM is probably right. ARM, handhelds, mobile etc is where all the action is at the moment. You are dead right about GDC; it's dead and nowhere near D2. D (D2) needs a marketing and rollout plan. One good such plan would embrace ARM, handhelds, mobile etc. Hint, hint. Golden (marketing) opportunities like this do not come around very often.Walter Bright wrote:what processor/s are we talking about? I'm guessing ARM. GDC is a bit out dated isn't it? (GDC being the only D compiler that might support ARM processors) -Roryhttp://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.Very cool article. Thanks Walter, I'll try to remember to pass that on to my grandkids :-) Also on that DDJ page I saw the ad for the Samsung Bada developer challenge. http://developer.bada.com/challenge/index.do There is some decent $prize money on offer here. Of course you have to use the Samsung Bada SDK which I understand is C++. Naturally we would all delight in one of the winning entires being some Bada app written in D. Now thinking about a killer app for D, me thinks it doesn't really matter what that app really does or if even it is really lame. The real kill would come from a D app winning a prize in the Bada Developer Challenge. So wadda you reckon?
Jun 26 2010
Hello Walter,http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.I did more or less the same thing to expand vector equations to there scalar components. But for some reason I needed two passes through cpp and a run through grep/sed (I think cpp was refusing to expand a macro on the correct side of another macro. -- ... <IXOYE><
Jun 26 2010
I did something similar some time ago: import std.stdio; struct EnumDescription { char[] name; char[] description; }; // // generates an enum, an associated string table and a "save" lookup // function which determines the string which belongs to an given enum // char[] generate_enum(char[] enumname, EnumDescription[] list) { // create enum declaration char result[] = "enum " ~ enumname ~ "{"; foreach(entry; list) { result ~= entry.name ~ ","; } result ~= "};"; // create description array result ~= `private static char[][` ~ enumname ~ `.max + 1] s_` ~ enumname ~ `ToString = [`; foreach(entry; list) { result ~= enumname ~ "." ~ entry.name ~ ` : "` ~ entry.description ~ `",`; } result ~= "];"; // create save "toString" function result ~= `static char[] ` ~ enumname ~ `ToString(` ~ enumname ~ ` type) { if (type <= ` ~ enumname ~ `.max) { return s_` ~ enumname ~ `ToString[type]; } return "<invalid enum, no description available>"; }`; return result; } const EnumDescription[] ErrorList = [ { "INTERNAL_ERROR" , "internal error" }, { "ALLOCATION_ERROR" , "allocation error" }, { "INTEGER_EXPECTED" , "integer expected" }, ]; mixin(generate_enum("ErrorType", ErrorList)); void main() { writefln(ErrorType.ALLOCATION_ERROR, " : ", ErrorTypeToString(ErrorType.ALLOCATION_ERROR)); } Greets KlausO Walter Bright schrieb:http://www.drdobbs.com/blog/archives/2010/06/the_x_macro.html Even though D doesn't have a text macro preprocessor, this can be done using string mixins and a bit of CTFE.
Jun 28 2010