mixin functions
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Nov 1 12:49:27 PDT 2012
On Thu, Nov 01, 2012 at 08:31:30PM +0100, Jacob Carlborg wrote:
> On 2012-11-01 16:55, Gor Gyolchanyan wrote:
> >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:
[...]
> I would vote for AST macros instead.
[...]
Yeah, mixins are a kind of hack that's unfortunately rather widely used
right now. A proper AST macro system would be much better. But I'm not
holding my breath for it, given how many issues we still have to fix
with our current feature set.
T
--
Indifference will certainly be the downfall of mankind, but who cares? -- Miquel van Smoorenburg
More information about the Digitalmars-d
mailing list