Interpolated strings
Martin Tschierschke via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 19 02:06:30 PDT 2017
On Monday, 17 April 2017 at 19:41:14 UTC, Jonas Drewsen wrote:
> On Monday, 17 April 2017 at 19:12:37 UTC, Martin Tschierschke
> wrote:
>> defining a new method exho! (derived from echo + mixin...:-)
>>
>> auto exho(string x)(){
>> return mixin("writeln("~interp!x~")");}
>>
>> You can just write:
>>
>> exho!"The number ${num} doubled is ${num * 2}!"
>
> It requires 'num' to be available to the exho function
> definition so will not
> work in the general case.
Thats a pity, so shouldn't we than try to find a way to define a
alias like 'shortcut'
for something like
mixin(compiletime_expresion!var)
so we can write just
shortcut!var ?
Or what about defining a new return type for functions allowing
them to return a mixin even if defined in a lib? (Because the
code above is allowed but only working if exho is defined in the
same scope as the var 'num'.)
Regards mt.
More information about the Digitalmars-d
mailing list