DIP 1027--String Interpolation--Final Review Discussion Thread
Arine
arine123445128843 at gmail.com
Tue Feb 4 18:20:27 UTC 2020
On Tuesday, 4 February 2020 at 07:12:11 UTC, Walter Bright wrote:
> On 2/3/2020 5:06 PM, Jonathan Marler wrote:
>> Some applications want the "Strings and Expressions" form
>> rather than the "Format String" form.
>
> To have "strings and expressions" then write it that way:
>
> foo("I want ", i, " bananas");
This just seems entirely tone death to the comment he made. All
interpolated strings are is syntactic sugar. You can just write
the alternative (including printf), the purpose of interpolated
strings is to not to.
To be useful it has to become something like this:
> i"$apples and ${%d}bananas"
>
> =>
>
> (__d_format_literal!(Format.init, " and ", Format("%d")),
> apples, bananas)
__d_format_literal is easy to parse compared to just a string. So
it is easier to turn it back into essentially a tuple, at the
cost of slow CTFE.
With this it'd be easy to check and just throw an error at
compile time if you don't want to allow custom formatting as well.
This is probably the best solution so far that still allows
customization and supports specifying custom formats that can be
used with printf.
i"value is ${%6.2f}value"
I just wouldn't want Format() to just be a string either though.
It'd be useful if it split all the options up appropriately. That
way you don't have to parse the format string yourself.
More information about the Digitalmars-d
mailing list