Next: About this document
Up: No Title
Previous: Reading Characters
Contains three clauses consult, reconsult and
listing
- Possible to place all predicates with the same name in
a separate file (module)
- This module is then loaded into a complete program - done
via consult(Filename)
- Possible to consult a list of file
- reconsult(Filename) - same as consult, except that
all previous predicate definitions (of the same name) are
deleted from the program and Filename
- listing(P) displays predicates with name P -
regardless of the arity
- listing - without argument, shows the complete program
plays(X,Y) :-
plays(X, Y, _).
plays(X, piano) :-
plays(X, keyboard).
plays(X, keyboard) :-
plays(X, guitar).
also, consider a file named 'beatles', which contains the
following :
plays(john,guitar,rhythm).
plays(george, guitar, solo).
plays(paul, guitar, bass).
plays(ringo, drums).
and consider the dialog (queries) with Prolog
Q: listing
A: yes
Q: consult(beatles)
A: yes
Q: listing
A: plays(john,guitar,rhythm).
plays(george, guitar, solo).
plays(paul, guitar, bass).
plays(ringo, drums).
yes
Q: reconsult(plays)
A: yes
Q: listing
A: plays(john,guitar,rhythm).
plays(george, guitar, solo).
plays(paul, guitar, bass).
plays(X,Y) :-
plays(X, Y, _).
plays(X, piano) :-
plays(X, keyboard).
plays(X, keyboard) :-
plays(X, guitar).
yes
- Note that reconsult(plays) resulted in the removal
of plays(ringo,drums)
- Also, only one occurrence of the required play clause
was removed - hence, the reconsult clause only needs to be
satisfied once (i.e. no backtracking)
Omer F Rana
Mon Mar 17 12:47:04 GMT 1997