Usage:
Part is split(Sting, Separator, Number)
This function splits the String using Separator like a splitting character. The Number gives which part has to be the returned value. For example if Number is zero then Part will be the first part before the first symbol Separator, if Number is one then Part will be the first part after the first symbol Separator and so on. If Separator divides String on N+1 parts (i.e. you can find it N times in the String) and if N<Number then split fails.
Remark: If Number is 0 then split will never fail. In this case it will return some beginning of the String. If Separator is not in the String then split will return the whole string.
Example:
?-
read(S, "Give me a sentence:
", s),
makeList(S, L, 0),
write( L ), nl.
makeList(S, [H|T], Pos):-
H is split(S, " ", Pos),
!,
Pos2 is Pos + 1,
makeList(S, T, Pos2).
makeList(S, [], Pos).