Swipl-wasm seems to lose last solution to a predicate

I’m using the latest version of swipl-wasm in a js project. I can load a prolog file, containing:

p(a).
p(b).
p(c).

into the prolog engine, then from the js side, I can query:

for (const a of swipl.prolog.query('p(X)')) {
  console.log(a.X);
}

and this returns, in the console:

a
b

It seems that the last solution isn’t reached (I tried also with other predicates). Can you reproduce this? Do you have any idea what this could be due to?

@jan for context

Interestingly,

console.log(prolog.query('findall(X, p(X), All)').once().All);

correctly prints:

Array(3) [ "a", "b", "c" ]

Thanks. There was a bug in the iterator implementation :frowning: Pushed a fix and updated SWI-Prolog WASM tests

1 Like

Thank you for the immediate fix @jan. Given that it is a fairly serious bug, could we hope in another release on npm of the swipl-wasm package soon?

@meditans, the npm package is maintained by @jeswr. You might have to submit a PR to change the commit hash here: npm-swipl-wasm/package.json at d00e479244240ab302d2055223f8f083499766d7 · SWI-Prolog/npm-swipl-wasm · GitHub

Thank you for the info @rla, it seems then that we have to wait for the commit to be released in the swipl repo (for now it’s in swipl-devel) as npm-swipl-wasm depends on that.