]]>Wow, that clears a LOT up. Thanks a bunch for your help!

]]>Note that I'm not a prolog guru whatsoever, but yes I think that's true . Which makes sense btw, because if it backtracked the whole searchtree up until the root, it has to start all over again.

]]>Oh! So does the fail predicate not make you start the whole rule over again? It solely checks for the last call and backtracks that?

]]>No, because there are four possible combinations: a(1)b(3), a(1)b(4), a(2)b(3) and a(2)b(4). So for

everya(X), it needs to checkeveryb(Y)

]]>@.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

]]>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.

]]>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.

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?

]]>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.

]]>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.