October 22
On 10/22/2023 4:32 AM, Arafel wrote:
> 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.

If you can make `i` work as a template, why not? I encourage you to give it a try and write the template!

I've already worked out the logic for this:

https://github.com/dlang/dmd/pull/15722/files#diff-a556a8e6917dd4042f541bdb19673f96940149ec3d416b0156af4d0e4cc5e4bdR14291

Feel free to turn it into a template, and let's see.
October 23
On 22/10/23 23:55, Steven Schveighoffer wrote:
> FWIW, that is something Adam opposed, but I insisted on. I did not think a String Interpolation DIP would be viable without it.

That's why I mentioned that he was a co-author, I guessed something like that might have happened. Still, he was asking for evidence when he had put his name to that, so at the very least he should be aware that it's a very common view.

FWIW, I fully agree with you that the primary objective of string interpolation should be building strings. I've been trying to find references, and everything I found online just _assumes_ that this is the case.

Of course if you can **also** do something else with that it's even cooler.

> 
> I still feel like one should be able to use an interpolation tuple as a string, but it's really hard to come up with a design that doesn't feel like a complete hack.

The problem is that it's inherently a high level feature. There's a reason why it first appeared and is even now still mostly used in interpreted languages.

Now, you want to embed it into the core of a language that tries to be minimalistic, so I understand that there are parts, for instance formatting numeric expressions, that doesn't really fit there.

But then you / the D leadership / the D Community should make a decision if we are to ever have this feature: either embed it into the language and bite the bullet, reusing for instance pragma msg's formatting routine, or extend the language so it can be implemented as a library.

I actually prefer the latter, and adding a shorthand for mixins might be a good solution, even if I also understand the preference for having mixins not too easy to use and clearly marked in the source code. Well, you can't have all, and as usual there are trade-offs.

> It's indeed much much simpler to just push that requirement to build a string if desired on the user.

Also, you (Adam, Walter, even you) are usually arguing form a library writer's perspective.

On the other hand, me, as a user of other people's libraries, will often need to deal with places that I have no control over, and that only expect strings, or even C interfaces that want a char*.

Sure, I can use `text` all the time, but this kind of removes most of the usefulness of the feature.

So I think any such feature needs to be exclusively, or at least mostly, a caller thing.

> -Steve
> 

October 23
On 23/10/23 3:13, Walter Bright wrote:
> On 10/22/2023 4:32 AM, Arafel wrote:
>> 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.
> 
> If you can make `i` work as a template, why not? I encourage you to give it a try and write the template!
> 
> I've already worked out the logic for this:
> 
> https://github.com/dlang/dmd/pull/15722/files#diff-a556a8e6917dd4042f541bdb19673f96940149ec3d416b0156af4d0e4cc5e4bdR14291
> 
> Feel free to turn it into a template, and let's see.

First of all, there are already dub projects that do this [1,2] for the simple case that I mentioned of getting a string as end result.

But if you want the same flexibility that your DIP offers, here is a small proof of concept of how you can get a tuple to be used in an "-f-" function with a mixin:

```d
import std;

enum i(string T) = "imported!\"std.meta\".AliasSeq!(\"%s: %s\",\"" ~ T ~ "\"," ~ T ~ ")";

void main() {
    int var = 5;
    writefln(mixin(i!"var"));
    // var: 5
}
```

This is a just to show that it **can** be done.

Implementing advanced parsing logic that generates whatever AliasSeq you want based on the input string instead of hardcoding it assuming it's just a variable name shouldn't be conceptually hard, especially not if it already exists, just perhaps tedious.

[1]: https://code.dlang.org/packages/stri
[2]: https://code.dlang.org/packages/jdiutil
October 23
On 23/10/23 10:28, Arafel wrote:
> Implementing advanced parsing logic that generates whatever AliasSeq you want based on the input string instead of hardcoding it assuming it's just a variable name shouldn't be conceptually hard, especially not if it already exists, just perhaps tedious.

Just a slightly more advanced version even with introspection and a dynamic format string... and even expressions!

Supporting expressions in aliases is a PITA, but it can be done with a bit of imagination. A delegate literal returning a voldemort struct would probably would work as well:

