On Wednesday, 23 September 2015 at 19:28:03 UTC, Nick Sabalausky wrote:
On 09/23/2015 03:18 PM, Chad Joan wrote:

This is why I argued for alternative mixin syntax in D some ... years?
... ago.

It'd be really cool to have a writefln overload that did this:

int somevar = 42;
writefln#("This is ${somevar}");

writefln#("Plus two and you get ${somevar+1}");

Which would just be shorthand for

int somevar = 42;
mixin writefln!("This is ${somevar}");

mixin writefln!("Plus two and you get ${somevar+2}");

I feel like a bit of syntax sugar could go a long way ;)

Yea, the trouble with string mixins is that they're ugly enough people don't like to use them.

I'd argued in the past for a way to tag a CTFE-able string-returning function as being intended for mixing-in, so you could omit the "mixin(...)" part. But we only ever got it for template mixins. Allowing it for string mixins was too controversial. :(

I dunno, maybe even a string mixin sugar as simple as this would be a big help:

mixin!func(args to func here)


mixin!interp("Some string here")

But I'm guessing the ship's ling since sailed for anything like that.

I hope not :(

I remember when Walter originally designed mixins, he stated something to the effect that he wanted them to be easily greppable at all times.

I would argue that they are so centrally important that they should be a symbol rather than a keyword. Still greppable. But also much more useful.

Since D already has the mixin keyword, I suspect it would be more practical to just ask people to grep for 'mixin|<mixin symbol>' instead of just 'mixin'.

There are similar (but orthogonal) concerns with delegate (anonymous function) nesting:

// D notation.
foo ( (x,y) {
    auto z = doSomething(x+y);
    return z*z;


// Speculative notation.
foo() : (x,y) {
    auto z = doSomething(x+y);
    return z*z;

Current D notation for nesting functions reminds me of C's notation for structs...

// C notation.
typedef struct WhatDoIPutHereFoo
    int x,y;
} Foo;

// D notation.  (Yay, consistency!)
struct Foo
    int x,y;

Extra semicolon and syntax noise and such.

I'm still incredibly glad D even has delegates and mixins at this point ;)

Reply via email to