a question about reading in alphabet letters

Jiun-Shiung Wu <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CALvsX_+Kipc8_7pUtMYhc5u56fNyU9MWvON3B_vL-h0rdnjmKQ@mail.gmail.com>
Hi,

I am practicing reading English sentences from a file, using get0/2. My
codes are as follows:

readInSentences :-
open('sentences.txt', read, Stream, [encoding(utf8)]),
readIn(Stream, List),
close(Stream),
write(List),nl,
put_list(List).

readIn(Stream, []) :-
get0(Stream, -1).
readIn(Stream, [Word|Tail]) :-
get0(Stream, Word),
readIn(Stream, Tail).

put_list([]).
put_list([H|T]) :-
put(H),
put_list(T).

I tried my codes and I got:

5 ?- readInSentences.
[104,115,105,32,32,111,107,10,104,116,105,32,32,101,46,87,32,97,32,114,116,32,105,104,116,101,112,110,-1]
hsi  ok
hti  e.W a rt ihtepn
ERROR: put/1: Type error: `character' expected, found `-1'

The three sentences to be read are: This is a book. (Enter) That is a pen.
(Enter). We can write with the pen.

Could someone tell me why some of the alphabetic letters are not read? I
use utf-8 because eventually I want to try my codes on Chinese texts.

Thank you!

Hunter Wu
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.