String mixin syntax sugar

Dmitry Olshansky dmitry.olsh at gmail.com
Tue Mar 20 12:38:54 PDT 2012


On 20.03.2012 22:25, Mantis wrote:
> Hello,
>
> since people discussed a lot about user-defined attributes recently,
> I've been thinking about a way to implement it with a string mixins. The
> problem with them is their syntax - it's far from what we want to use in
> everyday job.

Use template mixins? At least in struct/class area that catches the most 
attention it should work perfectly.

  I understand, they should be easily distinguished at use
> site, but perhaps this may be accomplished in other ways as well. My
> idea is to translate this kind of statements:
>
> # identifier statement
>
> into this:
>
> mixin( identifier( q{ statement } ) );
>
> where an identifier is a, possibly templated, function that accepts one
> string argument and returns a string. Here are some possible use cases:
>
> #serialize int a; // marked to be serializable
> #serialize!not int b; // -.- non-serializable
>
> #readonly float c; // generate trivial private setter and public getter

Why not just leave it alone, and (if need comes) turn it into property 
on demand.

>
> #handles!Events.Foo void handler(); // event handler
>
> #attribute!"Foo" void foo(); // function with additional compile-time info

It's just voodoo - no guaranties that #attribute can do that given the 
above rewrite.

>
> Most of these examples require some D parser, but, since it is planned
> to add parser-generation into Phobos, this shouldn't be a problem.
> What do you think, does it have some value for the language, and, if
> yes, is it possible to implement?

Looks like throwing nukes to pin down a pesky cockroach.
The sugar is more or less nice, but encourages ineffective compile-time 
wise idiom.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list