Interpolated strings

Nick Sabalausky (Abscissa) via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 20 11:49:13 PDT 2017


On 04/20/2017 02:40 PM, Nick Sabalausky (Abscissa) wrote:
>
> auto exho()
> {
>      return writeln("${name} and this are app ${age*365*24} hours!");
> }
>

Correction:

auto exho()
{
     return writeln(
         ""~
         _interp_text(name)~
         " and this are app "~
         _interp_text(age*365*24)~
         " hours!"
     );
}

Where _interp_text is really just a thin wrapper over std.conv.text.

Again, note that `name` and `age` are undefined symbols unless exho is 
defined as a nested function within the function that actually defines 
`name` and `age`.

And again, this is exactly why interp!"..." was forced to work by 
returning a string for the caller to mixin.



More information about the Digitalmars-d mailing list