1
votes

Following some learning exercises/tutorials online I encounter the bellow error when running my simple prolog program.

testReverse :-
  transImage(reserseList,'imageIN.pgm','imageOUT.pgm').

transImage(R,In,Out) :-
   read_pgm(In,PGM),
   transf_pgm(R,PGM,PGM2),
   write_pgm(Out,PGM2).

transf_pgm(R, pgm(A,B,H,W,M,L),  pgm(A,B,H,W,M,L2)) :-
   Term =.. [R,L,L2],
   call(Term).

reserseList([],[]).
reserseList([X|R],Reversed):-
    reserseList(R, RevList),
    append(RevList,[X],Reversed).

And the runtime error am getting in SWI-Prolog is

10 ?- testReverse
|    .
ERROR: read_pgm/2: Undefined procedure: fread/4
ERROR:   However, there are definitions for:
ERROR:         read/1
ERROR:         read/2

Any ideas why? Am very new to prolog, literally 2 days from online tutorials, so accept my apologies in advance If i make you further questions regarding your answer. Thank you.

1

1 Answers

3
votes

according to the error message you havent defined fread/4.
on the other hand, in the code you gave read_pgm/2 is not defined either (unless i'm missing something).

possible reasons:
the definition is in some other file.
fread/4 is not implemented in your prolog implementation.
you didnt load the library with fread/4.

i think you should post the rest of the code and which prolog implementation you use.
if you use swi-prolog, i dont think that there is fread/4.