开发者

How to make a list of lists in prolog

I use SWI-Prolog and I want to make a list of several other lists.

For example, I want to put the following three lists

[a,b,c]
[1,2]
[d]

into a larger one that looks like [[a,b,c],[1,2],[d]] .

divideList([]):-!.

divideList([Head|Tail]):-
    list_to_set开发者_如何学JAVA(Head,H),%H is a List 
    divideList(Tail).

I want to put all H in one list. How can I do this?


The problem is that you are not using H in your predicate to put the list you want

This should do it

divideList([], []):-!.
divideList([Head|Tail], [H|HTail]):-
    list_to_set(Head,H),%H is a List 
    divideList(Tail, HTail).

The second argument will have your list of lists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