String Interpolation

Arafel er.krali at gmail.com
Wed Oct 25 15:05:52 UTC 2023


On 25/10/23 13:29, Jonathan M Davis wrote:
> IMHO, mixins should be explicit, obvious, and greppable, and adding a 
> separate syntax for them which tries to hide them is going to make the 
> language worse. However a string is generated, if the programmer wants 
> to turn it into code, they should just use mixin, and if it's ugly, it's 
> ugly, but at least it's clear what's going on.

I agree, however the current options regarding string interpolation seem 
to be suboptimal:

1. Get a string interpolation that doesn't get you strings, and that 
needs support from the called function (or only work in specific cases, 
not for `foo(string bar);`. You also can't assign to string, nor use it 
in most libraries that don't support it explicitly.

2. Use a library solution using string mixins (quite cumbersome as a 
user, and probably also inefficient).

3. Introduce high level dependencies in the language itself, at least to 
do the formatting.

So I was just trying to brainstorm alternatives that would allow a 
library solution.

The biggest hurdle is accessing to the caller's scope, so far only 
string mixins get that. There could be perhaps a different feature that 
does it, i.e. a way to define a (compile time) function that get access 
to the caller's scope, but I'm not sure we would actually want that.


More information about the Digitalmars-d mailing list