2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
2015-01-04 23:58:23 +00:00
|
|
|
* YAP Prolog *
|
2015-03-11 22:22:27 +00:00
|
|
|
* *
|
2001-04-09 20:54:03 +01:00
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: preds.yap *
|
|
|
|
* Last rev: 8/2/88 *
|
|
|
|
* mods: *
|
|
|
|
* comments: Predicate Manipulation for YAP *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/**
|
|
|
|
* @{
|
2015-12-15 09:04:08 +00:00
|
|
|
* @defgroup Database The Clausal Data Base
|
|
|
|
* @ingroup builtins
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
Predicates in YAP may be dynamic or static. By default, when
|
|
|
|
consulting or reconsulting, predicates are assumed to be static:
|
|
|
|
execution is faster and the code will probably use less space.
|
2015-04-13 13:28:17 +01:00
|
|
|
Static predicates impose some restrictions: in general there can be no
|
2014-09-11 20:06:57 +01:00
|
|
|
addition or removal of clauses for a procedure if it is being used in the
|
|
|
|
current execution.
|
|
|
|
|
|
|
|
Dynamic predicates allow programmers to change the Clausal Data Base with
|
|
|
|
the same flexibility as in C-Prolog. With dynamic predicates it is
|
|
|
|
always possible to add or remove clauses during execution and the
|
|
|
|
semantics will be the same as for C-Prolog. But the programmer should be
|
2015-04-13 13:28:17 +01:00
|
|
|
aware of the fact that asserting or retracting are still expensive operations,
|
2014-09-11 20:06:57 +01:00
|
|
|
and therefore he should try to avoid them whenever possible.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-04-09 12:39:29 +01:00
|
|
|
:- system_module( '$_preds', [abolish/1,
|
|
|
|
abolish/2,
|
|
|
|
assert/1,
|
|
|
|
assert/2,
|
|
|
|
assert_static/1,
|
|
|
|
asserta/1,
|
|
|
|
asserta/2,
|
|
|
|
asserta_static/1,
|
|
|
|
assertz/1,
|
|
|
|
assertz/2,
|
|
|
|
assertz_static/1,
|
|
|
|
clause/2,
|
|
|
|
clause/3,
|
|
|
|
clause_property/2,
|
|
|
|
compile_predicates/1,
|
|
|
|
current_key/2,
|
|
|
|
current_predicate/1,
|
|
|
|
current_predicate/2,
|
|
|
|
dynamic_predicate/2,
|
|
|
|
hide_predicate/1,
|
|
|
|
nth_clause/3,
|
|
|
|
predicate_erased_statistics/4,
|
|
|
|
predicate_property/2,
|
|
|
|
predicate_statistics/4,
|
|
|
|
retract/1,
|
|
|
|
retract/2,
|
|
|
|
retractall/1,
|
|
|
|
stash_predicate/1,
|
|
|
|
system_predicate/1,
|
|
|
|
system_predicate/2,
|
|
|
|
unknown/2], ['$assert_static'/5,
|
|
|
|
'$assertz_dynamic'/4,
|
|
|
|
'$clause'/4,
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'/4,
|
2014-04-09 12:39:29 +01:00
|
|
|
'$init_preds'/0,
|
|
|
|
'$noprofile'/2,
|
|
|
|
'$public'/2,
|
|
|
|
'$unknown_error'/1,
|
|
|
|
'$unknown_warning'/1]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_boot', ['$check_head_and_body'/4,
|
|
|
|
'$check_if_reconsulted'/2,
|
|
|
|
'$head_and_body'/3,
|
|
|
|
'$inform_as_reconsulted'/2]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_errors', ['$do_error'/2]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_init', ['$do_log_upd_clause'/6,
|
|
|
|
'$do_log_upd_clause0'/6,
|
|
|
|
'$do_log_upd_clause_erase'/6,
|
|
|
|
'$do_static_clause'/5]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_modules', ['$imported_pred'/4,
|
|
|
|
'$meta_predicate'/4,
|
|
|
|
'$module_expansion'/5]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_preddecls', ['$check_multifile_pred'/3,
|
|
|
|
'$dynamic'/2]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_strict_iso', ['$check_iso_strict_clause'/1]).
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred assert_static(: _C_)
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
Adds clause _C_ to a static procedure. Asserting a static clause
|
|
|
|
for a predicate while choice-points for the predicate are available has
|
|
|
|
undefined results.
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2001-11-15 00:01:43 +00:00
|
|
|
assert_static(C) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$assert'(C , assertz_static, _ ).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred asserta_static(: _C_)
|
|
|
|
|
2015-01-17 10:44:13 +00:00
|
|
|
|
2015-07-23 01:31:03 +01:00
|
|
|
Adds clause _C_ as the first clause for a static procedure.
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
*/
|
2016-01-31 19:41:10 +00:00
|
|
|
asserta_static(C) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$assert'(C , asserta_static, _ ).
|
2015-07-23 01:31:03 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred assertz_static(: _C_)
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
Adds clause _C_ to the end of a static procedure. Asserting a
|
|
|
|
static clause for a predicate while choice-points for the predicate are
|
|
|
|
available has undefined results.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following predicates can be used for dynamic predicates and for
|
|
|
|
static predicates, if source mode was on when they were compiled:
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2016-01-31 19:41:10 +00:00
|
|
|
assertz_static(C) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$assert'(C , assertz_static, _ ).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred clause(+ _H_, _B_) is iso
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
A clause whose head matches _H_ is searched for in the
|
|
|
|
program. Its head and body are respectively unified with _H_ and
|
|
|
|
_B_. If the clause is a unit clause, _B_ is unified with
|
|
|
|
_true_.
|
|
|
|
|
|
|
|
This predicate is applicable to static procedures compiled with
|
|
|
|
`source` active, and to all dynamic procedures.
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2015-07-23 01:31:03 +01:00
|
|
|
clause(V0,Q) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$yap_strip_module'(V0, M, V),
|
|
|
|
must_be_of_type( callable, V ),
|
2006-03-24 16:26:31 +00:00
|
|
|
'$clause'(V,M,Q,_).
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred clause(+ _H_, _B_,- _R_)
|
|
|
|
|
|
|
|
The same as clause/2, plus _R_ is unified with the
|
|
|
|
reference to the clause in the database. You can use instance/2
|
|
|
|
to access the reference's value. Note that you may not use
|
|
|
|
erase/1 on the reference on static procedures.
|
|
|
|
*/
|
2016-01-03 02:06:09 +00:00
|
|
|
clause(P,Q,R) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$instance_module'(R,M0), !,
|
|
|
|
instance(R,T0),
|
|
|
|
( T0 = (H :- B) -> Q = B ; H=T0, Q = true),
|
|
|
|
'$yap_strip_module'(P, M, T),
|
|
|
|
'$yap_strip_module'(M0:H, M1, H1),
|
|
|
|
(
|
|
|
|
M == M1
|
|
|
|
->
|
|
|
|
H1 = T
|
2016-01-03 02:06:09 +00:00
|
|
|
;
|
2015-12-15 09:04:08 +00:00
|
|
|
M1:H1 = T
|
|
|
|
).
|
2015-07-23 01:31:03 +01:00
|
|
|
clause(V0,Q,R) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$yap_strip_module'(V0, M, V),
|
|
|
|
must_be_of_type( callable, V ),
|
2002-12-13 20:00:41 +00:00
|
|
|
'$clause'(V,M,Q,R).
|
|
|
|
|
2013-01-11 16:45:14 +00:00
|
|
|
'$clause'(P,M,Q,R) :-
|
|
|
|
'$is_exo'(P, M), !,
|
|
|
|
Q = true,
|
|
|
|
R = '$exo_clause'(M,P),
|
|
|
|
'$execute0'(P, M).
|
2003-08-27 14:37:10 +01:00
|
|
|
'$clause'(P,M,Q,R) :-
|
|
|
|
'$is_log_updatable'(P, M), !,
|
|
|
|
'$log_update_clause'(P,M,Q,R).
|
2016-01-03 02:06:09 +00:00
|
|
|
'$clause'(P,M,Q,R) :-
|
|
|
|
'$is_source'(P, M), !,
|
|
|
|
'$static_clause'(P,M,Q,R).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$clause'(P,M,Q,R) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
'$some_recordedp'(M:P), !,
|
2002-12-13 20:00:41 +00:00
|
|
|
'$recordedp'(M:P,(P:-Q),R).
|
2004-04-27 16:03:43 +01:00
|
|
|
'$clause'(P,M,Q,R) :-
|
2002-12-27 16:53:09 +00:00
|
|
|
\+ '$undefined'(P,M),
|
2016-01-03 02:06:09 +00:00
|
|
|
( '$is_system_predicate'(P,M) -> true ;
|
2001-11-15 00:01:43 +00:00
|
|
|
'$number_of_clauses'(P,M,N), N > 0 ),
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(P,Name,Arity),
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(access,private_procedure,Name/Arity),
|
2004-04-27 16:03:43 +01:00
|
|
|
clause(M:P,Q,R)).
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
'$init_preds' :-
|
2011-08-31 21:59:30 +01:00
|
|
|
once('$do_static_clause'(_,_,_,_,_)),
|
|
|
|
fail.
|
2015-04-13 13:28:17 +01:00
|
|
|
'$init_preds' :-
|
2011-08-31 21:59:30 +01:00
|
|
|
once('$do_log_upd_clause0'(_,_,_,_,_,_)),
|
|
|
|
fail.
|
2015-04-13 13:28:17 +01:00
|
|
|
'$init_preds' :-
|
2011-08-31 21:59:30 +01:00
|
|
|
once('$do_log_upd_clause'(_,_,_,_,_,_)),
|
|
|
|
fail.
|
2015-04-13 13:28:17 +01:00
|
|
|
'$init_preds' :-
|
2011-08-31 21:59:30 +01:00
|
|
|
once('$do_log_upd_clause_erase'(_,_,_,_,_,_)),
|
|
|
|
fail.
|
|
|
|
'$init_preds'.
|
|
|
|
|
|
|
|
:- '$init_preds'.
|
2003-11-26 18:36:35 +00:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred nth_clause(+ _H_, _I_,- _R_)
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
Find the _I_th clause in the predicate defining _H_, and give
|
|
|
|
a reference to the clause. Alternatively, if the reference _R_ is
|
|
|
|
given the head _H_ is unified with a description of the predicate
|
|
|
|
and _I_ is bound to its position.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-12-13 20:00:41 +00:00
|
|
|
nth_clause(V,I,R) :-
|
2015-07-23 01:31:03 +01:00
|
|
|
strip_module(V, M1, P), !,
|
2013-12-09 14:16:30 +00:00
|
|
|
'$nth_clause'(P, M1, I, R).
|
|
|
|
|
|
|
|
|
2003-12-01 19:22:01 +00:00
|
|
|
'$nth_clause'(P,M,I,R) :-
|
2013-12-09 14:16:30 +00:00
|
|
|
var(I), var(R), !,
|
|
|
|
'$clause'(P,M,_,R),
|
|
|
|
'$fetch_nth_clause'(P,M,I,R).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$nth_clause'(P,M,I,R) :-
|
2013-12-09 14:16:30 +00:00
|
|
|
'$fetch_nth_clause'(P,M,I,R).
|
2005-02-08 04:05:39 +00:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred abolish(+ _P_,+ _N_)
|
|
|
|
|
2014-10-09 10:46:09 +01:00
|
|
|
Completely delete the predicate with name _P_ and arity _N_. It will
|
|
|
|
remove both static and dynamic predicates. All state on the predicate,
|
|
|
|
including whether it is dynamic or static, multifile, or
|
2015-04-13 13:28:17 +01:00
|
|
|
meta-predicate, will be lost.
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2015-07-23 01:31:03 +01:00
|
|
|
abolish(N0,A) :-
|
|
|
|
strip_module(N0, Mod, N), !,
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish'(N,A,Mod).
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish'(N,A,M) :- var(N), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,abolish(M:N,A)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish'(N,A,M) :- var(A), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,abolish(M:N,A)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish'(N,A,M) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
( recorded('$predicate_defs','$predicate_defs'(N,A,M,_),R) -> erase(R) ),
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish'(N,A,M) :- functor(T,N,A),
|
2001-11-16 20:27:06 +00:00
|
|
|
( '$is_dynamic'(T, M) -> '$abolishd'(T,M) ;
|
2001-11-15 00:01:43 +00:00
|
|
|
/* else */ '$abolishs'(T,M) ).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred abolish(+ _PredSpec_) is iso
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
Deletes the predicate given by _PredSpec_ from the database. If
|
2015-07-23 01:31:03 +01:00
|
|
|
§§ _PredSpec_ is an unbound variable, delete all predicates for the
|
2014-09-11 20:06:57 +01:00
|
|
|
current module. The
|
|
|
|
specification must include the name and arity, and it may include module
|
|
|
|
information. Under <tt>iso</tt> language mode this built-in will only abolish
|
2015-04-13 13:28:17 +01:00
|
|
|
dynamic procedures. Under other modes it will abolish any procedures.
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
*/
|
2015-07-23 01:31:03 +01:00
|
|
|
abolish(X0) :-
|
|
|
|
strip_module(X0,M,X),
|
2002-10-14 17:25:38 +01:00
|
|
|
'$abolish'(X,M).
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
'$abolish'(X,M) :-
|
2015-06-19 01:12:05 +01:00
|
|
|
current_prolog_flag(language, sicstus), !,
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_abolish'(X,M).
|
2015-04-13 13:28:17 +01:00
|
|
|
'$abolish'(X, M) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
'$old_abolish'(X,M).
|
|
|
|
|
2001-12-11 15:39:28 +00:00
|
|
|
'$new_abolish'(V,M) :- var(V), !,
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish_all'(M).
|
2016-02-01 02:46:39 +00:00
|
|
|
'$new_abolish'(A/V,M) :- atom(A), var(V), !,
|
2001-12-11 19:53:07 +00:00
|
|
|
'$abolish_all_atoms'(A,M).
|
2010-02-27 23:07:03 +00:00
|
|
|
'$new_abolish'(Na//Ar1, M) :-
|
|
|
|
integer(Ar1),
|
|
|
|
!,
|
|
|
|
Ar is Ar1+2,
|
|
|
|
'$new_abolish'(Na//Ar, M).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_abolish'(Na/Ar, M) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(H, Na, Ar),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$is_dynamic'(H, M), !,
|
|
|
|
'$abolishd'(H, M).
|
|
|
|
'$new_abolish'(Na/Ar, M) :- % succeed for undefined procedures.
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(T, Na, Ar),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$undefined'(T, M), !.
|
|
|
|
'$new_abolish'(Na/Ar, M) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(modify,static_procedure,Na/Ar),abolish(M:Na/Ar)).
|
2001-11-19 17:56:07 +00:00
|
|
|
'$new_abolish'(T, M) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(predicate_indicator,T),abolish(M:T)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish_all'(M) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'(Na, M, S, _),
|
|
|
|
functor(S, Na, Ar),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_abolish'(Na/Ar, M),
|
2001-05-28 20:54:53 +01:00
|
|
|
fail.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish_all'(_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-12-11 19:53:07 +00:00
|
|
|
'$abolish_all_atoms'(Na, M) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'(Na,M,S,_),
|
|
|
|
functor(S, Na, Ar),
|
2001-12-11 19:53:07 +00:00
|
|
|
'$new_abolish'(Na/Ar, M),
|
|
|
|
fail.
|
|
|
|
'$abolish_all_atoms'(_,_).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_error_in_predicate_indicator'(V, Msg) :-
|
|
|
|
var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error, Msg).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_error_in_predicate_indicator'(M:S, Msg) :- !,
|
|
|
|
'$check_error_in_module'(M, Msg),
|
|
|
|
'$check_error_in_predicate_indicator'(S, Msg).
|
|
|
|
'$check_error_in_predicate_indicator'(S, Msg) :-
|
2010-02-27 23:07:03 +00:00
|
|
|
S \= _/_,
|
|
|
|
S \= _//_, !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(predicate_indicator,S), Msg).
|
2001-10-30 16:42:05 +00:00
|
|
|
'$check_error_in_predicate_indicator'(Na/_, Msg) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
var(Na), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error, Msg).
|
2001-10-30 16:42:05 +00:00
|
|
|
'$check_error_in_predicate_indicator'(Na/_, Msg) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
\+ atom(Na), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atom,Na), Msg).
|
2001-10-30 16:42:05 +00:00
|
|
|
'$check_error_in_predicate_indicator'(_/Ar, Msg) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
var(Ar), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error, Msg).
|
2001-10-30 16:42:05 +00:00
|
|
|
'$check_error_in_predicate_indicator'(_/Ar, Msg) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
\+ integer(Ar), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(integer,Ar), Msg).
|
2001-10-30 16:42:05 +00:00
|
|
|
'$check_error_in_predicate_indicator'(_/Ar, Msg) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
Ar < 0, !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(domain_error(not_less_than_zero,Ar), Msg).
|
2001-04-09 20:54:03 +01:00
|
|
|
% not yet implemented!
|
|
|
|
%'$check_error_in_predicate_indicator'(Na/Ar, Msg) :-
|
|
|
|
% Ar < maxarity, !,
|
2002-09-09 18:40:12 +01:00
|
|
|
% '$do_error'(type_error(representation_error(max_arity),Ar), Msg).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$check_error_in_module'(M, Msg) :-
|
|
|
|
var(M), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error, Msg).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_error_in_module'(M, Msg) :-
|
|
|
|
\+ atom(M), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atom,M), Msg).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$old_abolish'(V,M) :- var(V), !,
|
2015-11-05 17:26:50 +00:00
|
|
|
( true -> % current_prolog_flag(language, sicstus) ->
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,abolish(M:V))
|
2002-01-30 04:56:43 +00:00
|
|
|
;
|
|
|
|
'$abolish_all_old'(M)
|
|
|
|
).
|
2005-01-14 20:55:16 +00:00
|
|
|
'$old_abolish'(N/A, M) :- !,
|
|
|
|
'$abolish'(N, A, M).
|
2001-12-11 19:53:07 +00:00
|
|
|
'$old_abolish'(A,M) :- atom(A), !,
|
2015-06-19 01:12:05 +01:00
|
|
|
( current_prolog_flag(language, iso) ->
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(predicate_indicator,A),abolish(M:A))
|
2002-01-30 04:56:43 +00:00
|
|
|
;
|
|
|
|
'$abolish_all_atoms_old'(A,M)
|
|
|
|
).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$old_abolish'([], _) :- !.
|
|
|
|
'$old_abolish'([H|T], M) :- !, '$old_abolish'(H, M), '$old_abolish'(T, M).
|
2001-11-19 17:56:07 +00:00
|
|
|
'$old_abolish'(T, M) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(predicate_indicator,T),abolish(M:T)).
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolish_all_old'(M) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'(Na, M, S, _),
|
|
|
|
functor( S, Na, Ar ),
|
2001-12-28 16:42:18 +00:00
|
|
|
'$abolish'(Na, Ar, M),
|
2001-06-12 17:15:58 +01:00
|
|
|
fail.
|
2001-12-28 16:42:18 +00:00
|
|
|
'$abolish_all_old'(_).
|
2001-06-12 17:15:58 +01:00
|
|
|
|
2001-12-11 19:53:07 +00:00
|
|
|
'$abolish_all_atoms_old'(Na, M) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'(Na, M, S, _),
|
|
|
|
functor(S, Na, Ar),
|
2001-12-11 19:53:07 +00:00
|
|
|
'$abolish'(Na, Ar, M),
|
|
|
|
fail.
|
|
|
|
'$abolish_all_atoms_old'(_,_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-01-08 05:22:40 +00:00
|
|
|
'$abolishs'(G, M) :- '$system_predicate'(G,M), !,
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(G,Name,Arity),
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(modify,static_procedure,Name/Arity),abolish(M:G)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolishs'(G, Module) :-
|
2015-06-19 01:12:05 +01:00
|
|
|
current_prolog_flag(language, sicstus), % only do this in sicstus mode
|
2001-11-15 00:01:43 +00:00
|
|
|
'$undefined'(G, Module),
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(G,Name,Arity),
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(warning,no_match(abolish(Module:Name/Arity))).
|
2003-11-26 18:36:35 +00:00
|
|
|
'$abolishs'(G, M) :-
|
2014-10-10 10:00:27 +01:00
|
|
|
'$is_multifile'(G,M),
|
2003-11-26 18:36:35 +00:00
|
|
|
functor(G,Name,Arity),
|
2014-10-10 10:00:27 +01:00
|
|
|
recorded('$mf','$mf_clause'(_,Name,Arity,M,_Ref),R),
|
2003-11-26 18:36:35 +00:00
|
|
|
erase(R),
|
2014-10-10 10:00:27 +01:00
|
|
|
% no need erase(Ref),
|
2003-11-26 18:36:35 +00:00
|
|
|
fail.
|
2007-10-17 00:17:04 +01:00
|
|
|
'$abolishs'(T, M) :-
|
2007-12-05 12:17:25 +00:00
|
|
|
recorded('$import','$import'(_,M,_,_,T,_,_),R),
|
2007-10-17 00:17:04 +01:00
|
|
|
erase(R),
|
|
|
|
fail.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolishs'(G, M) :-
|
2003-11-21 16:56:20 +00:00
|
|
|
'$purge_clauses'(G, M), fail.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolishs'(_, _).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-07-27 01:14:15 +01:00
|
|
|
/** @pred stash_predicate(+ _Pred_) @anchor stash_predicate
|
|
|
|
Make predicate _Pred_ invisible to new code, and to `current_predicate/2`,
|
|
|
|
`listing`, and friends. New predicates with the same name and
|
|
|
|
functor can be declared.
|
|
|
|
**/
|
2015-07-23 01:31:03 +01:00
|
|
|
stash_predicate(P0) :-
|
|
|
|
strip_module(P0, M, P),
|
2012-11-25 23:36:43 +00:00
|
|
|
'$stash_predicate2'(P, M).
|
|
|
|
|
|
|
|
'$stash_predicate2'(V, M) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error,stash_predicate(M:V)).
|
|
|
|
'$stash_predicate2'(N/A, M) :- !,
|
|
|
|
functor(S,N,A),
|
|
|
|
'$stash_predicate'(S, M) .
|
|
|
|
'$stash_predicate2'(PredDesc, M) :-
|
|
|
|
'$do_error'(type_error(predicate_indicator,PredDesc),stash_predicate(M:PredDesc)).
|
|
|
|
|
2015-12-15 09:04:08 +00:00
|
|
|
/** @pred hide_predicate(+ _Pred_)
|
2014-07-27 01:14:15 +01:00
|
|
|
Make predicate _Pred_ invisible to `current_predicate/2`,
|
|
|
|
`listing`, and friends.
|
2012-11-25 23:36:43 +00:00
|
|
|
|
2014-07-27 01:14:15 +01:00
|
|
|
**/
|
2015-07-23 01:31:03 +01:00
|
|
|
hide_predicate(P0) :-
|
2016-01-04 14:11:09 +00:00
|
|
|
'$yap_strip_module'(P0, M, P),
|
|
|
|
must_be_of_type(callable, M:P),
|
|
|
|
'$hide_predicate'(P, M).
|
2002-08-14 17:00:54 +01:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred predicate_property( _P_, _Prop_) is iso
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
For the predicates obeying the specification _P_ unify _Prop_
|
2015-04-13 13:28:17 +01:00
|
|
|
with a property of _P_. These properties may be:
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
+ `built_in `
|
|
|
|
true for built-in predicates,
|
|
|
|
|
|
|
|
+ `dynamic`
|
|
|
|
true if the predicate is dynamic
|
|
|
|
|
|
|
|
+ `static `
|
|
|
|
true if the predicate is static
|
|
|
|
|
|
|
|
+ `meta_predicate( _M_) `
|
|
|
|
true if the predicate has a meta_predicate declaration _M_.
|
|
|
|
|
|
|
|
+ `multifile `
|
|
|
|
true if the predicate was declared to be multifile
|
|
|
|
|
|
|
|
+ `imported_from( _Mod_) `
|
|
|
|
true if the predicate was imported from module _Mod_.
|
|
|
|
|
|
|
|
+ `exported `
|
|
|
|
true if the predicate is exported in the current module.
|
|
|
|
|
|
|
|
+ `public`
|
|
|
|
true if the predicate is public; note that all dynamic predicates are
|
|
|
|
public.
|
|
|
|
|
|
|
|
+ `tabled `
|
|
|
|
true if the predicate is tabled; note that only static predicates can
|
|
|
|
be tabled in YAP.
|
|
|
|
|
|
|
|
+ `source (predicate_property flag) `
|
|
|
|
true if source for the predicate is available.
|
|
|
|
|
|
|
|
+ `number_of_clauses( _ClauseCount_) `
|
|
|
|
Number of clauses in the predicate definition. Always one if external
|
|
|
|
or built-in.
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
*/
|
|
|
|
predicate_property(Pred,Prop) :-
|
|
|
|
strip_module(Pred, Mod, TruePred),
|
|
|
|
'$predicate_property2'(TruePred,Prop,Mod).
|
|
|
|
|
|
|
|
'$predicate_property2'(Pred, Prop, Mod) :-
|
|
|
|
var(Mod), !,
|
|
|
|
'$all_current_modules'(Mod),
|
|
|
|
'$predicate_property2'(Pred, Prop, Mod).
|
|
|
|
'$predicate_property2'(Pred,Prop,M0) :-
|
|
|
|
var(Pred), !,
|
|
|
|
(M = M0 ;
|
2015-12-15 09:04:08 +00:00
|
|
|
M0 \= prolog, M = prolog ;
|
|
|
|
M0 \= user, M = user), % prolog and user modules are automatically incorporate in every other module
|
2002-12-13 20:00:41 +00:00
|
|
|
'$generate_all_preds_from_mod'(Pred, SourceMod, M),
|
|
|
|
'$predicate_property'(Pred,SourceMod,M,Prop).
|
|
|
|
'$predicate_property2'(M:Pred,Prop,_) :- !,
|
|
|
|
'$predicate_property2'(Pred,Prop,M).
|
2015-04-13 13:28:17 +01:00
|
|
|
'$predicate_property2'(Pred,Prop,Mod) :-
|
2002-12-13 20:00:41 +00:00
|
|
|
'$pred_exists'(Pred,Mod), !,
|
|
|
|
'$predicate_property'(Pred,Mod,Mod,Prop).
|
2015-04-13 13:28:17 +01:00
|
|
|
'$predicate_property2'(Pred,Prop,Mod) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$get_undefined_pred'(Pred, Mod, NPred, M),
|
2008-04-14 18:30:18 +01:00
|
|
|
(
|
|
|
|
Prop = imported_from(M)
|
|
|
|
;
|
2008-05-22 22:48:04 +01:00
|
|
|
'$predicate_property'(NPred,M,M,Prop),
|
2008-04-14 18:30:18 +01:00
|
|
|
Prop \= exported
|
|
|
|
).
|
2002-12-13 20:00:41 +00:00
|
|
|
|
|
|
|
'$generate_all_preds_from_mod'(Pred, M, M) :-
|
2015-12-15 09:04:08 +00:00
|
|
|
'$current_predicate'(_Na,M,Pred,_).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$generate_all_preds_from_mod'(Pred, SourceMod, Mod) :-
|
2013-11-25 22:09:03 +00:00
|
|
|
recorded('$import','$import'(SourceMod, Mod, Orig, Pred,_,_),_),
|
|
|
|
'$pred_exists'(Orig, SourceMod).
|
2002-12-13 20:00:41 +00:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
'$predicate_property'(P,M,_,built_in) :-
|
2016-01-03 02:06:09 +00:00
|
|
|
'$is_system_predicate'(P,M).
|
2015-04-13 13:28:17 +01:00
|
|
|
'$predicate_property'(P,M,_,source) :-
|
2015-06-19 01:12:05 +01:00
|
|
|
'$predicate_flags'(P,M,F,F),
|
2003-12-18 16:38:40 +00:00
|
|
|
F /\ 0x00400000 =\= 0.
|
2015-04-13 13:28:17 +01:00
|
|
|
'$predicate_property'(P,M,_,tabled) :-
|
2015-06-19 01:12:05 +01:00
|
|
|
'$predicate_flags'(P,M,F,F),
|
2003-12-18 16:38:40 +00:00
|
|
|
F /\ 0x00000040 =\= 0.
|
2002-12-13 20:00:41 +00:00
|
|
|
'$predicate_property'(P,M,_,dynamic) :-
|
|
|
|
'$is_dynamic'(P,M).
|
|
|
|
'$predicate_property'(P,M,_,static) :-
|
|
|
|
\+ '$is_dynamic'(P,M),
|
|
|
|
\+ '$undefined'(P,M).
|
2008-07-23 00:34:50 +01:00
|
|
|
'$predicate_property'(P,M,_,meta_predicate(Q)) :-
|
2002-12-13 20:00:41 +00:00
|
|
|
functor(P,Na,Ar),
|
2015-12-15 09:04:08 +00:00
|
|
|
prolog:'$meta_predicate'(Na,M,Ar,Q).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$predicate_property'(P,M,_,multifile) :-
|
|
|
|
'$is_multifile'(P,M).
|
|
|
|
'$predicate_property'(P,M,_,public) :-
|
|
|
|
'$is_public'(P,M).
|
2014-07-16 17:56:09 +01:00
|
|
|
'$predicate_property'(P,M,_,thread_local) :-
|
|
|
|
'$is_thread_local'(P,M).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$predicate_property'(P,M,M,exported) :-
|
|
|
|
functor(P,N,A),
|
2014-09-22 18:13:35 +01:00
|
|
|
once(recorded('$module','$module'(_TFN,M,_S,Publics,_L),_)),
|
2008-05-22 22:48:04 +01:00
|
|
|
lists:memberchk(N/A,Publics).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$predicate_property'(P,Mod,_,number_of_clauses(NCl)) :-
|
|
|
|
'$number_of_clauses'(P,Mod,NCl).
|
2013-11-25 22:09:03 +00:00
|
|
|
'$predicate_property'(P,Mod,_,file(F)) :-
|
2015-01-18 01:32:13 +00:00
|
|
|
'$owner_file'(P,Mod,F).
|
2002-12-13 20:00:41 +00:00
|
|
|
|
|
|
|
|
2014-11-28 02:32:35 +00:00
|
|
|
/**
|
|
|
|
@pred predicate_statistics( _P_, _NCls_, _Sz_, _IndexSz_)
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
Given predicate _P_, _NCls_ is the number of clauses for
|
|
|
|
_P_, _Sz_ is the amount of space taken to store those clauses
|
|
|
|
(in bytes), and _IndexSz_ is the amount of space required to store
|
|
|
|
indices to those clauses (in bytes).
|
|
|
|
*/
|
2003-11-12 12:33:31 +00:00
|
|
|
predicate_statistics(V,NCls,Sz,ISz) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error,predicate_statistics(V,NCls,Sz,ISz)).
|
2015-07-23 01:31:03 +01:00
|
|
|
predicate_statistics(P0,NCls,Sz,ISz) :-
|
|
|
|
strip_module(P0, M, P),
|
2003-11-12 12:33:31 +00:00
|
|
|
'$predicate_statistics'(P,M,NCls,Sz,ISz).
|
|
|
|
|
2006-10-10 21:21:42 +01:00
|
|
|
'$predicate_statistics'(M:P,_,NCls,Sz,ISz) :- !,
|
|
|
|
'$predicate_statistics'(P,M,NCls,Sz,ISz).
|
2003-11-12 12:33:31 +00:00
|
|
|
'$predicate_statistics'(P,M,NCls,Sz,ISz) :-
|
2006-10-10 21:21:42 +01:00
|
|
|
'$is_log_updatable'(P, M), !,
|
|
|
|
'$lu_statistics'(P,NCls,Sz,ISz,M).
|
2006-03-24 16:26:31 +00:00
|
|
|
'$predicate_statistics'(P,M,_,_,_) :-
|
2016-01-03 02:06:09 +00:00
|
|
|
'$is_system_predicate'(P,M), !, fail.
|
2006-03-24 16:26:31 +00:00
|
|
|
'$predicate_statistics'(P,M,_,_,_) :-
|
2003-11-12 12:33:31 +00:00
|
|
|
'$undefined'(P,M), !, fail.
|
|
|
|
'$predicate_statistics'(P,M,NCls,Sz,ISz) :-
|
|
|
|
'$static_pred_statistics'(P,M,NCls,Sz,ISz).
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred predicate_erased_statistics( _P_, _NCls_, _Sz_, _IndexSz_)
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
Given predicate _P_, _NCls_ is the number of erased clauses for
|
|
|
|
_P_ that could not be discarded yet, _Sz_ is the amount of space
|
|
|
|
taken to store those clauses (in bytes), and _IndexSz_ is the amount
|
|
|
|
of space required to store indices to those clauses (in bytes).
|
|
|
|
|
|
|
|
*/
|
2010-10-26 10:07:34 +01:00
|
|
|
predicate_erased_statistics(P,NCls,Sz,ISz) :-
|
2015-04-13 13:28:17 +01:00
|
|
|
var(P), !,
|
2010-10-26 10:07:34 +01:00
|
|
|
current_predicate(_,P),
|
|
|
|
predicate_erased_statistics(P,NCls,Sz,ISz).
|
2015-07-23 01:31:03 +01:00
|
|
|
predicate_erased_statistics(P0,NCls,Sz,ISz) :-
|
|
|
|
strip_module(P0,M,P),
|
2007-12-18 17:46:58 +00:00
|
|
|
'$predicate_erased_statistics'(M:P,NCls,Sz,_,ISz).
|
2008-02-07 22:34:45 +00:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred current_predicate( _A_, _P_)
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
Defines the relation: _P_ is a currently defined predicate whose name is the atom _A_.
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2015-07-23 01:31:03 +01:00
|
|
|
current_predicate(A,T0) :-
|
2015-08-07 22:57:53 +01:00
|
|
|
'$yap_strip_module'(T0, M, T),
|
2016-02-03 09:22:23 +00:00
|
|
|
(
|
|
|
|
'$current_predicate'(A,M, T, user)
|
2016-01-03 02:06:09 +00:00
|
|
|
;
|
2016-02-03 09:22:23 +00:00
|
|
|
'$imported_predicate'(T, M, T1, M1),
|
|
|
|
\+ '$is_system_predicate'(T1,M1)
|
2016-01-03 02:06:09 +00:00
|
|
|
).
|
2008-02-07 22:34:45 +00:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
/** @pred system_predicate( ?_P_ )
|
|
|
|
|
2015-11-12 14:54:01 +00:00
|
|
|
Defines the relation: indicator _P_ refers to a currently defined system predicate.
|
2014-11-25 12:03:48 +00:00
|
|
|
*/
|
2015-11-11 08:45:03 +00:00
|
|
|
system_predicate(P0) :-
|
2016-01-06 12:45:08 +00:00
|
|
|
'$yap_strip_module'(P0, M, P),
|
2015-11-12 14:54:01 +00:00
|
|
|
(
|
2016-01-31 10:21:10 +00:00
|
|
|
var(P)
|
2015-11-12 14:54:01 +00:00
|
|
|
->
|
2016-01-31 10:21:10 +00:00
|
|
|
P = A/Arity,
|
|
|
|
'$current_predicate'(A, M, T, system),
|
2016-01-03 02:06:09 +00:00
|
|
|
functor(T, A, Arity),
|
2016-01-31 10:21:10 +00:00
|
|
|
'$is_system_predicate'( T, M)
|
|
|
|
;
|
|
|
|
ground(P), P = A/Arity
|
|
|
|
->
|
|
|
|
functor(T, A, Arity),
|
|
|
|
'$current_predicate'(A, M, T, system),
|
2016-01-03 02:06:09 +00:00
|
|
|
'$is_system_predicate'( T, M)
|
2015-11-12 14:54:01 +00:00
|
|
|
;
|
2016-01-31 10:21:10 +00:00
|
|
|
ground(P), P = A//Arity2
|
2015-11-12 14:54:01 +00:00
|
|
|
->
|
2016-01-31 10:21:10 +00:00
|
|
|
Arity is Arity2+2,
|
2015-11-12 14:54:01 +00:00
|
|
|
functor(T, A, Arity),
|
2016-01-31 10:21:10 +00:00
|
|
|
'$current_predicate'(A, M, T, system),
|
2016-01-03 02:06:09 +00:00
|
|
|
'$is_system_predicate'( T, M)
|
2015-11-12 14:54:01 +00:00
|
|
|
;
|
|
|
|
P = A/Arity
|
|
|
|
->
|
2016-01-31 10:21:10 +00:00
|
|
|
'$current_predicate'(A, M, T, system),
|
2016-01-03 02:06:09 +00:00
|
|
|
'$is_system_predicate'( T, M),
|
2015-11-12 14:54:01 +00:00
|
|
|
functor(T, A, Arity)
|
2016-01-03 02:06:09 +00:00
|
|
|
;
|
|
|
|
P = A//Arity2
|
|
|
|
->
|
2016-01-31 10:21:10 +00:00
|
|
|
'$current_predicate'(A, M, T, system),
|
2016-01-03 02:06:09 +00:00
|
|
|
'$is_system_predicate'( T, M),
|
|
|
|
functor(T, A, Arity),
|
|
|
|
Arity >= 2,
|
|
|
|
Arity2 is Arity-2
|
2015-11-12 14:54:01 +00:00
|
|
|
;
|
|
|
|
'$do_error'(type_error(predicate_indicator,P),
|
|
|
|
system_predicate(P0))
|
|
|
|
).
|
2008-02-07 22:34:45 +00:00
|
|
|
|
|
|
|
|
2014-11-28 02:32:35 +00:00
|
|
|
/**
|
|
|
|
@pred current_predicate( _F_) is iso
|
2014-09-11 20:06:57 +01:00
|
|
|
|
2014-11-28 02:32:35 +00:00
|
|
|
True if _F_ is the predicate indicator for a currently defined user or
|
2015-01-18 01:32:13 +00:00
|
|
|
library predicate.The indicator _F_ is of the form _Mod_:_Na_/_Ar_ or _Na/Ar_,
|
2014-11-28 02:32:35 +00:00
|
|
|
where the atom _Mod_ is the module of the predicate,
|
2015-01-18 01:32:13 +00:00
|
|
|
_Na_ is the name of the predicate, and _Ar_ its arity.
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2013-11-25 22:57:05 +00:00
|
|
|
current_predicate(F0) :-
|
2015-11-05 17:26:50 +00:00
|
|
|
'$yap_strip_module'(F0, M, F),
|
|
|
|
(var(F) ->
|
2016-02-03 09:22:23 +00:00
|
|
|
F = A/N,
|
2016-01-06 12:45:08 +00:00
|
|
|
current_predicate(A, M:S),
|
2016-02-03 09:22:23 +00:00
|
|
|
functor(S, A, N)
|
2015-07-23 01:31:03 +01:00
|
|
|
;
|
2015-11-05 17:26:50 +00:00
|
|
|
(
|
|
|
|
functor(F,AN,2)
|
|
|
|
->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
'$do_error'(type_error(predicate_indicator,F0),
|
|
|
|
current_predicate(F0))
|
|
|
|
),
|
|
|
|
arg(1,F,A),
|
|
|
|
(atom(A) -> true ;
|
|
|
|
var(A) -> true ;
|
|
|
|
'$do_error'(type_error(predicate_indicator,F0),current_predicate(F0))
|
|
|
|
),
|
|
|
|
arg(2,F,N),
|
|
|
|
(integer(N) -> true ;
|
|
|
|
var(N) -> true ;
|
|
|
|
'$do_error'(type_error(predicate_indicator,F0),current_predicate(F0))
|
|
|
|
),
|
|
|
|
( AN == '/'
|
|
|
|
->
|
|
|
|
current_predicate(A, M:S),
|
|
|
|
functor( S, A, N)
|
|
|
|
;
|
|
|
|
AN == '//'
|
|
|
|
->
|
|
|
|
current_predicate(A, M:S),
|
|
|
|
Ar2 is N+2,
|
|
|
|
functor( S, A, Ar2)
|
|
|
|
;
|
|
|
|
'$do_error'(type_error(predicate_indicator,F0),current_predicate(F0))
|
|
|
|
)
|
2015-07-23 01:31:03 +01:00
|
|
|
).
|
2014-11-25 12:03:48 +00:00
|
|
|
|
2015-11-05 17:26:50 +00:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
'$imported_predicate'(A, ImportingMod, A/Arity, G, Flags) :-
|
|
|
|
'$get_undefined_pred'(G, ImportingMod, G0, ExportingMod),
|
|
|
|
functor(G, A, Arity),
|
|
|
|
'$pred_exists'(G, ExportingMod),
|
2015-06-19 01:12:05 +01:00
|
|
|
'$predicate_flags'(G0, ExportingMod, Flags, Flags).
|
2008-02-07 22:34:45 +00:00
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred current_key(? _A_,? _K_)
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
Defines the relation: _K_ is a currently defined database key whose
|
|
|
|
name is the atom _A_. It can be used to generate all the keys for
|
2014-11-25 12:03:48 +00:00
|
|
|
the internal data-base.
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2008-02-07 22:34:45 +00:00
|
|
|
current_key(A,K) :-
|
2015-07-23 01:31:03 +01:00
|
|
|
'$current_predicate'(A,idb,K,user).
|
2008-02-07 22:34:45 +00:00
|
|
|
|
2008-02-12 17:03:59 +00:00
|
|
|
% do nothing for now.
|
2008-02-22 15:08:37 +00:00
|
|
|
'$noprofile'(_, _).
|
|
|
|
|
2008-09-15 04:30:09 +01:00
|
|
|
'$ifunctor'(Pred,Na,Ar) :-
|
|
|
|
(Ar > 0 ->
|
|
|
|
functor(Pred, Na, Ar)
|
|
|
|
;
|
|
|
|
Pred = Na
|
|
|
|
).
|
2011-10-21 23:02:07 +01:00
|
|
|
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
/** @pred compile_predicates(: _ListOfNameArity_)
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Compile a list of specified dynamic predicates (see dynamic/1 and
|
|
|
|
assert/1 into normal static predicates. This call tells the
|
|
|
|
Prolog environment the definition will not change anymore and further
|
|
|
|
calls to assert/1 or retract/1 on the named predicates
|
|
|
|
raise a permission error. This predicate is designed to deal with parts
|
|
|
|
of the program that is generated at runtime but does not change during
|
|
|
|
the remainder of the program execution.
|
|
|
|
*/
|
2011-10-21 23:02:07 +01:00
|
|
|
compile_predicates(Ps) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$compile_predicates'(Ps, Mod, compile_predicates(Ps)).
|
|
|
|
|
|
|
|
'$compile_predicates'(V, _, Call) :-
|
|
|
|
var(V), !,
|
|
|
|
'$do_error'(instantiation_error,Call).
|
|
|
|
'$compile_predicates'(M:Ps, _, Call) :-
|
|
|
|
'$compile_predicates'(Ps, M, Call).
|
|
|
|
'$compile_predicates'([], _, _).
|
2014-10-07 01:35:41 +01:00
|
|
|
'$compile_predicates'([P|Ps], M, Call) :-
|
|
|
|
'$compile_predicate'(P, M, Call),
|
2011-10-21 23:02:07 +01:00
|
|
|
'$compile_predicates'(Ps, M, Call).
|
|
|
|
|
2014-10-07 01:35:41 +01:00
|
|
|
'$compile_predicate'(P, _M, Call) :-
|
2011-10-21 23:02:07 +01:00
|
|
|
var(P), !,
|
|
|
|
'$do_error'(instantiation_error,Call).
|
|
|
|
'$compile_predicate'(M:P, _, Call) :-
|
|
|
|
'$compile_predicate'(P, M, Call).
|
|
|
|
'$compile_predicate'(Na/Ar, Mod, _Call) :-
|
|
|
|
functor(G, Na, Ar),
|
|
|
|
findall((G.B),clause(Mod:G,B),Cls),
|
|
|
|
abolish(Mod:Na,Ar),
|
|
|
|
'$add_all'(Cls, Mod).
|
|
|
|
|
|
|
|
'$add_all'([], _).
|
|
|
|
'$add_all'((G.B).Cls, Mod) :-
|
|
|
|
assert_static(Mod:(G:-B)),
|
|
|
|
'$add_all'(Cls, Mod).
|
|
|
|
|
2013-11-05 17:59:19 +00:00
|
|
|
|
|
|
|
clause_property(ClauseRef, file(FileName)) :-
|
2013-11-26 09:40:00 +00:00
|
|
|
( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R)
|
|
|
|
-> true
|
|
|
|
;
|
2015-09-25 10:57:26 +01:00
|
|
|
instance_property(ClauseRef, 2, FileName) ).
|
2013-11-05 17:59:19 +00:00
|
|
|
clause_property(ClauseRef, source(FileName)) :-
|
2013-11-26 09:40:00 +00:00
|
|
|
( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R)
|
|
|
|
-> true
|
|
|
|
;
|
2015-09-25 10:57:26 +01:00
|
|
|
instance_property(ClauseRef, 2, FileName) ).
|
2013-11-05 17:59:19 +00:00
|
|
|
clause_property(ClauseRef, line_count(LineNumber)) :-
|
2015-09-25 10:57:26 +01:00
|
|
|
instance_property(ClauseRef, 4, LineNumber),
|
2013-11-05 17:59:19 +00:00
|
|
|
LineNumber > 0.
|
|
|
|
clause_property(ClauseRef, fact) :-
|
2015-09-25 10:57:26 +01:00
|
|
|
instance_property(ClauseRef, 3, true).
|
2013-11-05 17:59:19 +00:00
|
|
|
clause_property(ClauseRef, erased) :-
|
2015-09-25 10:57:26 +01:00
|
|
|
instance_property(ClauseRef, 0, true).
|
2013-11-05 17:59:19 +00:00
|
|
|
clause_property(ClauseRef, predicate(PredicateIndicator)) :-
|
2015-09-25 10:57:26 +01:00
|
|
|
instance_property(ClauseRef, 1, PredicateIndicator).
|
2013-11-25 11:16:10 +00:00
|
|
|
|
|
|
|
'$set_predicate_attribute'(M:N/Ar, Flag, V) :-
|
|
|
|
functor(P, N, Ar),
|
|
|
|
'$set_flag'(P, M, Flag, V).
|
|
|
|
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/**
|
|
|
|
@}
|
|
|
|
*/
|