String Interpolation

duckchess duckchess at chess.com
Thu Oct 26 10:04:52 UTC 2023


On Thursday, 26 October 2023 at 09:42:27 UTC, Arafel wrote:
> On 26/10/23 3:47, Adam D Ruppe wrote:
>> [...]
>
> You are not mentioning this part:
>
>> [...]
>
> I would find it perfect if there were an option to define 
> arbitrary prefixes to strings (other than the ones already used 
> by the language), like `i"Hello, ${name}` or `sql"SELECT * FROM 
> ${table};"`. Notice how the string itself doesn't need any 
> marker in Java:
>
>> [...]
>
> It's needing both what I don't like and find confusing: `string 
> s = i"Hello, ${world}".format` (or `.text`).
>
> We can do like Java, and assume that as soon as a template 
> expression is found, it will be automatically considered an 
> interpolated string, so actually strings literals will be 
> interpolated by default, and only if there are no expressions 
> the result would be a `string`.

with adams proposal you could do
```d
sql!i"SELECT * FROM > ${table};"
```

which is good enough. as walter will never agree to macros, adams 
proposal is the most simple and flexible design, so we should go 
for that.


More information about the Digitalmars-d mailing list