October 21

On Saturday, 21 October 2023 at 12:38:52 UTC, Commander Zot wrote:

>

can we please just have i"whatever ${var}" to return a fully interpolated string, not a tuple, not a template or anything.
because the common use case is auto s = i"whatever ${var}";,
so maybe just lower it into format("whatever %s", var).

Then also introduce t"whatever ${var}" for a tuple/template returned object as a completely seperate proposal and you discuss whatever proposal is better for it YADIP or 1037 or whatever.

this way it's also a lot simpler to understand what is happening for the users.

Interpolated strings, even if they look like it, are NOT strings. They are a obfuscated or better said, conveniently laid out source code.

They contain inside of them, between the {} program code even if it is just a variable name. Strings are strictly just data. Interpolated string is a mix of CODE and data.

By the very nature of what interpolated strings are it is not possible to treat them as strings.

October 21

On Saturday, 21 October 2023 at 15:59:06 UTC, duckchess wrote:

>

can we just lower ___"" into mixin(___!""), where ___ can be any template name. this way you can implement whatever interpolation method you want in a library.

https://github.com/adamdruppe/interpolation-examples/blob/master/01-basics.d

I'll add more examples to that repo as I have time, but this implementation allows libraries to do whatever methods they want.

October 21

On Saturday, 21 October 2023 at 18:14:55 UTC, Patrick Schluter wrote:

>

On Saturday, 21 October 2023 at 12:38:52 UTC, Commander Zot wrote:

>

[...]

Interpolated strings, even if they look like it, are NOT strings. They are a obfuscated or better said, conveniently laid out source code.

They contain inside of them, between the {} program code even if it is just a variable name. Strings are strictly just data. Interpolated string is a mix of CODE and data.

By the very nature of what interpolated strings are it is not possible to treat them as strings.

In C# an interpolated string is just a string

October 21

On Saturday, 21 October 2023 at 18:31:10 UTC, Imperatorn wrote:

>

In C# an interpolated string is just a string

This isn't true. It is an object that can convert to string (similar to D's alias toString this;)

October 21

On Saturday, 21 October 2023 at 18:59:13 UTC, Adam D Ruppe wrote:

>

On Saturday, 21 October 2023 at 18:31:10 UTC, Imperatorn wrote:

>

In C# an interpolated string is just a string

This isn't true. It is an object that can convert to string (similar to D's alias toString this;)

Yes, but it's implied is what I meant

October 21

On Saturday, 21 October 2023 at 19:07:07 UTC, Imperatorn wrote:

>

On Saturday, 21 October 2023 at 18:59:13 UTC, Adam D Ruppe wrote:

>

On Saturday, 21 October 2023 at 18:31:10 UTC, Imperatorn wrote:

>

In C# an interpolated string is just a string

This isn't true. It is an object that can convert to string (similar to D's alias toString this;)

Yes, but it's implied is what I meant

ie

		string name = "Johan";
		int age = 37;
		string s = $"Hello {name}, you are {age} years old";
		
		Console.WriteLine(s);

Would output Hello Johan, you are 37 years old.

October 21

On Saturday, 21 October 2023 at 18:25:22 UTC, Adam D Ruppe wrote:

>

On Saturday, 21 October 2023 at 15:59:06 UTC, duckchess wrote:

>

can we just lower ___"" into mixin(___!""), where ___ can be any template name. this way you can implement whatever interpolation method you want in a library.

https://github.com/adamdruppe/interpolation-examples/blob/master/01-basics.d

I'll add more examples to that repo as I have time, but this implementation allows libraries to do whatever methods they want.

I understand your proposal, and YADIP is better than DIP1037 imho. but it's adding a special case to the compiler and makes string result = i"$name! See that DIP $dipNumber is easy to convert to string.".text; marginally better to write than what we can do today to have the exact same outcome string result = mixin(i!"$name! See that DIP $dipNumber is easy to convert to string."); where i would be a mixin template capturing the surrounding variables and returning an interpolated string.

if we just lower ___"" into mixin(___!""), we can write

import std.sinterp : i;
string s = i"$name! See that DIP $dipNumber is easy to convert to string.";

or

import std.sqlinterp : sql;
sqlstring s = sql"$name! See that DIP $dipNumber is easy to convert to string.";

and if there's no matching template, then we get a normal "i not found, did you forget to include std.sinterp?" error message.

there would be no need for the compiler to even know what string interpolation is. we'd have 'mixin strings'™.

October 21

On Saturday, 21 October 2023 at 18:25:22 UTC, Adam D Ruppe wrote:

>

On Saturday, 21 October 2023 at 15:59:06 UTC, duckchess wrote:

>

can we just lower ___"" into mixin(___!""), where ___ can be any template name. this way you can implement whatever interpolation method you want in a library.

https://github.com/adamdruppe/interpolation-examples/blob/master/01-basics.d

I'll add more examples to that repo as I have time, but this implementation allows libraries to do whatever methods they want.

here's a better example of what i suggest:

https://run.dlang.io/is/n121Ph

October 21

On Saturday, 21 October 2023 at 20:58:44 UTC, duckchess wrote:

>

On Saturday, 21 October 2023 at 18:25:22 UTC, Adam D Ruppe wrote:

>

On Saturday, 21 October 2023 at 15:59:06 UTC, duckchess wrote:

>

can we just lower ___"" into mixin(___!""), where ___ can be any template name. this way you can implement whatever interpolation method you want in a library.

https://github.com/adamdruppe/interpolation-examples/blob/master/01-basics.d

I'll add more examples to that repo as I have time, but this implementation allows libraries to do whatever methods they want.

here's a better example of what i suggest:

https://run.dlang.io/is/n121Ph

Agreed. We need a better/simpler way to get the string from the expression without special syntax.

Like basically all other languages

October 22
On 21/10/23 19:10, Walter Bright wrote:
> For DIP1027,
> 
> |int var = 67; auto s = format(i"whatever $var"); |
> 
> would be equivalent to:
> 
> |auto s = "whatever 67";|

At which point it's barely an improvement overs what we can already do:

```
int var = 67; auto s = mixin(i!"whatever $var");
```

I'm not saving even one keypress, and readability isn't that much better either.

And we'll end up with multiple string literals, like `r"` and `q"`, and then something called "interpolated string" that uses a very similar token `i"` but that can't be used as a string, not even in the most straightforward cases.

Don't you think this will be unnecessarily confusing for users?

That's why I prefer DIP1036 over DIP1027, or even YAIDIP.

I understand that you don't want to make it implicitly convertible to strings. Fair enough, I'm sure there are solid reasons for that. But please, in that case, don't call it a "string", and also don't give it a string-like syntax.

Perhaps "interpolated sequence" with a clearly differentiated syntax? That would describe the feature much better.