consult(File) :-
retractall(done(_)),
current_input(Old),
open(File, read, Stream),
repeat,
read(Term),
try(Term),
close(Stream),
set_input(Old),
!.
try(end_of_file) :- !. % End of file marker read
try((?- Goals)) :- !, call(Goals), !, fail.
try((:- Goals)) :- !. % ignore directives
try(Clause) :-
head(Clause, Head),
record_done(Head),
assertz(Clause),
fail.
:- dynamic done/1.
record_done(Head) :- done(Head), !.
record_done(Head) :-
functor(Head, Func, Arity),
functor(Proc, Func, Arity),
asserta(done(Proc)),
retractall(Proc),
!.
head((A :- B), A) :- !.
head(A, A).
I didn't quite get what this consult predicate does, it was supposed to read in the clauses in a file and erases any existing clauses for predicates defined in that file. However, "read" takes in a user input (I use swi), then I tried to use read/2, and even after that, there still are some incongruences to the original idea for the code. Could someone shed some light on this matter?