Return elements list of list prologs [duplicate]

2019-08-23 07:25发布

This question already has an answer here:

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.

标签: list prolog head
1条回答
神经病院院长
2楼-- · 2019-08-23 07:56

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).
查看更多
登录 后发表回答