It's stuff like this which makes me very frustrated. Or depressed because it demonstrates just how poor a programmer I am:


string printStatement(string message) {
    return `writeln("` ~ message ~ `");`;
}

void main()
{
// Mixins are for mixing in generated code into the source code.
    // The mixed in code may be generated as a template instance
    // or a string.

    mixin(printStatement("hello world"));
    mixin(`writeln(` ~ `Hello`  ~ `);` );
    mixin("writeln(`World`);");       
}

Compiling gives me the errors:

Error: undefined identifier Hello

To me, `writeln(` ~ `Hello` ~ `);` is a valid D string? Okay, maybe a
string expression but a string nevertheless.

So, am I giving mixin more magical powers than it possesses?

Should we say that mixin needs to be given a "fully pre-formed D compilable" string?

Thanks. especially to let me vent.

Reply via email to