How to sum multiple results from a predicate in pr

2019-03-03 22:27发布

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.

标签: prolog
1条回答
唯我独甜
2楼-- · 2019-03-03 22:54

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.

查看更多
登录 后发表回答