Next: mpg-ref-unload_foreign_resource, Previous: mpg-ref-unknown, Up: mpg-bpr [Contents][Index]
unknown_predicate_handler/3
hook:- multifile user:unknown_predicate_handler/3.
user:unknown_predicate_handler(+Goal, +Module, -NewGoal)
User definable hook to trap calls to unknown predicates.
callable
The goal to trap.
atom
Any atom that is a current module
callable
The goal to call instead.
When Prolog comes across a call to an unknown predicate, Prolog makes
a call to user:unknown_predicate_handler/3
with the first two
arguments bound. Goal is bound to the call to the undefined
predicate and Module is the module in which that predicate is
supposed to be defined. If the call to
user:unknown_predicate_handler/3
succeeds, then Prolog replaces
the call to the undefined predicate with the call to
Module:NewGoal. Otherwise, the action taken is governed by the
unknown
Prolog flag.
Exceptions are treated as failures, except an error message is printed.
The following clause gives the
same behavior as setting unknown(_,fail)
:
unknown_predicate_handler(_, _, fail).
The following clause causes calls to undefined predicates whose names
begin with ‘xyz_’ in module m
to be trapped to
my_handler/1
in module n
. Predicates with names not
beginning with this character sequence are not affected.
unknown_predicate_handler(G, m, n:my_handler(G)) :- functor(G,N,_), atom_concat(xyz_, _, N).
Undefined Predicates, ref-ere, ref-lps-flg.