T... args!

Salih Dincer salihdb at hotmail.com
Sat Apr 30 05:06:42 UTC 2022


On Saturday, 30 April 2022 at 02:22:22 UTC, Tejas wrote:
> 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

I took a quick look and didn't like it!  Maybe it would be more 
useful to use it in a comprehensive project.

I like simple things more.  In D, I would like to be able to 
write:

```d
printq("Value: " stack.pop ", address 0x" stack.length + 
stack.ptr);
```

But due to a habit from C, I say like this:

```d
writef("Value: %s, address 0x%s", stack.pop, stack.length + 
stack.ptr);
```
Longer, yes, but I respect it.  There are many people like me who 
love the old.  But I also love the new conveniences:
```d
with(new Stack!IDs)
{
   while(!empty)
   {
     "Value".write(": ", pop);
     ", ".writefln!"%saddress 0x%x"
     (length + ptr);
   }
}
```
I like these too!  But it's not enough!  It's not enough, you 
know?  I'm a human!  I don't know what postfix is!  I have to 
keep up with the computer not it me.
The computer has to keep up with me, not me! Because I created it.

Ve's-selam, SDB at 79





More information about the Digitalmars-d-learn mailing list