Re: strange behavior of read/2

Jiun-Shiung Wu <[email protected]> Fri, 18 Apr 2014 13:20:19 +0800
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CALvsX_LiyzHZziJxAYRzN7vv-gjSxadrN2EAPgaZiizpFqWoKw@mail.gmail.com>
Sorry, guys. I found out where I went wrong. If you have read the previous
email, thank you and I apologize that I waste your time.

Jiun-Shiung Wu




2014-04-18 11:30 GMT+08:00 Jiun-Shiung Wu <[email protected]>:

>
> Hi, SWI-prolog users,
>
> I encountered a strange behavor of read/2 and any help will be appreciated.
>
> I use readFiles/1 to read a file which contain a bunch of files names and
> put the file names in a list. Then, I pass the list of file names to
> corpus_process/2 etc.
>
> When I run process_corpra, an error message shows up: ERROR: read/2:
> stream `<stream>(035F4FB8)' does not exist. I trace read/2, I found that
> read/2 is called again after the end_of_file marker.
>
> But, when run readFiles/1 alone, a list is returned successfully. When I
> trace everything, a list of file names is found successfully and passed to
> corpus_process. But, when I run process_corpra under a non-degugging mode,
> the above error message shows.
>
> Could someone help me with this? Thank you!
>
> Jiun-Shiung Wu
>
> ====
>
> My codes are as below:
>
> process_corpra :-
>  readFiles([HeadFile|TailFiles]),
> corpus_process(HeadFile, Result),
> del_space(Result, LMinusSpace),
>  name(T, LMinusSpace),
> open('corpusDirProcessed.txt', write, Stream2, [encoding(utf8)]),
> write(Stream2, T),
>  close(Stream2),
> process_corpra_aux(TailFiles).
>
> process_corpra_aux([]).
>  process_corpra_aux([HeadFile|TailFiles]) :-
> corpus_process(HeadFile, Result),
> del_space(Result, LMinusSpace),
>  name(T, LMinusSpace),
> open('corpusDirProcessed.txt', append, Stream, [encoding(utf8)]),
> write(Stream, T),
>  close(Stream),
> process_corpra_aux(TailFiles).
>
> readFile(Stream, ListofFiles) :-
>  read(Stream, File),
> readFileAux(Stream, File, ListofFiles).
>
> readFileAux(_, -1, []).
>
> readFileAux(_, end_of_file, []).
>
>
> readFileAux(Stream, File, [File|FileTail]) :-
> read(Stream, File2),
>  readFileAux(Stream, File2, FileTail).
>
> readFiles(ListofFiles) :-
> open('corpusDir.txt', read, Stream, [encoding(utf8)]),
>  readFile(Stream, ListofFiles),
> close(Stream).
>
-------------- next part --------------
HTML attachment scrubbed and removed