OMG, it’s not the result, it’s just SWI printing stuff as it moves along the search tree :). Try it without ‘fail’ and check out the 6 models you get.

Please log in or register to post a reply.

@Mihail121

First of all, thanks for your reply :)

I realize it’s just printing stuff as it moves along. However, the way it reaches things is beyond my understanding. Namely, when it reaches the single “4” instead of “2, 4”. Any explanation of this?

It’s very logical though. There are two go’s, one with a single a(X), and one with an a(X) followed by a b(Y).

So the first two digits, 1 and 2, are simply all combinations that can be made with a. The following digits, 134234, are from the second go, which are all combinations with a and b combined. First it combines a(1) with b(Y), resulting in 134, then it does the same for a(2), resulting in 234.

@.oisyn

The following digits, 134234, are from the second go, which are all combinations with a and b combined. First it combines a(1) with b(Y), resulting in 134, then it does the same for a(2), resulting in 234.

Would this not work in the manner of “13”, followed by “24”? This is the approach I imagine it should have taken. I apparently misunderstand something in the way prolog processes these

*every* a(X), it needs to check *every*
b(Y)

- Upcoming Multiplatform Game Program...
- Our first game - looking for feedbacks
- Network Emulation Tool
- Trouble with accessing GLSL array
- Fiction
- Game Programming Patterns: Bytecode
- Interactive WebGL Water Demo
- Skeletal Animation Tutorial with GP...
- Unreal Engine 4
- Microsoft xbox one selling poorly

The fail predicate seems a bit unpredictable under certain cases to me. Take the following example.

Code:

a(1).

a(2).

b(3).

b(4).

go:- a(X), write(X).

go:- a(X), write(X), b(Y), write(Y).

Query this with ?- go, fail.

The result is 12134234. How does this make sense? Can somebody explain the logic behind that? Thanks.