YAP
7.1.0
undefined.yap
1
/*************************************************************************
2
* *
3
* YAP Prolog *
4
* *
5
* Yap Prolog was developed at NCCUP - Universidade do Porto *
6
* *
7
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8
* *
9
**************************************************************************
10
* *
11
* File: undefined.yap *
12
* Last rev: 8/2/88 *
13
* mods: *
14
* comments: Predicate Undefined for YAP *
15
* *
16
*************************************************************************/
17
18
/** @defgroup Undefined_Procedures Handling Undefined Procedures
19
@ingroup YAPControl
20
@{
21
22
A predicate in a module is said to be undefined if there are no clauses
23
defining the predicate, and if the predicate has not been declared to be
24
dynamic. What YAP does when trying to execute undefined predicates can
25
be specified in three different ways:
26
27
28
+ By setting an YAP flag, through the yap_flag/2 or
29
set_prolog_flag/2 built-ins. This solution generalizes the
30
ISO standard by allowing module-specific behavior.
31
+ By using the unknown/2 built-in (this deprecated solution is
32
compatible with previous releases of YAP).
33
+ By defining clauses for the hook predicate
34
`user:unknown_predicate_handler/3`. This solution is compatible
35
with SICStus Prolog.
36
37
38
*/
39
40
/** @pred user:unknown_predicate_handler(+ _Call_, + _M_, - _N_)
41
42
In YAP, the default action on undefined predicates is to output an
43
`error` message. Alternatives are to silently `fail`, or to print a
44
`warning` message and then fail. This follows the ISO Prolog standard
45
where the default action is `error`.
46
47
The user:unknown_predicate_handler/3 hook was first introduced in
48
SICStus Prolog. It allows redefining the answer for specifici
49
calls. As an example. after defining `undefined/1` by:
50
51
```
52
undefined(A) :-
53
format('Undefined predicate: ~w~n',[A]), fail.
54
```
55
and executing the goal:
56
57
```
58
:- assert(user:unknown_predicate_handler(U,M,undefined(M:U)) )
59
```
60
a call to a predicate for which no clauses were defined will result in
61
the output of a message of the form:
62
63
```
64
Undefined predicate:
65
```
66
followed by the failure of that call.
67
*/
68
:-
multifile
unknown_predicate_handler/3
.
69
:-
dynamic
unknown_predicate_handler/3
.
70
71
'$undefp'(
G0
)
:-
72
'$yap_strip_module'(
G0
,
M
,
G
),
73
'$yap_strip_module'
:
unknown_predicate_handler
(
G
,
M
,
NewG
),
74
unknown_predicate_handler,
75
call
(
NewG
).
76
'$undefp'(
G
)
:-
77
prolog_flag(unknown,
Flag
),
78
'$undef_error'(
Flag
,
G
).
79
80
/*
81
'$undef_error'(_, Goal) :-
82
recorded('$import','$import'(M,_MF,G0,Goal,_,_),_), !,
83
!,
84
functor(Goal,N,A),
85
functor(G0,N0,A),
86
'$do_import'(N/A-N0/A,M,user),
87
call(M:G0),
88
*/
89
'$undef_error'(error,
ModGoal
)
:-
90
'$yap_strip_module'(
ModGoal
,
M
,
G
),
91
functor
(
G
,
N
,
A
),
92
throw
(error(existence_error(procedure,
M
:
N
/
A
),
G
)).
93
'$undef_error'(warning,
ModGoal
)
:-
94
'$yap_strip_module'(
ModGoal
,
M
,
G
),
95
functor
(
G
,
N
,
A
),
96
print_warning( error, error(existence_error(procedure,
M
:
N
/
A
),
ModGoal
) ).
97
%% no need for code at this point.
98
%%'$undef_error'(fail,_) :-
99
%% fail.
100
101
/** @pred unknown(- _O_,+ _N_)
102
103
The unknown predicate, informs about what the user wants to be done
104
when there are no clauses for a predicate. Using unknown/3 is
105
strongly deprecated. We recommend setting the `unknown` prolog
106
flag for generic behaviour, and calling the hook
107
user:unknown_predicate_handler/3 to fine-tune specific cases
108
undefined goals.
109
110
*/
111
112
unknown
(
P
,
NP
)
:-
113
yap_flag( unknown,
P
,
NP
).
114
115
/**
116
@}
117
*/
118
throw/1
throw(+ Ball)
unknown/2
no need for code at this point
unknown_predicate_handler/3
unknown_predicate_handler(+ Call, + M, - N)
call/1
call( 0:P )
functor/3
functor( T, F, N)
pl
undefined.yap
Generated by
1.9.3