Meta-programming - examples

janderson askme at me.com
Sun Feb 11 16:30:53 PST 2007


Witold Baryluk wrote:
 > Nice ideas.
 >
 > I'm also thinking on few powerful things.
 >
 > Compile time XML parser:
 >  - configuration files:
 >
 >    config.xml:
 >      <start><tag v="aa"></start>
 >
 >    mixin(buildclasses!(xml(import("config.xml")));
 >    writefln(xml.start.tag.v);  // will print aa
 >
 >    mixin(xpath!(xml, val, "start/tag.v"));
 >    writefln(val);    // "aa"
 >

I think XML reading will be really useful.  In my game - programming - 
experience XML (including the binary version) is good for proto-typing 
but it eventually needs to be replaced by a binary format.  It's just to 
slow to phase, you want your data in the same order as the data 
structures, not all over the place.   Compile time xml would solve that 
(sort of because you've moved the bottleneck).

However most of the time in my field design/art can't compile the 
executables themselves.  A possible work around is to compile XML dll's 
on the fly, the final version would not need to do this.


 > There is endless posibilities to extend syntax.
 > We can practicly implement some small langauages in this way,
 > and emit D code with some templates.
 >
 > This is pretty cool, but we will need even quicker compilation time, 
for this to be
 > fully useful.

Agreed.
 >
 > Even after compiler optimalisations, IDE will have problems with 
parsing such things.

They could always be put into another file if this is of concern.  That 
way xml will look fine (if the editor is smart enough).  Having said 
that most DSL scripting languages don't get syntax highlighting, and its 
not worth the effort.

 >
 > I think we also should have regexp functions accessible in compile 
time. It is painful to
 > parse things by hand.
 >
I agree, but I think they are only a sub-set of what we need.  I think 
regex extentions could be implemented by a suped-up 
template/compile-time language.



More information about the Digitalmars-d mailing list