Some Thoughts On String Interpolation [l10n, restricting access, AA]

kdevel kdevel at vogtner.de
Fri Oct 27 13:06:12 UTC 2023


On Friday, 27 October 2023 at 12:22:00 UTC, Nick Treleaven wrote:
> On Thursday, 26 October 2023 at 11:18:46 UTC, kdevel wrote:
>> **Accessing Elements Of An AA**
>>
>> ```d
>> string[string] aa;
>> aa["name"] = "value";
>> writeln (i"The name in s is $(aa[\"name\"])"
>> ```
>>
>> That typing is laborious. Isn't there a way to bind the 
>> expression to the keys of the AA?
>
> I think that is orthogonal to the DIP

Maybe. I am under the impression that there are no valid real 
usecases for string interpolation. Currently I have on my notepad 
"HTML", "SQL" and "composition of filesystem paths", none of 
which I would like to do using string interpolation.

> (though having to escape the `"` does make it worse).

As far as I understood Adam correctly my code must read

```d
writeln (i"The name in s is $(aa["name"])");
//                            ^^^^^^^^^^
```

There was missing the closing parenthesis and the final 
semicolon, too.
According to Adam in [1] the marked part (^^^) is plain D code, 
so the quotation marks must not be escaped.

[1] 
https://forum.dlang.org/post/wbcvuejmwircauzgxmdh@forum.dlang.org


More information about the Digitalmars-d mailing list