帮助Prolog列表 [英] Help With Prolog Lists

查看:56
本文介绍了帮助Prolog列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Prolog的新手,正在寻求帮助.我想做的基本上是从列表中获取一些列表,如果这有意义的话?大声笑

Im new to Prolog and was looking for some assistance. What i am trying to do is basically get the some of the list of list, if that makes sense? lol

我想要实现的是... sum([[1,2 ,, [3,4],[5,6]]).应该返回: 列表数:3 清单1 3 清单2 7 清单3 11 ....等

What i am trying to achieve is.... sum([ [1,2],[3,4],[5,6] ]). should return: Number Of Lists: 3 List 1 3 List 2 7 List 3 11....etc

我可以获得很简单的列表数,但是我不太确定如何遍历列表,然后为每个列表加个数.我使事情变得比实际复杂吗?哈哈!

I can get the Number of Lists which is fairly simple but im not quite sure how to loop through the List and then for each List add the number up. Am i making this more complicated than it actually is? lol!

如果有人可以帮助我或向我指出总体方向,那将是很好的.

If anyone can help me or point me in the general direction that would be great.

预先感谢

推荐答案

在SWI-Prolog中,您可以使用maplistsumlist;

In SWI-Prolog you can use maplist and sumlist;

?- maplist(sumlist, [[1,2], [3,4], [5,6]], Lengths).
Lengths = [3, 7, 11].

现在,您可以按照自己喜欢的方式漂亮地打印Lengths.

Now you can pretty-print Lengths the way you like.

要了解如何实现maplistsumlist,只需调用listing(maplist)listing(sumlist).

To learn how maplist and sumlist are implemented, just call listing(maplist) and listing(sumlist).

这篇关于帮助Prolog列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