Skip to content

Instantly share code, notes, and snippets.

@zkessin
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkessin/0b1f436f753b1a7c4402 to your computer and use it in GitHub Desktop.
Save zkessin/0b1f436f753b1a7c4402 to your computer and use it in GitHub Desktop.
%-*- Prolog -*-
split(Head, Tail, HeadLength, FullList) :-
length(Head, HeadLength),
append(Head, Tail, FullList).
?- split(H,T, 3, [a,b,c,d,e,f,g,h,i,j,k,l]).
H = [a, b, c],
T = [d, e, f, g, h, i, j, k, l].
@zkessin
Copy link
Author

zkessin commented Aug 18, 2014

So what is going on here?

Basicly given a List, Full List and a length it is broken into sub lists of which the first half is the specified length, and he 2nd is the rest. This works because append can break a list apart, and length can cause it to backtrack until it finds the Head it wants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment