Information Technology Reference
In-Depth Information
Dynamic predicates.
In SWI-Prolog, predicates are not dynamic unless the special
:- dynamic
declaration is included in the file (see chapter 8). In some Prolog
systems,
all
predicates are considered to be dynamic. (So if a predicate that does
not appear in a program is used in a query, the query will
fail
rather than cause
an
error
, as it does in SWI-Prolog.)
Assert and retract.
The predicates
assert
and
retract
are used here to add and
remove clauses for dynamic predicates (see chapter 8). Other Prolog systems
may use predicates with slightly different names for this purpose.
Member and append.
The predicates
member
and
append
are built-in predicates in
SWI-Prolog. In some older systems, these need to be defined by the user. (The
definitions appear in chapter 7 under the names
elem
and
join
).
Copying terms.
A special predicate
copy_term
is used in chapter 11. This is a built-
in SWI-Prolog predicate, but it is difficult to duplicate otherwise. One definition
that often works is based on
assert
and
retract
:
copy_term(X,Y) :-
assert(mycopy(X)), mycopy(Y), retract(mycopy(X)).
Sending output to a file.
The predicates
protocol
and
noprotocol
are used to send
the output produced by Prolog to an external file (see appendix C). Other con-
ventions are used in other systems, including
tell
and
told
for output, and
see
and
seen
for input.
Tracing.
Prolog systems vary considerably on how they handle tracing. The SWI-
Prolog conventions are described in appendix C.
There are many tutorials and FAQs about Prolog that can be found online. For more
information about SWI-Prolog, see
http://www.swi-prolog.org/
. A survey that has
a lot of information about many of the older versions of Prolog can be found at
http://www.faqs.org/faqs/prolog/
.