Re: Create a List of Lists



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
.



Relevant Pages

  • RE: Cannot Add To Library
    ... no good, still lists same files. ... re-created...still no luck. ... the library and the WMDB files does not seem to help. ... cd "location of music directory" (with quotes ...
    (microsoft.public.windowsmedia.player)
  • Re: XP Files and Transfer Wiz Error
    ... comprehensive...and lists the exact error screen I am ... >FILE & SETTINGS TRANSFER WIZARD ... >| bad on the one I had been using, but no luck. ...
    (microsoft.public.windowsxp.setup_deployment)
  • Help with PROLOG predicates
    ... group could help me with writing the following predicates, ... PROLOG predicate I want to use is "member" otherwise I want to use recursion ... and returns the result in the third parameter. ... lists, contain the same elements but not necessarily in the same order. ...
    (comp.lang.prolog)
  • Re: Defragmenting XP Registry
    ... |> lists 5 benefits of which I only care about 2: ... |> data from the registry in a more efficient manner ... GOOD LUCK. ... |and then go about reviewing them by reading reviews, ...
    (microsoft.public.windowsxp.general)
  • Re: dividing list
    ... > And, to any one, please, could you explain me what means "preserving ... > order" in this context?. ... and, on its own, append/3 would generate too many solutions. ... numbers but keep the lists (by replacing each X in my second split/3 ...
    (comp.lang.prolog)