# Swipl-wasm seems to lose last solution to a predicate

**URL:** <https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616>\
**Category:** Help!\
**Tags:** bug, wasm\
**Created:** [November 19, 2024, 4:10pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616 "2024-11-19T16:10:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![meditans](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/meditans/32/1768_2.png) [@meditans](https://swi-prolog.discourse.group/u/meditans)\
**Post date:** [November 19, 2024, 4:10pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/1 "2024-11-19T16:10:54Z")

</div>

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

```prolog
p(a).
p(b).
p(c).

```

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

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

```

and this returns, in the console:

```prolog
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

---

<div class="post-metadata">

**Author:** ![meditans](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/meditans/32/1768_2.png) [@meditans](https://swi-prolog.discourse.group/u/meditans)\
**Post date:** [November 19, 2024, 4:15pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/2 "2024-11-19T16:15:52Z")

</div>

Interestingly,

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

```

correctly prints:

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

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 20, 2024, 9:33am UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/3 "2024-11-20T09:33:50Z")

</div>

Thanks. There was a bug in the iterator implementation ☹ Pushed a fix and updated [SWI-Prolog WASM tests](https://wasm.swi-prolog.org/wasm/test)

---

<div class="post-metadata">

**Author:** ![meditans](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/meditans/32/1768_2.png) [@meditans](https://swi-prolog.discourse.group/u/meditans)\
**Post date:** [November 20, 2024, 2:53pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/4 "2024-11-20T14:53:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rla](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/rla/32/6863_2.png) [@rla](https://swi-prolog.discourse.group/u/rla)\
**Post date:** [November 20, 2024, 4:58pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/5 "2024-11-20T16:58:43Z")

</div>

@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](https://github.com/SWI-Prolog/npm-swipl-wasm/blob/d00e479244240ab302d2055223f8f083499766d7/package.json#L80)

---

<div class="post-metadata">

**Author:** ![meditans](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/meditans/32/1768_2.png) [@meditans](https://swi-prolog.discourse.group/u/meditans)\
**Post date:** [November 20, 2024, 6:21pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/6 "2024-11-20T18:21:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![meditans](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/meditans/32/1768_2.png) [@meditans](https://swi-prolog.discourse.group/u/meditans)\
**Post date:** [December 2, 2024, 1:47pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/7 "2024-12-02T13:47:16Z")

</div>

Actually, without particular hurry @jan, do you have any idea on when we could have a release of swi-prolog (that will be picked up by the npm package) containing this feature?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 2, 2024, 2:04pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/8 "2024-12-02T14:04:13Z")

</div>

9.3.16 is being built right now. And, if I understood @jeswr correctly, the npm version was already updated to use the fixed non-release version.

---

<div class="post-metadata">

**Author:** ![meditans](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/meditans/32/1768_2.png) [@meditans](https://swi-prolog.discourse.group/u/meditans)\
**Post date:** [December 2, 2024, 5:11pm UTC](https://swi-prolog.discourse.group/t/swipl-wasm-seems-to-lose-last-solution-to-a-predicate/8616/9 "2024-12-02T17:11:43Z")

</div>

Thank you, I didn’t understand that the npm version was already out, but I see a new release now!
