DIP 1027---String Interpolation---Community Review Round 1
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Sun Dec 15 00:18:39 UTC 2019
On Saturday, 14 December 2019 at 07:34:05 UTC, Walter Bright
wrote:
> On 12/11/2019 2:57 AM, Alexandru Ermicioi 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.")
>
> I don't see the point of that. The user could write it that way
> to begin with.
Yes he could. The main concern I have is that current proposal is
tied to printf syntax (template string first, and then args to
replace) which will be quite cumbersome for people who would like
to use tuple resulting from interpolation. They will need to
parse template string to find all args placeholders and then
split template string on those locations in most basic case. This
is unnecessary boilerplate code thrown onto user. Example above
solves this issue by removing the need to parse this template
string since it won't be there anymore. In any case Adam's
version seems more versatile and could work nicely, allowing user
to choose what he would get from interpolation. For example it
could alias itself to a built version of interpolated string, and
expose interface to get interpolated tuple in printf format, or
in format suitable for text function. Also having such structure
we could encode other information such as variable prefix syntax
used in interpolation string if it is decided to have the ability
to change prefix, which could be then used nicely to throw
asserts on wrong interpolation syntax being used and etc.
The only thing is I don't understand why a struct is not
sufficient for interpolated string in Adam's proposal.
Best regards,
Alexandru
More information about the Digitalmars-d
mailing list