Return elements list of list prologs [duplicate]

穿精又带淫゛_ 提交于 2019-12-25 01:06:22

问题


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

That's my code:

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.

回答1:


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).


来源:https://stackoverflow.com/questions/50543473/return-elements-list-of-list-prologs

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