开发者

How to make a list of lists in prolog

开发者 https://www.devze.com 2023-03-05 06:14 出处:网络
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

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

精彩评论

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