Better string mixins
Michelle Long
HappyDance321 at gmail.com
Fri Dec 28 05:55:30 UTC 2018
The problem with mixing in code is that one has to manually build
code strings like:
static foreach(k; X)
mixin("int Var"~k~" = "~k~";);
which is error prone, ugly, time consuming, and harder to read.
Instead, I propose a simple extension:
static foreach(k; X)
mixin("int Var at k = @k;");
Here the @ simple, or whatever symbol would be best, takes the
variable and inserts it from the outer scope as a string,
converting it to a string if necessary.
It can only be used on such CT variables so errors should not
exist.
If necessary, maybe
static foreach(k; X)
@mixin("int Var at k = @k;");
or
static foreach(k; X)
mixin(@"int Var at k = @k;");
could be used.
This avoids having to do shit like
mixin("foo("~x~", "~y~", "~z~");");
so one has
mixin("foo(@x, at y, at z);");
which translates almost directly in to standard code(one can
simply strip the @'s).
More information about the Digitalmars-d
mailing list