December 16, 2021

On Tuesday, 14 December 2021 at 21:06:19 UTC, Paul Backus wrote:

>

On Tuesday, 14 December 2021 at 20:07:43 UTC, Daniel N wrote:

>

On Tuesday, 14 December 2021 at 16:15:28 UTC, WebFreak001 wrote:

>
string name = readln();
auto greeting = text!(__header!..., "hello ", name, "!");

that wouldn't work because name is a runtime variable and you are trying to use it as a template parameter here.

I assumed it works with alias/variadic params...?

import std;

int sum(Vs...)()
{
    int sum = 0;

    foreach(v ; Vs)
        sum += v;

    return sum;
}

void main()
{
    int a = to!int(readln());
    sum!a.writeln;
}

It works for variables, but not arbitrary expressions. For example, if you wrote

    sum!(a, a+1).writeln;

...then you would get an error:

Error: variable `a` cannot be read at compile time

So passing a raw a should work (it's an alias parameter).

Passing a+1 obviously doesn't as it is not a value that can be computed at compile time. Which lead me to think, can't we generate some kind of struct on the fly for the "${}" syntax? That would solve the problem and the end result would be supperior to the i solution (in fact, it would allow to implement the i solution as a library).

December 16, 2021
On Thursday, 16 December 2021 at 13:19:16 UTC, deadalnix wrote:
> So passing a raw a should work (it's an alias parameter).

yeah

> Which lead me to think, can't we generate some kind of struct on the fly for the "${}" syntax?

I wrote about that back in 2019, indeed, at that point, it was my preference:
http://dpldocs.info/this-week-in-d/Blog.Posted_2019_05_13.html#my-string-interpolation-proposal

But it brings its own problems: this forces at least partial evaluation early which makes trouble with non-copyable types, breaks ref and aliases, and might be trouble tracking lifetime.

It is a solidly decent plan but not quite full D potential.

But like I've said before, all this stuff has been discussed to death. Some of us have been debating all this for years.
December 16, 2021
On Thursday, 16 December 2021 at 13:31:07 UTC, Adam D Ruppe wrote:
> On Thursday, 16 December 2021 at 13:19:16 UTC, deadalnix wrote:
>> So passing a raw a should work (it's an alias parameter).
>
> yeah
>
>> Which lead me to think, can't we generate some kind of struct on the fly for the "${}" syntax?
>
> I wrote about that back in 2019, indeed, at that point, it was my preference:
> http://dpldocs.info/this-week-in-d/Blog.Posted_2019_05_13.html#my-string-interpolation-proposal
>
> But it brings its own problems: this forces at least partial evaluation early which makes trouble with non-copyable types, breaks ref and aliases, and might be trouble tracking lifetime.
>
> It is a solidly decent plan but not quite full D potential.
>
> But like I've said before, all this stuff has been discussed to death. Some of us have been debating all this for years.

And nobody will ever agree, so we just have to somehow stick with one implementation or it'll never happen.
1 2 3 4 5
Next ›   Last »