I would like to split a list of words separated through integers into a list of lists.
Sample query and expected result:
?- separatewords([h,e,l,l,o,1,o,v,e,r,3,t,h,e,r,e], X).
X = [[h,e,l,l,o],[o,v,e,r],[t,h,e,r,e]].
The following things I already achieved:
Splitting the list into one list before the first integer and one after the first integer:
Sample query with result:
?- take1word([h,e,l,l,o,1,o,v,e,r,3,t,h,e,r,e], X, Y).
X = [h,e,l,l,o], Y = [o,v,e,r,3,t,h,e,r,e]. % OK
My code:
take1word([H|T],[],T) :-
integer(H).
take1word([H|T],[H|Hs],Y) :-
( float(H), take1word(T,Hs,Y)
; atom(H), take1word(T,Hs,Y)
).
For separating words my code is the following:
separatewords([],[]).
separatewords([H|T],L) :- separatewords(T,[take1word([H|T],)|L]).
It only give me false
as a result, but I don't know, what I am doing wrong.
See Question&Answers more detail:
os