October 19, 2023
On Thursday, 19 October 2023 at 07:45:44 UTC, Walter Bright wrote:
> On 10/18/2023 6:42 PM, monkyyy wrote:
>> I would think its nonlinear and you could easily justify 90 -> 95% being 2x the complexity cost
>
> For another example, the iphone camera pretty much destroyed the market for standalone cameras other than special purpose ones.

I didn't misunderstand you I disagree with your numbers and what they implied you were thinking about the tradeoff space.

The difference between 90% and 95%, isn't *linear*, 0-1 probalitys are an s-curve, and 90% means it breaks 1 out of 10, 95% means it breaks 1 out of 20, 99% means it breaks 1 out of 100. etc.

Given a complexity increase of 2x going from 90% to 95% means on the user's end they will get 1/2 the number of headaches, so I would feel that's a good and realistic trade-off. By all means don't chase 100%, but 95,97,99% different story.
October 19, 2023
On 10/19/2023 3:40 AM, Andrea Fontana wrote:
> // Example
> deleteFiles("/tmp/test.txt", "/tmp/old.txt");
> deleteFiles(i"/tmp/$dirname/$file"); <-- ooops this will be expanded?


It will be:

```
deleteFiles("/tmp/%s/%s", dirname, file);
```

And you'll probably get a message like:

"Could not find /tmp/%s/%s"


October 19, 2023
On 10/19/2023 4:10 AM, Richard (Rikki) Andrew Cattermole wrote:
> Don't worry about it, it has already been rejected and this was one of the reasons why.
> 
> https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md#final-review

It doesn't give that as a reason.
October 20, 2023

On Thursday, 19 October 2023 at 23:45:19 UTC, Walter Bright wrote:

>

On 10/19/2023 3:40 AM, Andrea Fontana wrote:

>

// Example
deleteFiles("/tmp/test.txt", "/tmp/old.txt");
deleteFiles(i"/tmp/$dirname/$file"); <-- ooops this will be expanded?

It will be:

deleteFiles("/tmp/%s/%s", dirname, file);

And you'll probably get a message like:

"Could not find /tmp/%s/%s"

You might get a message like:

Could not find `/tmp/%s/%s`
successfully removed directory and all files under `importantApp`
Could not find `tempfile.cache`

The point is that it's too easy to match to strings, compile, and do a completely unexpected thing. And yes, that's the major reason why 1027 is so bad.

-Steve

October 20, 2023
On 10/18/2023 7:47 PM, Adam D Ruppe wrote:
>> I'd like to see an example of code of how this customization might work, because I don't see it.
> 
> 
> Element makeHtmlFromTemplate(T...)(T t) if(T.length && is(T[0] == core.interpolation.InterpolationHeader!Parts, Parts...)) {
>      string html;
>      foreach(idx, str; Parts) {
>        if(idx % 2 == 0)
>          html ~= str; // i know this is html string literal thanks to noramlization
>        else
>         // note i also know what code this came from in case i need it for error messages, debug info, etc, it is in `str`
>          html ~= htmlEntitiesEncode(to!string(t[idx / 2]));
>      }
> 
>      return Element.make(Html(html));
> }
> 
> 
> auto element = makeHtmlFromTemplate(i`
>     <html>
>        <p class="foo" title="$(title)">
>             $(content)
>        </p>
>     </html>
> `);

Thanks for the example. I thought I'd show the equivalent with DIP1027. It's a bit crude, and I didn't bother with the details of html generation, but this shows the method and can be compiled and run:

```
import std.conv;

string makeHtmlFromTemplate(Parts...)(const char[] fmt, Parts parts)
{
    string html;
    size_t i;

    void advance()
    {
        while (i < fmt.length)
        {
            if (fmt[i] == '%' && i + 1 < fmt.length && fmt[i + 1] == 's')
            {
                i += 2;
                return;
            }
            html ~= fmt[i];
            ++i;
        }
    }

    advance();
    foreach (part; parts)
    {
        html ~= to!string(part); // or htmlEntityEncode
        advance();
    }
    return html;
}

void main()
{
    import std.stdio;
    string abc = "def";
    string html = makeHtmlFromTemplate("format %s %s sss", abc, 73);
         // tuple generated by DIP1027 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         // from i"format $abc $(73) sss"
    writeln(html);
}
```
which prints:

format def 73 sss

This code can be adapted to do whatever output schema one wants. Compare the tuple generated by DIP1027:

