I would say that you are almost at a working implementation with your remark that append/3
can be used for splitting lists. This is indeed what append/3
in the instantiation (-,-,+)
does.
The only added requirement that seems to occur in your question is to exclude cases in which either of the splits is empty. This can be achieved by checking for inequivalence between terms using \==/2
.
This results in the following code:
splits(List, X/Y):-
append(X, Y, List),
X \== [],
Y \== [].
PS: Notice that your use of len
in your code snippet is wrong, since len
is not a Prolog variable but an atom. Handing an atom to the second argument of length/2
produces a type error, and an arithmetic error in len > 0
(provided that len
is not defined as a function). (Both observations relate to SWI-Prolog.)
Hope this helps!