Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2
Imperatorn
johan_forsberg_86 at hotmail.com
Thu Feb 4 13:37:32 UTC 2021
On Thursday, 4 February 2021 at 12:56:14 UTC, Adam D. Ruppe wrote:
> On Thursday, 4 February 2021 at 12:27:49 UTC, Imperatorn wrote:
>> Or get rid of $ like in C# and have
>>
>> i"I ate {nrOfApples} apples today" and
>> i"I ate {nrOfApples + nrOfOranges} fruits today"
>>
>> Clean imo
>
> Note that we chose the sequence ${expr} to avoid duplicating
> standard uses of symbols inside strings.
>
> This next bit isn't in the dip but Just using {} alone would
> conflict with tons of D syntax.
>
> mixin(iq{ void foo() { is this a function body or an
> interpolated section? } });
That would be like an interpolated verbatim string.
"iq" would be roughly equal to "$@" in that case.
In the example you provided, it depends on what character is
used. If { and } are used (instead of $), you need to escape
those by { and }.
Example in C# ("@" removed from "@$" because no escape characters
are present, also, since 8.0 the order doesn't matter, ie @$ EQU
$@):
1. string s = $"{ void foo() { is this a function body or an
interpolated section? } }";
2. string s = $"{{ void foo() { is this a function body or an
interpolated section? } }}";
In case 1 the entire expression is evaluated, in case 2 the
beginning and end curly brackets are "escaped" and therefore the
inner expression is evaluated.
More information can be found here:
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/string-interpolation
https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting
More information about the Digitalmars-d
mailing list