Discussion Thread: DIP 1036--Formatted String Tuple Literals--Community Review Round 1

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Sep 12 14:47:47 UTC 2020


On 9/12/20 9:44 AM, Paul Backus wrote:
> On Saturday, 12 September 2020 at 12:37:14 UTC, Andrei Alexandrescu wrote:
>> On 9/11/20 5:36 PM, Stefan Koch wrote:
>>>
>>> could be a compiler tuple which doesn't need std nor object.d.
>>
>> Shouldn't because it needs to be expandable on demand, not implicitly.
> 
> The only way I can think of to do this that works in the general case is 
> something like the following:
> 
> // Before
> writeln(i"Hello $name!".expand);
> 
> // After
> template Pack(Args...)
> {
>      alias expand = Args;
> }

Affirmative. We have that already: 
https://dlang.org/library/std/typecons/tuple.expand.html

A dead simple Pack would have a good place in druntime and have Tuple be 
an elaboration thereof.

> auto ref __interpexpr1() { return name; }
> 
> writeln(Pack!("Hello ", __interpexpr1, "!").expand);
> 
> The reason you can't use a struct (that is, a "run=time tuple") is that 
> the mapping from *expressions* to *values* is not injective--it discards 
> information about ref-ness and lazy-ness (and maybe others I haven't 
> thought of?). And the reason you have to "quote" each expression by 
> wrapping it in a function is that template argument lists only accept 
> symbols, not expressions.
> 
> I'm not sure if I like this better or worse than DIP 1027's "naked 
> argument list" approach.

I'd say don't complicate with that. Copy everything into the tuple. When 
one reaches for interpolated strings, it's not like they're hoping for a 
speed demon. Okay to draw the line at @nogc.


More information about the Digitalmars-d mailing list