DIP 1027---String Interpolation---Community Review Round 1
Steven Schveighoffer
schveiguy at gmail.com
Sat Dec 14 14:47:28 UTC 2019
On 12/14/19 3:36 AM, Walter Bright wrote:
> On 12/11/2019 11:33 AM, H. S. Teoh wrote:
>> 2) The previous example does bring up another issue: is there a nice way
>> to handle long interpolated strings, i.e., wrap long interpolated
>> strings to multiple lines? I.e., does the following work?
>>
>> database.exec(i"UPDATE %table SET key=%key, value=%{f}value "~
>> "WHERE index < %{d}index AND "~
>> "timestamp > %{D}lastTime");
>
> No. The trouble happens with how semantic analysis is done - leaves
> first, then non-leaves. It's just the wrong order to make the
> concatenation make sense.
What if the strings are all interpolated strings? e.g.:
database.exec(i"UPDATE %table SET key=$key, value=${f}value "~
i"WHERE index < ${d}index AND "~
i"timestamp > ${D}lastTime");
I don't know enough about the grammar/implementation to know if this
makes more sense or not.
>
> I've thought about this for the last week. The most practical idea is to
> simply concatenate adjacent strings, as in:
>
> database.exec(i"UPDATE %table SET key=%key, value=%{f}value "
> "WHERE index < %{d}index AND "
> "timestamp > %{D}lastTime");
But we deprecated that because it's too error prone.
> I.e. the 'i' string comes first, and gets concatenated with any
> following string literals. This also enables using 'q' strings as
> interpolated strings:
>
> i"" q{a + b}
I actually think 'i' should be able to go before any string literal.
e.g.:
iq{$a + $b}
i`$a + $b`
Just like suffixes can be applied to any string literal to alter the width.
-Steve
More information about the Digitalmars-d
mailing list