DIP 1027---String Interpolation---Community Review Round 1
Steven Schveighoffer
schveiguy at gmail.com
Sat Dec 14 14:36:40 UTC 2019
On 12/14/19 3:56 AM, Walter Bright wrote:
> On 12/11/2019 2:49 PM, Steven Schveighoffer wrote:
>> Only thing better would be some way to set the default specifier to
>> avoid all the verbosity.
>
> Since that would require some extra syntax for each i string literal,
> it's not worth it.
>
It doesn't actually
i"$apples and $bananas" would still work. The default specifier is
optional, just like format specifier parameters e.g. %02x have an
optional 02.
The only time extra syntax would be required is if you start with a
brace and want to keep the default.
i`{"name" : $name}`.format; // JSON interpolated object.
This would result in a confusion because of the initial brace. (I'm
assuming here that we can use all the different quote types for convenience)
BUT
1. You can just do
i`{}{"name": $name}`.format;
i` {"name": $name}`.format; // taking advantage of the JSON grammar.
i`{%s}{"name": $name}`.format; // respecify default
2. Or if we have your proposal of allowing string concatenation (I'll
respond to that separately), then (i"{}" `{"name": $name}`).format
should work, and doesn't look terrible.
Normally an interpolated string will not have any need for the default
alteration, and you won't notice it.
I have some SQL strings with 10 or more fields, which would be
super-verbose to continually put {?} or to maybe forget one!
If there is a better default specifier sequence that you would accept,
that would be fine too.
-Steve
More information about the Digitalmars-d
mailing list