YAP 7.1.0
Handling Undefined Procedures

A predicate in a module is said to be undefined if there are no clauses defining the predicate, and if the predicate has not been declared to be dynamic. More...

Detailed Description

A predicate in a module is said to be undefined if there are no clauses defining the predicate, and if the predicate has not been declared to be dynamic.

What YAP does when trying to execute undefined predicates can be specified in three different ways:


Class Documentation

◆ unknown_predicate_handler/3

class unknown_predicate_handler/3

unknown_predicate_handler(+ Call, + M, - N)

In YAP, the default action on undefined predicates is to output an error message Alternatives are to silently fail, or to print a warning message and then fail This follows the ISO Prolog standard where the default action is error

The user:unknown_predicate_handler/3 hook was first introduced in SICStus Prolog It allows redefining the answer for specifici calls As an example after defining undefined/1 by:

undefined(A) :-
format('Undefined predicate: ~w~n',[A]), format.
format(+ T, :L)

and executing the goal:

:- assert(user:unknown_predicate_handler(U,M,undefined(M:U)) )
assert(+ C)

a call to a predicate for which no clauses were defined will result in the output of a message of the form:

Undefined assert:

followed by the failure of that call

◆ unknown/2

class unknown/2

no need for code at this point

%'$undef_error'(fail,_) :- %% fail

unknown(- O,+ N)

The unknown predicate, informs about what the user wants to be done when there are no clauses for a predicate Using unknown/3 is strongly deprecated We recommend setting the unknown prolog flag for generic behaviour, and calling the hook user:unknown_predicate_handler/3 to fine-tune specific cases undefined goals