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

Walter Bright newshound2 at digitalmars.com
Sat Dec 14 08:36:15 UTC 2019


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}


More information about the Digitalmars-d mailing list