tags:

views:

48

answers:

1

Hello, Im trying to read a file in gprolog, but I have a small problem, it seems to read a line, then skip one, then read the next one, etc...

Heres my code :

readFichierEnt([],Fichier_Ent) :- read(end_of_file).
readFichierEnt(ExampleList,Fichier_Ent) :- read(X), write(X), readFichierEnt(ExampleList,Fichier_Ent).

If I provided traintest.txt as the input file I get :

sdfasdf1dfas3fas5end_of_file

whereas the file is :

classes([unacc, acc, good, vgood]).
sdfasdf1.
asdfas2.
dfas3.
fas4.
fas5.
df6.

Can anyone help me with this ? Thanks.

+1  A: 

Here are two things to consider:

  • read/1 just fails when the end of file is reached. You don't have to check for it.
  • What is worse, your read(end_of_file) reads a term, and fails if it's not the predicate "end_of_file.". This is the goal which consumes every second line in your example.
Jerome