On Monday, 22 May 2017 at 15:26:26 UTC, Andrei Alexandrescu wrote:
Yah, didn't want to overload the article (or the discussion) with the expression/statement distinction. -- Andrei

Yeah, the details might be too much for a general audience (and I realize you know this, I'm commenting more for other readers who might be interested), but I do think this illustrates an important point for anyone who wants to use mixin: it is similar to, but not exactly like copy/pasting code into the source.

mixin parses a piece of code, then pastes the *AST node*, not the source code, into the tree where the mixin is found. That's why the semicolon is required in the statement context - it needs a complete branch that actually fits the AST at the moment, not just a string that is pasted into the source code at the location.

So similar enough to copy/paste to get someone quickly started playing with code generation, but this key difference is needed to really understand it.

Reply via email to