```
tuple("format %s %s sss", abc, 73)
```
and with YAIDIP:
```
tuple(.object.imported!"core.interpolation".InterpolationHeader!("", "format ", "", abc, "", 73, "", " sss", ""), "", "format ", "", abc, "", 73, "", " sss", "")
```
October 20, 2023
On Friday, 20 October 2023 at 07:14:45 UTC, Walter Bright wrote:
> On 10/18/2023 7:47 PM, Adam D Ruppe wrote:
>> [...]
>
> Thanks for the example. I thought I'd show the equivalent with DIP1027. It's a bit crude, and I didn't bother with the details of html generation, but this shows the method and can be compiled and run:
>
> ```
> import std.conv;
>
> string makeHtmlFromTemplate(Parts...)(const char[] fmt, Parts parts)
> {
>     string html;
>     size_t i;
>
>     void advance()
>     {
>         while (i < fmt.length)
>         {
>             if (fmt[i] == '%' && i + 1 < fmt.length && fmt[i + 1] == 's')
>             {
>                 i += 2;
>                 return;
>             }
>             html ~= fmt[i];
>             ++i;
>         }
>     }
>
>     advance();
>     foreach (part; parts)
>     {
>         html ~= to!string(part); // or htmlEntityEncode
>         advance();
>     }
>     return html;
> }
>
> void main()
> {
>     import std.stdio;
>     string abc = "def";
>     string html = makeHtmlFromTemplate("format %s %s sss", abc, 73);
>          // tuple generated by DIP1027 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>          // from i"format $abc $(73) sss"
>     writeln(html);
> }
> ```
> which prints:
>
> format def 73 sss
>
> This code can be adapted to do whatever output schema one wants. Compare the tuple generated by DIP1027:
>
> ```
> tuple("format %s %s sss", abc, 73)
> ```
> and with YAIDIP:
> ```
> tuple(.object.imported!"core.interpolation".InterpolationHeader!("", "format ", "", abc, "", 73, "", " sss", ""), "", "format ", "", abc, "", 73, "", " sss", "")
> ```


Whatever happens, can we please either merge the new dip or your dip?

Please?

Whatever dip is the simplest and performs the best should win.

Just so we get somewhere. The community is begging you all to settle for something.

Maybe a "winner" could be chosen emperically instead?

Write some examples and run.

Measure the performance. Fastest that is also currect wins.

Easy 😍
October 20, 2023
On 10/19/2023 6:52 PM, Steven Schveighoffer wrote:
> The point is that it's too easy to match to strings, compile, and do a completely unexpected thing. And yes, that's the major reason why 1027 is so bad.

I don't recall this issue even being discussed in the old review of it. It isn't listed in the review objections for DIP1027.

https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md#description

If you can point the discussion out to me, I'd appreciate it.

But I undestand you don't like this, and there is a rather nice solution. Recall Andrea Fontana's example:

```
void deleteFiles(string[]... files) { ... }
```

As a special case, an i-string will not be a match for `string[]...`. This makes sense, as a function requiring a format string would not be expecting no string. A match would have to be of the form:

```
void deleteFiles(string fmt, ...) { ... }
```

which is the natural form a formatting function would take. If the user wanted to use i-strings to pass to `deleteFiles(string[]...)`, he'd use:

```
string dirname = "project";
string file = "main.o";
deleteFiles(format(i"/tmp/$dirname/$file"));
```

which looks rather nice and self-evident. Hope you like it!


October 20, 2023
On Friday, 20 October 2023 at 07:14:45 UTC, Walter Bright wrote:

>
> ```
> tuple("format %s %s sss", abc, 73)
> ```

This requires cumbersome workarounds for the format string to be accessible at compile time:

alias tmp = i"format %s %s sss";
string html = makeHtmlFromTemplate!(tmp[0])(tmp[1..$]);

The simple tuple approach could work in Zig - they have "comptime" for partial evaluation (D's old 'static' function parameters plan put into practice).


October 20, 2023
On Friday, 20 October 2023 at 08:26:35 UTC, Max Samukha wrote:
> On Friday, 20 October 2023 at 07:14:45 UTC, Walter Bright wrote:
>
>>
>> ```
>> tuple("format %s %s sss", abc, 73)
>> ```
>
> This requires cumbersome workarounds for the format string to be accessible at compile time:
>
> alias tmp = i"format %s %s sss";
> string html = makeHtmlFromTemplate!(tmp[0])(tmp[1..$]);
>
> The simple tuple approach could work in Zig - they have "comptime" for partial evaluation (D's old 'static' function parameters plan put into practice).

I didn't know about that old "'static' function parameters", what was that?
October 20, 2023
On Friday, 20 October 2023 at 09:43:47 UTC, Imperatorn wrote:

>
> I didn't know about that old "'static' function parameters", what was that?

`void foo(static T t);`