How to sum multiple results from a predicate in prolog?

▼魔方 西西 提交于 2019-12-20 05:51:01

问题


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.

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/35867950/how-to-sum-multiple-results-from-a-predicate-in-prolog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!