users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

more elegant solution?


From: Detlef Sax
Subject: more elegant solution?
Date: Mon, 22 Jul 2002 21:23:05 +0200 (CEST)

Hello,
I used for stream input always get_char and or get_code.
Now I do have a file to read only containing atoms. A good time to
try read_atom/2.

I found a solution for this simple task, but there was a problem at
the end of the file. There is a char code 10 or \n or literally a
newline.

So read_atom/2 throws a syntax_error. And my solution seems to me
more as a workaround than a clean solution. Does anyone give me a
hint? Maybe other readers profit of an answer:

I'm still using GNU Prolog 1.2.12 on a i386/FreeBSD

% q/0 only added for better understanding
q :- SRC = 'db_horr_komment.pl',
        add_db(SRC), !.

add_db(SRC) :-
        open(SRC, read, Stream),
        add_stream_alias(Stream, src_stream),
% Here I think I start fumble around:
        set_prolog_flag(syntax_error, fail),
        add_db_stream(_Atom).

add_db_stream(Atom) :-
        read_atom(src_stream, Atom),
        Atom \== end_of_file,
        assertz(horr(Atom)),
        add_db_stream(_NAtom).
add_db_stream(Atom) :-
        read(src_stream, Atom),
        Atom == end_of_file,
% Nothing has happen 
        set_prolog_flag(syntax_error, error),
        close(src_stream).

Bye and best regards
Detlef

-- 
http://www.noart.de/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]