0

I am new in Prolog and wanted to learn it. I have been trying to create a list while iterating facts but list that was created one step back refreshing and lost the data. How can I keep the data and add elements to list?

funct(a,b,1).
funct(b,c,2).
funct(b,d,3).

creatingList(X,Y,R):- funct(X,Y,A), funct(Y,Z,B), \+member(B,R) , append(R,B,R).

I tried that , but when I trace it keeps losing data, which I expect is R = [1,2,3].

4

1 回答 1

3

@User 是正确的:

?- findall(funct(X,Y,Z), funct(X,Y,Z), Functs).
Functs = [funct(a, b, 1), funct(b, c, 2), funct(b, d, 3)].

setof/3并且bagof/3可能也适用,但它们的语义有点复杂。

于 2013-04-17T14:11:27.597 回答