有可能在prolog中将列表作为事实吗



我是prolog的新手,想知道是否可以将列表作为事实,这样我就可以将其与if、and、then一起使用。例如:

list(a,b,c,d).
fact(x).
fact(y).
if x and y then list(a,b,c,d).

当然可以,但您所写的内容毫无意义。"Prolog程序"是一个含义列表X<=&amp;B,它确定您的查询返回的是false还是true(当您获得使查询true作为答案的变量的值时,是构造性的true(。因此,拥有if x and y then list(a,b,c,d)的想法并不符合这一点。。除非你想说之类的话

foo([a,b,c,d]).   % This is true! List [a,b,c,d] has attribute "foo"
bar(a).           % This is true! The atom a has attribute "bar"
baz(b).           % This is true! The atom b has attribute "baz"
% A value for X has attribute "solution" if:
% 1) It has attribute bar
% 2) It is a member of any list that has attribute "foo"
solution(X) :- bar(X),foo(List),member(X,List).
?- solution(X).

将给出CCD_ 6。

最新更新