T... args!

Tejas notrealemail at gmail.com
Sat Apr 30 02:22:22 UTC 2022


On Friday, 29 April 2022 at 16:10:52 UTC, Salih Dincer wrote:
> On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer 
> wrote:
>> [...]
>
> I see, think it can be done with mixin:
> ```d
> template prn(alias args)
> {
>   string prn()
>   {
>     string result = "write(";
>     foreach(s; args.split("|"))
>     {
>       result ~= format("%s,", s);
>     }
>     return result ~ ");";
>   }
> }
>
> void main()
> {
>   int data = 456;
>   char enter = '\n';
>
>   mixin(prn!q{
>     enter| 123 | " str " |  data |
>
>     enter|    __TIME__   | enter }
>   );
>
>   mixin(
>     prn!q{"This value of " |41| " is prime."}
>   );
> }
> ```
>
> If there was some convenience on the compiler side, we could 
> integrate it into D.
>
> SDB at 79

There's already an implementation of `mixin` string interpolation 
in https://github.com/Abscissa/scriptlike


More information about the Digitalmars-d-learn mailing list