DIP 1027---String Interpolation---Community Review Round 1
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Wed Dec 11 14:30:17 UTC 2019
On Wednesday, 11 December 2019 at 11:01:58 UTC, MrSmith wrote:
> On Wednesday, 11 December 2019 at 10:57:13 UTC, 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.")
>
> That's an option, but one would also need to figure out
> handling of format specifiers
Do we really need support for format specifiers which are mostly
appliable for primitive numeric type? I doubt existing format
specifiers could be used with structs, classes, or any aggregate
structures.
An alternative to specifiers we could define free functions that
would format numeric values as needed allowing us to write smth
like:
i"I ate %apples and %bananas totalling %(apples +
bananas).format(formatargs))"
then, accepting function wouldn't require to meddle with specific
printf semantics, and will get properly pre-formatted data to
process.
if format specifiers are still desired they could be passed as
separate arguments similar how it is done for getopts, and then
accepting function would need to treat them in context of passed
args.
Best regards,
Alexandru.
More information about the Digitalmars-d
mailing list