New syntax for string mixins

Jonathan M Davis jmdavisProg at gmx.com
Thu Dec 16 14:05:27 PST 2010


On Thursday, December 16, 2010 11:28:03 Jacob Carlborg wrote:
> On 2010-12-15 23:00, Nick Sabalausky wrote:
> > "Jonathan M Davis"<jmdavisProg at gmx.com>  wrote in message
> > news:mailman.1035.1292441722.21107.digitalmars-d at puremagic.com...
> > 
> >> On Wednesday, December 15, 2010 11:27:47 Jacob Carlborg wrote:
> >>> That was my idea as well, that
> >>> 
> >>> @get_set("int", "bar");
> >>> 
> >>> could be translated into
> >>> 
> >>> mixin(get_set("int", "bar")); just like
> >>> 
> >>> just like scope statements are translated into try/catch/finally.
> >> 
> >> Honestly, I don't see much gain in using @ rather than mixin(). It's a
> >> little
> >> less typing, but that's it.
> > 
> > It does seem like a small difference, just replacing "mixin" with "@" and
> > removing one layer of parens. But I think that extra layer of parens,
> > minor as it seems, makes a big difference in the readability (and
> > "typeability") of mixin invocations. Those extra parens do get to be a
> > real bother, major visual noise at least to my eyes.
> 
> ^^ I completely agree.
> 
> >> And it precludes stuff like mixin("lhs " ~ op ~ "
> >> rhs") like happens all the time in overloaded operator functions.
> > 
> > I don't see why these shouldn't work:
> > 
> > @"int foo;";
> > return @("lhs " ~ op ~ " rhs");
> > 
> > At least with just the "@" part of the proposal. Maybe the delegate thing
> > might make it tricker, I dunno.
> 
> My idea was actually to get rid of the strings where the code to be
> mixed in is defined and to have a better syntax where it's used.
> 
> The delegates are just a way of passing a block of code around. If you
> just use it in place then maybe one could do like this:
> 
> @(int foo;);
> return @(lhs@(op)rhs);

I would have thought that template mixins would be the thing to use when you 
didn't want to deal with strings. string mixins are extremely powerful and 
flexible, and I'd really hate to lose them. And IIRC, Kenji Hara was working on a 
module to really help make dealing with complicated string mixins easier and 
less painful. Anything that you propose is going to have to have major benefits 
over the current string mixin situation for it to stand any chance of being 
accepted.

- Jonathan M Davis


More information about the Digitalmars-d mailing list