[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read from file
From: |
Vic Bancroft |
Subject: |
Re: read from file |
Date: |
Tue, 15 Aug 2006 08:52:36 -0400 |
User-agent: |
Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) |
address@hidden wrote:
hi,
Aloha
i want to read data from the file (data.txt). and want to use these prolog
predicate like
a(book)
a(computer)
a(phone)
a(pen)
a(pencil)
Unless you use a read option for end_of_term, your term data should have
the 'dot' delimeter, e.g.,
a(book).
a("computer").
a("phone").
a('pen').
a('pencil').
Also note the distinction between an list of characters (using the
double quote) and an atom (using the single quote). This is most easily
seen using the writeq/1 predicate, as in,
terms(A) :-
see(A),
repeat,
read(B),
writeq(B),
nl,
( B = end_of_file ->
true, !
; fail
),
seen.
This predicate results in the output,
| ?- terms( 'term_data.txt' ).
a(book)
a([99,111,109,112,117,116,101,114])
a([112,104,111,110,101])
a(pen)
a(pencil)
end_of_file
yes
Did you really need to use read_atom/1 or perhaps read_token/1 ?
more,
l8r,
v
--
"The future is here. It's just not evenly distributed yet."
-- William Gibson, quoted by Whitfield Diffie