0

我有以下形式的 Prolog 代码:

setof(Element,some_function(P,Element,C),Elements)

这样Element解决方案中的术语的所有实例some_function都收集在列表中Elements

我现在想改进这一点,只有当它在 list 上不存在时才会添加memberchkterm 的任何实例化。ElementElementsList

我尝试了以下方法:

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时,现在会失败。而我希望它返回一个空列表,但不会失败。ElementListElements

关于如何做到这一点的任何想法?谢谢!

4

0 回答 0