The Emacs/Prolog interface provides a facility that enables you to quickly locate procedures in source files once the procedures have been loaded. If you have loaded several files into Prolog at once, it can be helpful to be able to locate a procedure directly without having to search through several files.
While inspecting the definition of foo/1
,
foo(X) :- bar(X).
in some Prolog source window, you may want to see the definition of the
predicate bar/1
. To do so put the cursor anywhere on the name
bar
and type <ESC> . and respond to the Emacs message line,
Find: (default bar/1)
by pressing <RET>. Prolog will then visit the file that
defined bar/1
(this may be the same file that defined foo/1
) and put
the cursor on the first clause of bar/1
in that file.
While inspecting a previously submitted Prolog query,
| ?- bar(X).
in the Prolog execution window, you may want to see the definition of
the predicate bar/1
. This is done exactly in the same manner as
above.
Alternatively, you can type <ESC> . at the main Prolog prompt. The cursor moves to the bottom of the screen, and the system displays the message
Find:
Type the name of the predicate whose procedure you want to locate followed
by a slash and
the arity of the predicate; then press <RET>. (Recall that the
arity is the number of
arguments the predicate has.)
For example, to locate the procedure for
employee(smith, harold)
, you would type employee/2, as shown below.
Find: employee/2 <RET>
Please note: You can type the predicate name without typing the arity, and the system will still locate the predicate. If the predicate is defined for more than one arity, the system will simply locate one of the definitions of the predicate. You can then type <ESC> , to successively locate the other definition(s).
This will also search other files for additional clauses for a multifile predicate, or will search for a predicate of the same name and arity in a different module.
If Prolog cannot find a procedure of the specified name and arity, it displays a message telling you the procedure is undefined:
foo/2 is undefined
If the specified predicate is a built-in predicate, Prolog displays a message to that effect:
nl/0 is a built-in predicate