序言中是否可以列出事实?

时间:2020-04-22 17:01:00

标签: prolog

我是新来的人,想知道是否有可能列出事实,以便我可以将它与if和then一起使用。 例如:

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

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

1 个答案:

答案 0 :(得分:1)

可以,但是您写的东西毫无意义。 “ Prolog程序”是含义 X <= A&...&B 的列表,该列表确定您的哪些查询以falsetrue返回(当您获得使查询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).

将给出X=a

相关问题