在prolog中,是否可以将一个列表作为一个事实?

问题描述 投票:0回答:1

我是prolog的新手,想知道是否可以把一个列表作为一个事实,这样我就可以用if,and,then.For example.I am new to prolog an wanted to know if it is possible to have a list as a fact so I can use it with if, and, then.For example:

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

if x and y then list(a,b,c,d).
prolog
1个回答
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.

© www.soinside.com 2019 - 2024. All rights reserved.