digitalmars.D.learn - substitute with predicate won't compile
- Bastiaan Veelo (16/16) Oct 28 Why doesn't this compile?
- H. S. Teoh (8/24) Oct 28 You have all your arguments as CT arguments; I think .substitute wants
- Bastiaan Veelo (12/39) Oct 28 This seems to be a bug. It does work with runtime arguments, but
- H. S. Teoh (7/16) Oct 28 [...]
- Dukc (11/22) Oct 29 Yes, I tried this and it seems to be the case. My error:
Why doesn't this compile?
```d
import std;
void main()
{
string s;
//...
s = s.substitute!((a, b) => sicmp(a, b) == 0, "&", "&",
"<", "<",
">", ">",
""", `"`,
"'",
"'").array;
}
```
-- Bastiaan.
Oct 28
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, "&", "&",
"<", "<",
">", ">",
""", `"`,
"'", "'").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
Oct 28
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: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"("&", "&", "<", "<", ">", ">", """, `"`, "'", "'").to!string; ``` -- Bastiaan.Why doesn't this compile? ```d import std; void main() { string s; //... s = s.substitute!((a, b) => sicmp(a, b) == 0, "&", "&", "<", "<", ">", ">", """, `"`, "'", "'").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
Oct 28
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"("&", "&",
"<", "<",
">", ">",
""", `"`,
"'", "'").to!string;
```
[...]
Hmm. Probably a bug then!
T
--
What do you get if you throw a grenade into a French kitchen? Linoleum blown
apart.
Oct 28
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:
```d
s = s.substitute!"a.toLower==b.toLower"("&", "&",
"<", "<",
">", ">",
""", `"`,
"'",
"'").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/algorith
/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/algorith
/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.
Oct 29









"H. S. Teoh" <hsteoh qfbox.info> 