列表序言的返回元素列表 [英] Return elements list of list prologs

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

问题描述

如何在Prolog中返回列表列表的所有元素:

How to return all the elements of a list of lists in Prolog:

那是我的代码:

treturn_list_members([[Head|_]|Lists], Head).
treturn_list_members([[_|T]|Lists], Head):- return_list_members([T|Lists], Head).

执行时,它仅返回第一个列表的元素.

When I execute, it only return the elem of the first list.

?- treturn_list_members([[12,3],[45,6],[11,90]],L).
L = 12 ;
L = 3 ;
false.

推荐答案

宁可使用更好的名称. 返回"意味着您可以操作此关系.但是只要说出参数是什么,就足够了:

Rather use a better name. "Returning" means that you operationalize this relation. But it suffices to say what the arguments are:

listoflist_member(Xss, X) :-
   member(Xs, Xss),
   member(X, Xs).

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

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