Mixed up over mixins.

WhatMeWorry via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 20 12:27:43 PDT 2017


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.



More information about the Digitalmars-d-learn mailing list