[英]How to use evaluation in Prolog
I am very new to Prolog and I can't seem to wrap my mind around it. 我对Prolog还是很陌生,我似乎无法全神贯注于它。 I am trying to write a predicate that, given facts predefined about prerequisites for college, will be able to list all the prereqs in a list.
我正在尝试编写一个谓词,给定有关大学先决条件的事实,它将能够在列表中列出所有先决条件。
So far I have 到目前为止,我有
list_prereqs(Course, List) :-
prereqs(Course, List),
list_prereqs(List, A).
But this doesn't work. 但这是行不通的。 How do I use the answer that I get from prereqs in the recursive call?
如何使用从递归调用中的前提条件获得的答案? Or am I going about this all wrong?
还是我要解决所有这些错误?
How about findall/3
? findall/3
怎么样? Like this; 像这样;
list_prereqs(Prereqs) :-
findall(prereqs(Course, List), prereqs(Course, List), Prereqs).
Prereqs
above is unified to the list of all the prereqs. 上面的
Prereqs
已统一到所有前提条件的列表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.