"string interpolation"
Amex
Amex at gmail.com
Sat Jun 8 21:28:13 UTC 2019
I and many others write a code that uses string mixins simply to
define a symbol based on others:
mixin(T~" "~id~" = "~value~");");
This is very ugly and it is impossible to debug properly.
Why not allivate this issue? Is is so common that there can be a
short hand syntax that the compiler can decode naturally.
e.g.,
#T #id = #value;
Or whatever syntax one wants to device.
¡T¡¡id¡ = ¡value¡;
↕T ↕id = ↕value;
Whatever...
The compiler then types the symbol and tries to resolve it. If it
is a string in it inserts it directly as a symbol.
Basically whatever the simplification it is effectively lowered
in to a string mixin...
but because it is expected to be used in a statement or
expression it can be parsed. Only the marked symbols are resolved
and everything else must be a valid expression. Essentially the
compiler resolves the symbols then parses the string as if it
were typed in as direct code. Since the symbol substitution is
well defined it can easily backtrack to pinpoint the error in the
"mixin".
if id = "fdf";
↕"int" ↕id = ↕"3";
is the same as
int fdf = 3;
Of course, if T is a type then
↕T ↕id = ↕value;
is the same as
T ↕id = ↕value;
More information about the Digitalmars-d
mailing list