DIP 1027---String Interpolation---Community Review Round 1
Bastiaan Veelo
Bastiaan at Veelo.net
Wed Dec 11 23:09:01 UTC 2019
On Wednesday, 11 December 2019 at 22:49:01 UTC, Steven
Schveighoffer wrote:
> On 12/11/19 5:37 PM, H. S. Teoh wrote:
[…]
>> i"$abc" == tuple("%s", abc);
>> i"$({%d}abc)" == tuple("%d", abc);
>> i"$({?}abc)" == tuple("?", abc);
>>
>> For convenient interop with printf/writefln, we can still
>> default to
>> "%s" as the default placeholder, but the {} syntax now no
>> longer assumes
>> printf syntax, making i"" literals MUCH more useful in many
>> more places
>> outside the purvey of printf/writefln.
>>
>> So you'd do SQL strings like this:
>>
>> string name;
>> int serial;
>> float cost;
>> db.exec(i"INSERT INTO mytable VALUES (${?}name, ${?}serial,
>> ${?}cost)");
>>
>> which translates the last line to:
>>
>> db.exec("INSERT INTO mytable VALUES (?, ?, ?)", name, serial,
>> cost);
>>
>> without the need for any intermediate format string parser.
>
> OK, this is definitely a winner, way better than my idea. Only
> thing better would be some way to set the default specifier to
> avoid all the verbosity.
>
> Please make this part of the DIP Walter!
Isn’t
https://forum.dlang.org/post/vxzqttydlvzngrwrvipa@forum.dlang.org
better still? Streamlining template mixins could pay off in many
more places, and is truly extendable and customisable.
Bastiaan
More information about the Digitalmars-d
mailing list