Variable references in strings (Was: Structs implementing interfaces
Don
nospam at nospam.com
Tue Feb 10 04:13:21 PST 2009
Ary Borenszweig wrote:
> bearophile wrote:
>> Ary Borenszweig:
>>> res ~= res ~= "\n\treturn
>>> cast(${iface})cast(void*)&_iface_${iface}_vtbl;";
>>
>> Have you tried std.metastrings.Format!()? I use it quite often.
>
> template Format(A...)
> Formats constants into a string at compile time. Analogous to
> std.string.format().
>
> Parameters:
> A = tuple of *constants*, which can be strings, characters, or
> integral values.
>
> I want it in runtime. I basically want this:
>
> foo = `Hello ${var}!`;
>
> or
>
> foo = `Hello $var!`;
>
> to be the same as:
>
> foo = `Hello ` ~ var ~ `!`;
>
> You can see in this trivial example how readability is improved (and you
> type less), and in a bigger example (like the one in this thread) it
> should be better.
More than a year ago, I created a CTFE function dollar() to do that.
It's a very simple. No language support is required.
foo = mixin(dollar("Hello $var!"));
We just need a way to get rid of the "mixin(" bit.
More information about the Digitalmars-d
mailing list