Re: Create a List of Lists
- From: Bill Spight <bspight@xxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 17:10:28 GMT
Dear Andrew,
I'm a bit confused how you would create a List of Lists from a bigger list.
e.g.
[a,b,c,d,e,f,g,h,i,j,k,l] goes to [ [a,b,c], [d,e,f], [g,h,i], [j,k,l] ]
My following effort doesn't work.
splitting([A,B,C|Tail],List2):-
append([A,B,C], List2, List3),
splitting(Tail,List3).
I have tried various different predicates instead of append/3 with no luck.
Is this approach fundamentally flawed?
Yes. append/3 merges two lists into a third, it does not make the first
two lists members of the third.
Here's a hint. Let's say that you want to makes lists with only one
member. Then the before list will look like this: [Head | Tail0] and the
second list will look like this: [[Head] | Tail]. You can express that
fact with this clause:
listify([Head | Tail0], [[Head] | Tail]) :-
listify(Tail0, Tail).
OC, for the full predicate you need to have a clause for the empty list.
Think in terms of before and after data structures.
Good luck!
Bill
.
- References:
- Create a List of Lists
- From: Andrew
- Create a List of Lists
- Prev by Date: Re: how to make a list
- Next by Date: Re: Replace occurrence of a list with another?
- Previous by thread: Create a List of Lists
- Next by thread: how stop the search in a data base?
- Index(es):
Relevant Pages
|
|