Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2

Arafel er.krali at gmail.com
Thu Feb 4 16:31:17 UTC 2021


On 4/2/21 17:15, Meta wrote:
> However, if you want a tuple sequence as described in the DIP, you can 
> simply call a (probably compiler-supplied) helper method; maybe it 
> doesn't even have to be new: why not .tupleof?
> 
> auto apples = 2;
> auto bananas = 3;
> 
> auto s1 = i"I have ${apples + bananas} fruit";
> static assert(is(typeof(s1) == string));
> 
> auto s2 = i"I have ${apples + bananas} fruit".tupleof;
> 
> Then we can hide all the complexity of interpolated sequences behind the 
> .tupleof (or whatever we decide on) magic property.

Could this be made so it's transparent to the user of a library?

I.e. in the SQL case, the user of a library just types:

```
auto result = connection.execute(i"SELECT * FROM foo WHERE bar = ${baz}");
```

instead of

```
auto result = connection.execute(i"SELECT * FROM foo WHERE bar = 
${baz}".tupleof);
```

If it has to be explicit, how would the signature of 
Connection.execute(...) look like? How would the user easily know that 
the function expects an interpolated literal, just by looking at it?


More information about the Digitalmars-d mailing list