如何总结序言中谓词的多个结果? [英] How to sum multiple results from a predicate in prolog?
本文介绍了如何总结序言中谓词的多个结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个谓词有时会返回多个数值结果,例如.
So I have a predicate that sometimes returns more than one numerical result, eg.
X=3;
X=1
如何将多个返回值相加?有时我的谓词返回一个单一的数值,这很好,但如果它返回多个,我希望它将多个结果相加并输出,而不是单独列出它们.
How can I sum multiple return values together? On occasion my predicate returns a single numerical value which is fine but if it returns more than one I want it to sum the multiple results together and output that rather than listing them separately.
谢谢.
推荐答案
您没有向我们展示代码,所以我无法确切说出正确的解决方案,但您可以尝试使用 findall/3
或 bagof/3
谓词收集列表中的结果,然后将它们相加.
You didnt show us code so i cant tell exactly what is correct solution, but you can try with findall/3
or bagof/3
predicates to collect results in list and then sum them all.
这篇关于如何总结序言中谓词的多个结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文