Re: Building lists and sublists



"andrea" <kerny404@xxxxxxxxx> writes:

When it finds a '.' it ends and when it finds a ' ' it goes to the
rest of the list, creating more and more words..

A rather direct translation of your description:

par(WordSoFar, Words) :-
get_char(C),
( C == ' ' ->
reverse(WordSoFar, Word),
Words = [Word|Rest],
par([], Rest)
; C == '.' ->
reverse(WordSoFar, Word),
Words = [Word]
; par([C|WordSoFar], Words)
).

Example:

?- par([], Words).
|: these are the words.


Words = [[t, h, e, s, e], [a, r, e], [t, h, e], [w, o, r, d, s]]


All the best,
Markus Triska
.