检查是否存在任何解决方案

Check if any solution exists

我在表单中有一些代码

plan([],_).
plan([ Item | RemainingItems ], Groups) :-
  doStuff(Groups, Item, UpdatedGroups),
  rulesObeyed(UpdatedGroups),
  plan(RemainingItems, UpdatedGroups).

doStuff 只有一棵可能的子树,但是 rulesObeyed 可以根据组的数量无限增长,因为可以通过多种方式遵守规则。 这导致该计划 returns 一遍又一遍地使用相同的解决方案。

有什么办法可以这样说

solution_exists(rulesObeyed(UpdatedGroups))

所以它没有考虑 rulesObeyed 的所有可能解决方案?

解决方案是使用 once/1 - 或 \+ \+ 作为错误发布。