我想知道是否有人设法使用'列表'。在JPL中命令检查Prolog知识库的内容? JPL要求您构造查询并根据您在查询中设置的变量返回解决方案。例如(Java):
Query q = new Query("holdsAt((X,Y) = true, 3)");
while ( q.hasMoreSolutions() ){
Hashtable s = q.nextSolution();
System.out.println(s.get("X")+", "+s.get("Y"));
}
我看不出这对list / 0,甚至是需要实例化输入的列表/ 1是如何工作的。目前我正在使用表格代码
predicate_property(L,interpreted),
\+ predicate_property(L, built_in),
\+ predicate_property(L,imported_from(_)),
current_predicate( X, L), current_predicate(X/Z).
返回知识库中存在的函数:
myFunction:-
myGoal1,
myGoal2.
答案:
L = myFunction(_G403,_G404),
X = myFunction,
Z = 2
但这还不够,因为没有任何目标被归还。我想我需要什么(如果列表函数不能使用JPL调用),是一个函数,它作为变量返回谓词头以及必须满足的相关目标列表。不幸的是,我不熟悉列表功能的内部,所以我不知道该怎么做。
提前致谢
答案 0 :(得分:0)
我有一个暂时正常工作的功能,但我担心它的效率低于'上市'电话
getClauses(Y):-
predicate_property(L,interpreted),
\+ predicate_property(L, built_in),
\+ predicate_property(L,imported_from(_)),
current_predicate( X, L),
current_predicate(X/Z),
findall((L, T), clause(L, T), Y).
返回知识库中存在的谓词:
myPredicate:-
myGoal1,
myGoal2.
结果:
?- getClauses(Y).
Y = [ (myPredicate, myGoal1, myGoal2)]
请注意,这对从其他模块导入的谓词不起作用。