String Interpolation

Imperatorn johan_forsberg_86 at hotmail.com
Sun Oct 22 12:22:00 UTC 2023


On Sunday, 22 October 2023 at 11:32:12 UTC, Arafel wrote:
> On 21/10/23 19:10, Walter Bright wrote:
>> For DIP1027,
>> 
>> |int var = 67; auto s = format(i"whatever $var"); |
>> 
>> would be equivalent to:
>> 
>> |auto s = "whatever 67";|
>
> At which point it's barely an improvement overs what we can 
> already do:
>
> ```
> int var = 67; auto s = mixin(i!"whatever $var");
> ```
>
> I'm not saving even one keypress, and readability isn't that 
> much better either.
>
> And we'll end up with multiple string literals, like `r"` and 
> `q"`, and then something called "interpolated string" that uses 
> a very similar token `i"` but that can't be used as a string, 
> not even in the most straightforward cases.
>
> Don't you think this will be unnecessarily confusing for users?
>
> That's why I prefer DIP1036 over DIP1027, or even YAIDIP.
>
> I understand that you don't want to make it implicitly 
> convertible to strings. Fair enough, I'm sure there are solid 
> reasons for that. But please, in that case, don't call it a 
> "string", and also don't give it a string-like syntax.
>
> Perhaps "interpolated sequence" with a clearly differentiated 
> syntax? That would describe the feature much better.

Agreed, it's misleading. In almost all languages in existence it 
is implied that you want a string. It's about ergonomics. It 
should be clearly stated that you do *not* get a string and have 
to do that yourself, or more convenient ways should be added to 
do what you want in 99% of cases.


More information about the Digitalmars-d mailing list