DIP 1027---String Interpolation---Community Review Round 1

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Wed Dec 11 16:55:19 UTC 2019


On Wednesday, 11 December 2019 at 15:41:56 UTC, Patrick Schluter 
wrote:
> On Wednesday, 11 December 2019 at 10:57:13 UTC, Alexandru 
> Ermicioi wrote:
>> On Wednesday, 11 December 2019 at 09:52:21 UTC, Mike Parker 
>> wrote:
>>> [...]
>>
>> Why not just split interpolated string into just a tuple of 
>> args & strings. For example:
>> Given: (i"I ate %apples and %bananas totalling %(apples + 
>> bananas) fruit.")
>> Is lowered to a tuple: ("I ate ", apples, " and ", bananas," 
>> totalling ", apples + bananas," fruit.")
>>
>> It seems current version unnecessarily ties to printf 
>> formatting syntax, and makes harder for them to be used in 
>> custom user code.
>>
>> Also user still needs call a function to get assembled string 
>> which differs from what other languages are doing with 
>> interpolated strings.
>>
>
> This wouldn't work for C formats like printf. The proposition 
> has the nice property of being usable for DasBetterC and 
> interfacing with C libraries that use format specifiers 
> (libxml2 anyone?).

Indeed it doesn't, yet it falls nicely with std.conv.text, and 
variadic args versions of writeln, has less development overhead 
(no need to parse string for printf placeholders) when writing 
functions accepting resulting tuple from interpolation string, 
and could be made compatible with betterC mode by having a util 
func that transforms tuple to printf compliant version.

Best regards,
Alexandru.


More information about the Digitalmars-d mailing list