```d
enum i(string expr) =
    "new class(" ~ expr ~ ") {\n" ~
    "    alias _T = typeof(" ~ expr ~ ");\n" ~
    "    _T _v;\n" ~
    "        this(_T _v) {\n" ~
    "            this._v = _v;\n" ~
    "    }\n" ~
    "    static if (is(_T : int)) {\n" ~
    "        enum formatString =  \"%s (detected integer): %d\";\n" ~
    "    } else static if (is(_T : double)) {\n" ~
    "        enum formatString = \"%s (detected double): %f\";\n" ~
    "    } else {\n" ~
    "        enum formatString = \"%s (default: \" ~ _T.stringof ~ \"): %s\";\n" ~
    "    }\n" ~
    "    alias _seq =  imported!\"std.meta\".AliasSeq!(formatString,\"" ~ expr ~ "\",_v);\n " ~
    "}._seq";

void main() {
    import std.stdio : writefln;
    import std.math : sqrt;

    int a = 5;

    writefln(mixin(i!"a + 10"));
    // a + 10 (detected integer): 15
    writefln(mixin(i!"sqrt(5.0) / 2"));
    // sqrt(5.0) / 2 (detected double): 1.118034
    string b = "5";
    writefln(mixin(i!"b"));
    // b (default: string): 5
}

```

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

You can obviously do whatever you need with the input string.
October 23

On Monday, 23 October 2023 at 10:45:45 UTC, Arafel wrote:

>

On 23/10/23 10:28, Arafel wrote:

>

Implementing advanced parsing logic that generates whatever AliasSeq you want based on the input string instead of hardcoding it assuming it's just a variable name shouldn't be conceptually hard, especially not if it already exists, just perhaps tedious.

Just a quick comment. When posting code, be sure to check the "Enable Markdown" checkbox to the right of the send button.

If you did, your code would look like this:

enum i(string expr) =
    "new class(" ~ expr ~ ") {\n" ~
    "    alias _T = typeof(" ~ expr ~ ");\n" ~
    "    _T _v;\n" ~
    "        this(_T _v) {\n" ~
    "            this._v = _v;\n" ~
    "    }\n" ~
    "    static if (is(_T : int)) {\n" ~
    "        enum formatString =  \"%s (detected integer): %d\";\n" ~
    "    } else static if (is(_T : double)) {\n" ~
    "        enum formatString = \"%s (detected double): %f\";\n" ~
    "    } else {\n" ~
    "        enum formatString = \"%s (default: \" ~ _T.stringof ~ \"): %s\";\n" ~
    "    }\n" ~
    "    alias _seq =  imported!\"std.meta\".AliasSeq!(formatString,\"" ~ expr ~ "\",_v);\n " ~
    "}._seq";

void main() {
    import std.stdio : writefln;
    import std.math : sqrt;

    int a = 5;

    writefln(mixin(i!"a + 10"));
    // a + 10 (detected integer): 15
    writefln(mixin(i!"sqrt(5.0) / 2"));
    // sqrt(5.0) / 2 (detected double): 1.118034
    string b = "5";
    writefln(mixin(i!"b"));
    // b (default: string): 5
}
October 23
On 23/10/23 13:47, Imperatorn wrote:
> Just a quick comment. When posting code, be sure to check the "Enable Markdown" checkbox to the right of the send button.

Unfortunately I use Thunderbird and the newsgroup, not the web interface, so I'm not sure how I can enable markdown there. If anybody knows (perhaps adding a header or something?) I would be glad to do it.

Alternatively, wouldn't it make sense to enable it by default so it would apply to all the messages coming from email / the newsgroup?
October 23
On Monday, 23 October 2023 at 12:03:04 UTC, Arafel wrote:
> On 23/10/23 13:47, Imperatorn wrote:
>> Just a quick comment. When posting code, be sure to check the "Enable Markdown" checkbox to the right of the send button.
>
> Unfortunately I use Thunderbird and the newsgroup, not the web interface, so I'm not sure how I can enable markdown there. If anybody knows (perhaps adding a header or something?) I would be glad to do it.

Oh, I see.

> Alternatively, wouldn't it make sense to enable it by default so it would apply to all the messages coming from email / the newsgroup?

Fair point

October 23

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;)

In fact neither, it's syntactic sugar.

int count = 10;
string s = $"I drink {count} beers";

is syntactic sugar for:

int count = 10;
DefaultInterpolationHandler dh = new DefaultInterpolationHandler();
dh.AppendLiteral("I drink ");
dh.AppendFormatted(count);
dh.AppendLiteral(" beers");
string s = dh.ToStringAndClear();

From compiler point of view, Roslyn stores in AST a interpolated string as an array of expressions which get converted before IL compilation to the code above.

October 23
On Monday, 23 October 2023 at 14:12:25 UTC, Rumbu 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;`)
>
> In fact neither, it's syntactic sugar.
>
> ```csharp
> int count = 10;
> string s = $"I drink {count} beers";
> ```
>
> is syntactic sugar for:
> ...

Maybe we're talking about the same thing or it changed, but I thought it was a syntactic sugar for string.format():

https://web.archive.org/web/20160304034509/https://roslyn.codeplex.com/discussions/570614

Matheus.
October 23

On Monday, 23 October 2023 at 14:12:25 UTC, Rumbu 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

Correct. But what I was trying to communicate it that it gives you a string by default.