Re: Building lists and sublists
- From: Markus Triska <triska@xxxxxx>
- Date: Wed, 13 Dec 2006 22:06:38 +0100
"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
.
- Follow-Ups:
- Re: Building lists and sublists
- From: andrea
- Re: Building lists and sublists
- References:
- Building lists and sublists
- From: andrea
- Building lists and sublists
- Prev by Date: Re: difference lists ad CLP(FD) exercises
- Next by Date: Re: Building lists and sublists
- Previous by thread: Building lists and sublists
- Next by thread: Re: Building lists and sublists
- Index(es):