mixin functions
Gor Gyolchanyan
gor.f.gyolchanyan at gmail.com
Thu Nov 1 08:55:56 PDT 2012
I find myself doing this very very often and it pains me to write ugly code
like this over and over again:
mixin(()=>{
string result;
foreach(i; 0..10)
result ~= "writeln(" ~ to!string(i); ~ ");\n"'
return result;
}());
All it does is generates a string in a delegate, which is immediately
called and passed to a mixin.
Almost all mixins contain generated strings and most if them need a
dedicated string generator.
I don't want to propose new syntax, because we all know that new syntax is
the last thing that will be developed, considering the number of bugs out
there. The first thing I wanted to do was this:
mixin
{
foreach(i; 0..10)
mixin ~= "writeln(" ~ to!string(i); ~ ");\n"'
}
I'm not suggesting this to be implemented, this is just what I
automatically wanted to write.
Anybody else had this kind of thoughts?
--
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121101/a99fef49/attachment-0001.html>
More information about the Digitalmars-d
mailing list