October 13, 2023

On Friday, 13 October 2023 at 17:38:23 UTC, bachmeier wrote:

>

On Friday, 13 October 2023 at 15:34:59 UTC, kdevel wrote:

>

Your functions foo and bar both not only make calls to interp but they
also necessarily contain, in order to succeed, the name of the variable.

Yes

But then you can't re-use foo with another string, e.g.

"String needing interpolation to insert ${yold} and ${ynew}."
> >

Your approach creates more dependencies between unrelated components than necessary.

Then don't use it? The goal of programming is to get the right output.

Your code does not meet that requirement.

> >

How do you unittest foo and bar?

The same as any other function.

Having the signature of foo and bar alone I am not able to write a unittest.

> >

The dependencies can easily be avoided if foo and bar only returned the value of the computation, the results are stored in the AA given as subs in the call to interp.

I prefer less complicated code to code that imposes arbitrary restrictions.

In your code of foo and bar you have to assemble the AA and call interp twice compared to once. I would call my approach less complicated and my foo and bar versions do not suffer from the arbitrary restriction of beeing applicable only to strings having a predefined variable name.

October 13, 2023

On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:

> >

And reminder: How do you implement your interp function in terms of
DIP 1027's string interpolation?

I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.

Maybe I misunderstood you in "Again, though, this really should be done by the language rather than the user having to mess with it."

October 13, 2023
On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:
> I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.

dip 1027 was utter trash, but there's future good dips that would easily solve these things. pity D's leadership is so clueless and obstinate.
October 14, 2023
On Friday, 13 October 2023 at 18:24:08 UTC, Adam D Ruppe wrote:
> On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:
>> I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.
>
> dip 1027 was utter trash, but there's future good dips that would easily solve these things. pity D's leadership is so clueless and obstinate.

We just want to be able to do

string s = "Hello {name}, you are {age} years old and have {money - 42} dollars in the bank";

Is it too much to ask? 😭
October 14, 2023
On Saturday, 14 October 2023 at 06:25:15 UTC, Imperatorn wrote:
> On Friday, 13 October 2023 at 18:24:08 UTC, Adam D Ruppe wrote:
>> On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:
>>> I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.
>>
>> dip 1027 was utter trash, but there's future good dips that would easily solve these things. pity D's leadership is so clueless and obstinate.
>
> We just want to be able to do
>
> string s = "Hello {name}, you are {age} years old and have {money - 42} dollars in the bank";
>
> Is it too much to ask? 😭

yes. this would break existing code.
October 14, 2023
On Saturday, 14 October 2023 at 11:31:53 UTC, Commander Zot wrote:
> On Saturday, 14 October 2023 at 06:25:15 UTC, Imperatorn wrote:
>> On Friday, 13 October 2023 at 18:24:08 UTC, Adam D Ruppe wrote:
>>> On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:
>>>> I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.
>>>
>>> dip 1027 was utter trash, but there's future good dips that would easily solve these things. pity D's leadership is so clueless and obstinate.
>>
>> We just want to be able to do
>>
>> string s = "Hello {name}, you are {age} years old and have {money - 42} dollars in the bank";
>>
>> Is it too much to ask? 😭
>
> yes. this would break existing code.

Not with an interpolation character like $ in C#
October 14, 2023

On Saturday, 14 October 2023 at 06:25:15 UTC, Imperatorn wrote:

>

On Friday, 13 October 2023 at 18:24:08 UTC, Adam D Ruppe wrote:

>

On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:

>

I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.

dip 1027 was utter trash, but there's future good dips that would easily solve these things. pity D's leadership is so clueless and obstinate.

We just want to be able to do

string s = "Hello {name}, you are {age} years old and have {money - 42} dollars in the bank";

Is it too much to ask? 😭

Why does not this work for you?

string s = text("Hello ",name,", you are ",age," years old and have ",money - 42," dollars in the bank");
October 14, 2023

On Saturday, 14 October 2023 at 14:47:26 UTC, Andrey Zherikov wrote:

>

On Saturday, 14 October 2023 at 06:25:15 UTC, Imperatorn wrote:

>

On Friday, 13 October 2023 at 18:24:08 UTC, Adam D Ruppe wrote:

>

On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:

>

I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.

dip 1027 was utter trash, but there's future good dips that would easily solve these things. pity D's leadership is so clueless and obstinate.

We just want to be able to do

string s = "Hello {name}, you are {age} years old and have {money - 42} dollars in the bank";

Is it too much to ask? 😭

Why does not this work for you?

string s = text("Hello ",name,", you are ",age," years old and have ",money - 42," dollars in the bank");

Too many unnecessary quotes and commas, tedious to write and read. And for debug purpose I also want to print the variable names ...

string interpolation is nothing fancy, but just syntax sugar to make the life easier.
People have been asking it for years, but still not available.

So, why not just do it?

October 14, 2023

On Saturday, 14 October 2023 at 14:47:26 UTC, Andrey Zherikov wrote:

>

On Saturday, 14 October 2023 at 06:25:15 UTC, Imperatorn wrote:

>

On Friday, 13 October 2023 at 18:24:08 UTC, Adam D Ruppe wrote:

>

On Friday, 13 October 2023 at 17:31:29 UTC, bachmeier wrote:

>

I don't know, but I also don't know why I would want to, because DIP 1027 was not accepted.

dip 1027 was utter trash, but there's future good dips that would easily solve these things. pity D's leadership is so clueless and obstinate.

We just want to be able to do

string s = "Hello {name}, you are {age} years old and have {money - 42} dollars in the bank";

Is it too much to ask? 😭

Why does not this work for you?

string s = text("Hello ",name,", you are ",age," years old and have ",money - 42," dollars in the bank");

It's ok, but just nicer to do it as in C#

October 14, 2023

On Saturday, 14 October 2023 at 14:47:26 UTC, Andrey Zherikov wrote:

>

Why does not this work for you?

string s = text("Hello ",name,", you are ",age," years old and have ",money - 42," dollars in the bank");

We had a discussion on this a few years ago where someone said the same thing, but they had a missing space, and it wasn't immediately obvious. I'll sometimes create strings that are fed to the shell. Keeping the quoting straight is not the highlight of your day. That was probably the reason I rolled my own solution. text works for some things, but I find other approaches easier on the brain cells. I don't mind typing a few extra characters. I want to write it once and know I never have to think about it again.