0

I want to be able to turn

this: [[[a],b],c]

into this: [a,b,c]

with a constantly changing lists, so far I've done this:

a([[[A],B],C]).
strechList(List,C):-
    List=[H,T],
    append(T,List1,C),
    strechList(H,List1).
strechList(A,A).

but it doesn't work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • `[H,T]` is a list of only two elements. I'm supposing you meant, `[H|T]` which is a list whose first element (*head*) is `H` and *tail list* is `T`. Your rule `strechList(A, A).` says that any list is the stretch of itself, which doesn't sound correct. – lurker Mar 18 '15 at 23:43

1 Answers1

1

That predicate is called 'flatten'. It's built-in if you're using SWI-Prolog. Also check this answer.

Community
  • 1
  • 1
vmg
  • 4,176
  • 2
  • 20
  • 33