我有以下形式的 Prolog 代码:
setof(Element,some_function(P,Element,C),Elements)
这样Element
解决方案中的术语的所有实例some_function
都收集在列表中Elements
。
我现在想改进这一点,只有当它在 list 上不存在时才会添加memberchk
term 的任何实例化。Element
Elements
List
我尝试了以下方法:
setof(Element,some_function(P,Element,C,List),Elements)
................
some_function(P,Element,C,List) :-
.... the function as it was ....,
\+ memberchk(Element,List).
这在只List
添加未打开的元素的意义上确实有效。但问题是,当 term 的所有实例都已经 onsetof
时,现在会失败。而我希望它返回一个空列表,但不会失败。Element
List
Elements
关于如何做到这一点的任何想法?谢谢!