简体   繁体   中英

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.

Thanks.

您没有向我们显示代码,所以我无法确切说明什么是正确的解决方案,但是您可以尝试使用findall/3bagof/3谓词来收集列表中的结果,然后将所有结果求和。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM