Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more.

Sönke Ludwig via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Fri Sep 25 02:49:20 PDT 2015


Am 23.09.2015 um 16:33 schrieb Nick Sabalausky:
> (...)
>
> void main()
> {
>      int somevar = 42;
>      mixin interp;
>      iwriteln!("This is ${somevar}.");
>
>      int another = 17;
>      iwriteln!("This won't work, using ${another}.");
> }
>
> Seems like it would be too awkward and confusing to be worthwhile. :(
>

True, it's still far from being good. There is another possible syntax 
variation:

   mixin template iwriteln(string str, int line = __LINE__)
   {
     auto __dummy_/*~line*/ = () {
       import std.stdio;
       // pretend to parse the input string
       write("Result: ");
       write(result);
       writeln();
       return true;
     } ();
   }

   void main()
   {
     int result = 42;
     mixin iwriteln!"Result: #{result}";
   }

Works only for top-level calls, but has less visual noise, so maybe it 
makes sense to include that as a convenience function.


More information about the Digitalmars-d-announce mailing list