DIP 1027---String Interpolation---Community Review Round 1
Patrick Schluter
Patrick.Schluter at bbox.fr
Wed Dec 11 15:46:55 UTC 2019
On Wednesday, 11 December 2019 at 11:35:05 UTC, rumbu wrote:
> On Wednesday, 11 December 2019 at 11:00:12 UTC, MrSmith wrote:
>> On Wednesday, 11 December 2019 at 10:48:56 UTC, Rumbu wrote:
>>> So we cannot have variables named d, s, f, g, x and so on
>>> because they are standard format specifiers. What happens
>>> with custom format specifiers, any one letter variable cannot
>>> be interpolated?
>>
>> According to proposal you would wrap format specifiers into
>> {}, like i"%{d}bananas"
>
> Nope, that means "use %d format specifier to print number of
> bananas". According to the DIP, this is invalid:
No. Read the grammar. Format specifiers MUST be in {}.
Element:
Character
'%%'
'%' Argument
'%' FormatString Argument
FormatString:
'{' FormatString '}'
CharacterNoBraces
CharacterNoBraces:
CharacterNoBrace
CharacterNoBrace CharacterNoBraces
CharacterNoBrace:
characters excluding '{' and '}'
characters does not exclude s, d, f, g etc.
>
> string what = "bread";
> int d = 10;
> writefln(i"making %what using %d ingredients");
which is transformed in
writefln("making %s using %s ingredients", what, d);
More information about the Digitalmars-d
mailing list