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.
The goal to trap.
Any atom that is a current module
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. See ref-lps-flg.
Exceptions are treated as failures, except an error message is printed.
The following clause gives the
same behaviour 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.