Mixed up over mixins.
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 20 12:41:14 PDT 2017
On 08/20/2017 12:27 PM, WhatMeWorry wrote:
> // 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.
Yes, it means that the string must be legal D code.
> mixin(`writeln(` ~ `Hello` ~ `);` );
Yes, that's a D string but the string itself is not legal D code because
it would be mixing in the following:
writeln(Hello);
The problem is, there is no Hello defined in the program.
You need to make sure that Hello is a string itself:
writeln("Hello");
So, you need to use the following mixin:
mixin(`writeln(` ~ `"Hello"` ~ `);` );
Ali
More information about the Digitalmars-d-learn
mailing list