Just another example of missing string interpolation

kdevel kdevel at vogtner.de
Fri Oct 13 15:16:27 UTC 2023


On Friday, 13 October 2023 at 14:25:34 UTC, bachmeier wrote:
> On Friday, 13 October 2023 at 12:04:18 UTC, kdevel wrote:
>> On Thursday, 12 October 2023 at 21:45:55 UTC, bachmeier wrote:
>>>> [...]
>>>> What if `s` is `"${a}"` and `subs` is `["a": "${b}", "b": 
>>>> "x"]`?
>>>
>>> That's the reason it needs to be supported by the language.
>>
>> The problem with your code is that it loops over the wrong 
>> list.
>> It should iterate over the variable occurrences in the string 
>> `s`.
>
> That depends. If you don't want to do all of the substitutions,

You don't have to do all substitutions in one go. If a key is 
missing
in `subs` one alternative to throwing `MissingKey` could be to 
silently
skip that variable occurrence.

> either because you potentially have `${something}` as part of 
> the final string,

How do you convey that intent inside the string? `format` does it 
by
estabilishing a special syntax for `%` (`%%` -> `%`).

How do you handle that case with DIP 1027?

And reminder: How do you implement your `interp` function in 
terms of
DIP 1027's string interpolation?


More information about the Digitalmars-d mailing list