Thread overview
substitute with predicate won't compile
3 days ago
Bastiaan Veelo
3 days ago
H. S. Teoh
3 days ago
Bastiaan Veelo
3 days ago
H. S. Teoh
2 days ago
Dukc
3 days ago

Why doesn't this compile?

import std;

void main()
{
    string s;
    //...
    s = s.substitute!((a, b) => sicmp(a, b) == 0, "&", "&",
                                                  "&lt;", "<",
                                                  "&gt;", ">",
                                                  "&quot;", `"`,
                                                  "&apos;", "'").array;
}

-- Bastiaan.

3 days ago
On Tue, Oct 28, 2025 at 07:43:56PM +0000, Bastiaan Veelo via Digitalmars-d-learn wrote:
> Why doesn't this compile?
> 
> ```d
> import std;
> 
> void main()
> {
>     string s;
>     //...
>     s = s.substitute!((a, b) => sicmp(a, b) == 0, "&amp;", "&",
>                                                   "&lt;", "<",
>                                                   "&gt;", ">",
>                                                   "&quot;", `"`,
>                                                   "&apos;", "'").array;
> }
> ```

You have all your arguments as CT arguments; I think .substitute wants the lamdba as a CT argument but the other arguments as RT.

But having said that, after changing the substitution arguments to RT arguments, it still doesn't compile for me for some reason.  So I dunno.


T

-- 
They say that "guns don't kill people, people kill people." Well I think the gun helps. If you just stood there and yelled BANG, I don't think you'd kill too many people. -- Eddie Izzard, Dressed to Kill
3 days ago

On Tuesday, 28 October 2025 at 20:08:41 UTC, H. S. Teoh wrote:

>

On Tue, Oct 28, 2025 at 07:43:56PM +0000, Bastiaan Veelo via Digitalmars-d-learn wrote:

>

Why doesn't this compile?

import std;

void main()
{
    string s;
    //...
    s = s.substitute!((a, b) => sicmp(a, b) == 0, "&amp;", "&",
                                                  "&lt;", "<",
                                                  "&gt;", ">",
                                                  "&quot;", `"`,
                                                  "&apos;", "'").array;
}

You have all your arguments as CT arguments; I think .substitute wants the lamdba as a CT argument but the other arguments as RT.

But having said that, after changing the substitution arguments to RT arguments, it still doesn't compile for me for some reason. So I dunno.

T

This seems to be a bug. It does work with runtime arguments, but only if the predicate is given as a string:

    s = s.substitute!"a.toLower==b.toLower"("&amp;", "&",
                                            "&lt;", "<",
                                            "&gt;", ">",
                                            "&quot;", `"`,
                                            "&apos;", "'").to!string;

-- Bastiaan.

3 days ago
On Tue, Oct 28, 2025 at 09:14:42PM +0000, Bastiaan Veelo via Digitalmars-d-learn wrote: [...]
> This seems to be a bug. It does work with runtime arguments, but only
> if the predicate is given as a string:
> ```d
>     s = s.substitute!"a.toLower==b.toLower"("&amp;", "&",
>                                             "&lt;", "<",
>                                             "&gt;", ">",
>                                             "&quot;", `"`,
>                                             "&apos;", "'").to!string;
> ```
[...]

Hmm. Probably a bug then!


T

-- 
What do you get if you throw a grenade into a French kitchen?  Linoleum blown apart.
2 days ago

On Tuesday, 28 October 2025 at 21:14:42 UTC, Bastiaan Veelo wrote:

>

This seems to be a bug. It does work with runtime arguments, but only if the predicate is given as a string:

    s = s.substitute!"a.toLower==b.toLower"("&amp;", "&",
                                            "&lt;", "<",
                                            "&gt;", ">",
                                            "&quot;", `"`,
                                            "&apos;", "'").to!string;

-- Bastiaan.

Yes, I tried this and it seems to be the case. My error:

/nix/store/inkxb5vqy7agpm0wzqk07ha9a9llnfd2-dmd-2.107.1/include/dmd/std/algorithm/iteration.d(6953): Error: function `app.main.substitute!((a, b) => a == b, string, string, string, string, string, string, string, string, string, string, string).substitute.SubstituteSplitter.popFront` cannot access function `find` in frame of function `D main`
/nix/store/inkxb5vqy7agpm0wzqk07ha9a9llnfd2-dmd-2.107.1/include/dmd/std/algorithm/searching.d(2388):        `find` declared here
app.d(8): Error: template instance `app.main.substitute!((a, b) => a == b, string, string, string, string, string, string, string, string, string, string, string)` error instantiating

I believe it means substitute is not correctly taking context pointers into account.