DIP 1027---String Interpolation---Community Review Round 1

Meta jared771 at gmail.com
Sat Dec 14 16:04:06 UTC 2019


On Saturday, 14 December 2019 at 08:36:15 UTC, 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.
>
> 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");
>
> 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}

One thing to note is that if string interpolation returns a 
struct like Adam proposed, concatenation would be possible 
between interpolated strings.


More information about the Digitalmars-d mailing list