2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* 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 *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @defgroup Database Using the Clausal Data Base
|
|
|
|
@ingroup YAPBuiltins
|
|
|
|
@{
|
|
|
|
|
|
|
|
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.
|
|
|
|
Static predicates impose some restrictions: in general there can be no
|
|
|
|
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
|
|
|
|
aware of the fact that asserting or retracting are still expensive operations,
|
|
|
|
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,
|
|
|
|
'$handle_throw'/3,
|
|
|
|
'$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]).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
% The next predicates are applicable only
|
|
|
|
% to dynamic code
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred asserta(+ _C_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
Adds clause _C_ to the beginning of the program. If the predicate is
|
|
|
|
undefined, declare it as dynamic.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
asserta(Mod:C) :- !,
|
|
|
|
'$assert'(C,Mod,first,_,asserta(Mod:C)).
|
2001-11-15 00:01:43 +00:00
|
|
|
asserta(C) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$assert'(C,Mod,first,_,asserta(C)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred assertz(+ _C_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
Adds clause _C_ to the end of the program. If the predicate is
|
|
|
|
undefined, declare it as dynamic.
|
|
|
|
|
|
|
|
Most Prolog systems only allow asserting clauses for dynamic
|
|
|
|
predicates. This is also as specified in the ISO standard. YAP allows
|
|
|
|
asserting clauses for static predicates. The current version of YAP
|
|
|
|
supports this feature, but this feature is deprecated and support may go
|
|
|
|
away in future versions.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
assertz(Mod:C) :- !,
|
|
|
|
'$assert'(C,Mod,last,_,assertz(Mod:C)).
|
2001-11-15 00:01:43 +00:00
|
|
|
assertz(C) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$assert'(C,Mod,last,_,assertz(C)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred assert(+ _C_)
|
|
|
|
|
|
|
|
|
|
|
|
Same as assertz/1. Adds clause _C_ to the program. If the predicate is undefined,
|
|
|
|
declare it as dynamic. New code should use assertz/1 for better portability.
|
|
|
|
|
|
|
|
Most Prolog systems only allow asserting clauses for dynamic
|
|
|
|
predicates. This is also as specified in the ISO standard. YAP allows
|
|
|
|
asserting clauses for static predicates, as long as the predicate is not
|
|
|
|
in use and the language flag is <tt>cprolog</tt>. Note that this feature is
|
|
|
|
deprecated, if you want to assert clauses for static procedures you
|
|
|
|
should use assert_static/1.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
assert(Mod:C) :- !,
|
|
|
|
'$assert'(C,Mod,last,_,assert(Mod:C)).
|
2001-11-15 00:01:43 +00:00
|
|
|
assert(C) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$assert'(C,Mod,last,_,assert(C)).
|
|
|
|
|
|
|
|
'$assert'(V,Mod,_,_,_) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,assert(Mod:V)).
|
2007-04-10 23:13:21 +01:00
|
|
|
'$assert'(V,Mod,_,_,_) :- var(Mod), !,
|
|
|
|
'$do_error'(instantiation_error,assert(Mod:V)).
|
2010-02-26 10:22:41 +00:00
|
|
|
'$assert'(I,Mod,_,_,_) :- number(I), !,
|
2014-10-20 09:20:56 +01:00
|
|
|
'$do_error'(type_error(callable,I),assert(Mod:I)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assert'(M:C,_,Where,R,P) :- !,
|
|
|
|
'$assert'(C,M,Where,R,P).
|
2003-08-27 14:37:10 +01:00
|
|
|
'$assert'((H:-G),M1,Where,R,P) :- !,
|
|
|
|
'$assert_clause'(H, G, M1, Where, R, P).
|
|
|
|
'$assert'(H,M1,Where,R,_) :-
|
2008-08-06 01:56:11 +01:00
|
|
|
strip_module(M1:H, HM, H1),
|
|
|
|
'$assert_fact'(H1, HM, Where, R).
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
'$assert_clause'(H, _, _, _, _, P) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
var(H), !, '$do_error'(instantiation_error,P).
|
|
|
|
'$assert_clause'(M1:C, G, M1, Where, R, P) :- !,
|
|
|
|
'$assert_clause2'(C, G, M1, Where, R, P).
|
|
|
|
'$assert_clause'(H, G, M1, Where, R, P) :- !,
|
|
|
|
'$assert_clause2'(H, G, M1, Where, R, P).
|
|
|
|
|
|
|
|
'$assert_fact'(H,Mod,Where,R) :-
|
2012-03-22 21:43:26 +00:00
|
|
|
( '$is_log_updatable'(H, Mod) ->
|
|
|
|
'$compile_dynamic'(H, Where, H, Mod, R)
|
|
|
|
;
|
|
|
|
'$is_dynamic'(H, Mod) ->
|
2003-08-27 14:37:10 +01:00
|
|
|
'$assertat_d'(Where, H, true, H, Mod, R)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2003-08-27 14:37:10 +01:00
|
|
|
'$undefined'(H,Mod) ->
|
|
|
|
functor(H, Na, Ar),
|
|
|
|
'$dynamic'(Na/Ar, Mod),
|
|
|
|
'$assert_fact'(H,Mod,Where,R)
|
|
|
|
;
|
|
|
|
'$access_yap_flags'(14, 1) -> % I can assert over static facts in YAP mode
|
|
|
|
'$assert1'(Where,H,H,Mod,H)
|
|
|
|
;
|
|
|
|
functor(H, Na, Ar),
|
2006-03-24 16:26:31 +00:00
|
|
|
'$do_error'(permission_error(modify,static_procedure,Na/Ar),Mod:assert(H))
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
'$assert_clause2'(HI,BI,Mod,Where,R,P) :-
|
2008-08-06 01:56:11 +01:00
|
|
|
'$expand_clause'((HI :- BI),C0,C,Mod,HM),
|
|
|
|
'$assert_clause3'(C0,C,HM,Where,R,P).
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
'$assert_clause3'(C0,C,Mod,Where,R,P) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_head_and_body'(C,H,B,P),
|
2003-08-27 14:37:10 +01:00
|
|
|
( '$is_log_updatable'(H, Mod) ->
|
2005-01-28 23:14:41 +00:00
|
|
|
'$compile_dynamic'((H :- B), Where, C0, Mod, R)
|
2003-08-27 14:37:10 +01:00
|
|
|
;
|
|
|
|
'$is_dynamic'(H, Mod) ->
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assertat_d'(Where, H, B, C0, Mod, R)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2001-11-15 00:01:43 +00:00
|
|
|
'$undefined'(H,Mod) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(H, Na, Ar),
|
2001-11-15 19:01:41 +00:00
|
|
|
'$dynamic'(Na/Ar, Mod),
|
2003-08-27 14:37:10 +01:00
|
|
|
'$assert_clause3'(C0,C,Mod,Where,R,P)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
'$access_yap_flags'(14, 1) -> % I can assert over static facts in YAP mode
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assert1'(Where,C,C0,Mod,H)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
functor(H, Na, Ar),
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(modify,static_procedure,Na/Ar),P)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assert_dynamic'(V,Mod,_,_,_) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,assert(Mod:V)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assert_dynamic'(M:C,_,Where,R,P) :- !,
|
2001-12-12 20:08:12 +00:00
|
|
|
'$assert_dynamic'(C,M,Where,R,P).
|
2014-10-07 01:35:41 +01:00
|
|
|
'$assert_dynamic'((H:-_G),_M1,_Where,_R,P) :-
|
2008-07-23 00:34:50 +01:00
|
|
|
var(H), !, '$do_error'(instantiation_error,P).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assert_dynamic'(CI,Mod,Where,R,P) :-
|
2008-08-06 01:56:11 +01:00
|
|
|
'$expand_clause'(CI,C0,C,Mod,HM),
|
|
|
|
'$assert_dynamic2'(C0,C,HM,Where,R,P).
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
'$assert_dynamic2'(C0,C,Mod,Where,R,P) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_head_and_body'(C,H,B,P),
|
2003-08-27 14:37:10 +01:00
|
|
|
( '$is_log_updatable'(H, Mod) ->
|
2005-01-28 23:14:41 +00:00
|
|
|
'$compile_dynamic'(C, Where, C0, Mod, R)
|
2003-08-27 14:37:10 +01:00
|
|
|
;
|
|
|
|
'$is_dynamic'(H, Mod) ->
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assertat_d'(Where,H,B,C0,Mod,R)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2001-11-15 00:01:43 +00:00
|
|
|
'$undefined'(H, Mod) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(H, Na, Ar),
|
2001-11-15 19:01:41 +00:00
|
|
|
'$dynamic'(Na/Ar, Mod),
|
2003-08-27 14:37:10 +01:00
|
|
|
'$assert_dynamic2'(C0,C,Mod,Where,R,P)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
functor(H,Na,Ar),
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(modify,static_procedure,Na/Ar),P)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred assert_static(: _C_)
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
assert_static(Mod:C) :- !,
|
|
|
|
'$assert_static'(C,Mod,last,_,assert_static(Mod:C)).
|
2001-11-15 00:01:43 +00:00
|
|
|
assert_static(C) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$assert_static'(C,Mod,last,_,assert_static(C)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred asserta_static(: _C_)
|
|
|
|
|
|
|
|
|
|
|
|
Adds clause _C_ to the beginning of a static procedure.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
asserta_static(Mod:C) :- !,
|
|
|
|
'$assert_static'(C,Mod,first,_,asserta_static(Mod:C)).
|
2001-11-15 00:01:43 +00:00
|
|
|
asserta_static(C) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$assert_static'(C,Mod,first,_,asserta_static(C)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-10-14 17:25:38 +01:00
|
|
|
asserta_static(Mod:C) :- !,
|
|
|
|
'$assert_static'(C,Mod,last,_,assertz_static(Mod:C)).
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred assertz_static(: _C_)
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2001-04-09 20:54:03 +01:00
|
|
|
assertz_static(C) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
'$current_module'(Mod),
|
|
|
|
'$assert_static'(C,Mod,last,_,assertz_static(C)).
|
|
|
|
|
|
|
|
'$assert_static'(V,M,_,_,_) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,assert(M:V)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assert_static'(M:C,_,Where,R,P) :- !,
|
|
|
|
'$assert_static'(C,M,Where,R,P).
|
2014-10-07 01:35:41 +01:00
|
|
|
'$assert_static'((H:-_G),_M1,_Where,_R,P) :-
|
2008-07-23 00:34:50 +01:00
|
|
|
var(H), !, '$do_error'(instantiation_error,P).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assert_static'(CI,Mod,Where,R,P) :-
|
2008-08-06 01:56:11 +01:00
|
|
|
'$expand_clause'(CI,C0,C,Mod, HM),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_head_and_body'(C,H,B,P),
|
2008-08-06 01:56:11 +01:00
|
|
|
( '$is_dynamic'(H, HM) ->
|
|
|
|
'$do_error'(permission_error(modify,dynamic_procedure,HM:Na/Ar),P)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2008-08-06 01:56:11 +01:00
|
|
|
'$undefined'(H,HM), get_value('$full_iso',true) ->
|
|
|
|
functor(H,Na,Ar), '$dynamic'(Na/Ar, HM), '$assertat_d'(Where,H,B,C0,HM,R)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
2008-08-06 01:56:11 +01:00
|
|
|
'$assert1'(Where,C,C0,HM,H)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
|
|
|
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assertat_d'(first,Head,Body,C0,Mod,R) :- !,
|
2005-01-28 23:14:41 +00:00
|
|
|
'$compile_dynamic'((Head:-Body), first, C0, Mod, CR),
|
2003-08-27 14:37:10 +01:00
|
|
|
( get_value('$abol',true)
|
2001-04-09 20:54:03 +01:00
|
|
|
->
|
2002-06-11 06:30:47 +01:00
|
|
|
'$flags'(Head,Mod,Fl,Fl),
|
2003-12-04 18:12:26 +00:00
|
|
|
( Fl /\ 0x20000000 =\= 0 -> '$check_multifile_pred'(Head,Mod,Fl) ; true )
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
|
|
|
'$head_and_body'(C0, H0, B0),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$recordap'(Mod:Head,(H0 :- B0),R,CR),
|
|
|
|
( '$is_multifile'(Head, Mod) ->
|
2014-08-04 15:45:30 +01:00
|
|
|
source_location(F, _),
|
2001-11-15 00:01:43 +00:00
|
|
|
functor(H0, Na, Ar),
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$multifile_dynamic'(_,_,_), '$mf'(Na,Ar,Mod,F,R), _)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assertat_d'(last,Head,Body,C0,Mod,R) :-
|
2005-01-28 23:14:41 +00:00
|
|
|
'$compile_dynamic'((Head:-Body), last, C0, Mod, CR),
|
2003-08-27 14:37:10 +01:00
|
|
|
( get_value('$abol',true)
|
2001-04-09 20:54:03 +01:00
|
|
|
->
|
2002-06-11 06:30:47 +01:00
|
|
|
'$flags'(Head,Mod,Fl,Fl),
|
2003-12-04 18:12:26 +00:00
|
|
|
( Fl /\ 0x20000000 =\= 0 -> '$check_multifile_pred'(Head,Mod,Fl) ; true )
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
|
|
|
'$head_and_body'(C0, H0, B0),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$recordzp'(Mod:Head,(H0 :- B0),R,CR),
|
|
|
|
( '$is_multifile'(H0, Mod) ->
|
2013-11-04 01:14:48 +00:00
|
|
|
source_location(F, _),
|
2001-11-15 00:01:43 +00:00
|
|
|
functor(H0, Na, Ar),
|
2003-08-27 14:37:10 +01:00
|
|
|
recordz('$multifile_dynamic'(_,_,_), '$mf'(Na,Ar,Mod,F,R), _)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
'$assert1'(last,C,C0,Mod,_) :- '$compile'(C,0,C0,Mod).
|
|
|
|
'$assert1'(first,C,C0,Mod,_) :- '$compile'(C,2,C0,Mod).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assertz_dynamic'(X, C, C0, Mod) :- (X/\4)=:=0, !,
|
2001-04-09 20:54:03 +01:00
|
|
|
'$head_and_body'(C,H,B),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assertat_d'(last,H,B,C0,Mod,_).
|
|
|
|
'$assertz_dynamic'(X,C,C0,Mod) :-
|
2010-12-13 22:03:54 +00:00
|
|
|
'$head_and_body'(C,H,B),
|
|
|
|
functor(H,N,A),
|
2001-09-27 15:01:16 +01:00
|
|
|
('$check_if_reconsulted'(N,A) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
true
|
|
|
|
;
|
2001-09-27 15:01:16 +01:00
|
|
|
(X/\8)=:=0 ->
|
2001-04-09 20:54:03 +01:00
|
|
|
'$inform_as_reconsulted'(N,A),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$remove_all_d_clauses'(H,Mod)
|
2001-09-27 15:01:16 +01:00
|
|
|
;
|
|
|
|
true
|
2001-04-09 20:54:03 +01:00
|
|
|
),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$assertat_d'(last,H,B,C0,Mod,_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$remove_all_d_clauses'(H,M) :-
|
|
|
|
'$is_multifile'(H, M), !,
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(H, Na, A),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$erase_all_mf_dynamic'(Na,A,M).
|
|
|
|
'$remove_all_d_clauses'(H,M) :-
|
|
|
|
'$recordedp'(M:H,_,R), erase(R), fail.
|
|
|
|
'$remove_all_d_clauses'(_,_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$erase_all_mf_dynamic'(Na,A,M) :-
|
2013-11-04 01:14:48 +00:00
|
|
|
source_location( F , _),
|
2010-09-28 01:01:37 +01:00
|
|
|
recorded('$multifile_dynamic'(_,_,_), '$mf'(Na,A,M,F,R), R1),
|
2001-04-09 20:54:03 +01:00
|
|
|
erase(R1),
|
|
|
|
erase(R),
|
|
|
|
fail.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$erase_all_mf_dynamic'(_,_,_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred asserta(+ _C_,- _R_)
|
|
|
|
|
|
|
|
The same as `asserta(C)` but unifying _R_ with
|
|
|
|
the database reference that identifies the new clause, in a
|
|
|
|
one-to-one way. Note that `asserta/2` only works for dynamic
|
|
|
|
predicates. If the predicate is undefined, it will automatically be
|
|
|
|
declared dynamic.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
asserta(M:C,R) :- !,
|
|
|
|
'$assert_dynamic'(C,M,first,R,asserta(M:C,R)).
|
2001-11-15 00:01:43 +00:00
|
|
|
asserta(C,R) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$assert_dynamic'(C,M,first,R,asserta(C,R)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred assertz(+ _C_,- _R_)
|
|
|
|
|
|
|
|
The same as `assertz(C)` but unifying _R_ with
|
|
|
|
the database reference that identifies the new clause, in a
|
|
|
|
one-to-one way. Note that `asserta/2` only works for dynamic
|
|
|
|
predicates. If the predicate is undefined, it will automatically be
|
|
|
|
declared dynamic.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
assertz(M:C,R) :- !,
|
|
|
|
'$assert_dynamic'(C,M,last,R,assertz(M:C,R)).
|
2001-11-15 00:01:43 +00:00
|
|
|
assertz(C,R) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$assert_dynamic'(C,M,last,R,assertz(C,R)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred assert(+ _C_,- _R_)
|
|
|
|
|
|
|
|
The same as `assert(C)` ( (see Modifying the Database)) but
|
|
|
|
unifies _R_ with the database reference that identifies the new
|
|
|
|
clause, in a one-to-one way. Note that `asserta/2` only works for dynamic
|
|
|
|
predicates. If the predicate is undefined, it will automatically be
|
|
|
|
declared dynamic.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
assert(M:C,R) :- !,
|
|
|
|
'$assert_dynamic'(C,M,last,R,assert(M:C,R)).
|
2001-11-15 00:01:43 +00:00
|
|
|
assert(C,R) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$assert_dynamic'(C,M,last,R,assert(C,R)).
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred clause(+ _H_, _B_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-09-23 14:43:47 +01:00
|
|
|
clause(M:P,Q) :- !,
|
2002-12-13 20:00:41 +00:00
|
|
|
'$clause'(P,M,Q,_).
|
2001-11-15 00:01:43 +00:00
|
|
|
clause(V,Q) :-
|
|
|
|
'$current_module'(M),
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2003-10-30 11:31:05 +00:00
|
|
|
clause(P,Q,R) :- var(P), !,
|
|
|
|
'$current_module'(M),
|
|
|
|
'$clause'(P,M,Q,R).
|
2002-12-13 20:00:41 +00:00
|
|
|
clause(M:P,Q,R) :- !,
|
|
|
|
'$clause'(P,M,Q,R).
|
|
|
|
clause(V,Q,R) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$clause'(V,M,Q,R).
|
|
|
|
|
2003-10-30 11:31:05 +00:00
|
|
|
'$clause'(P,M,Q,R) :-
|
|
|
|
'$instance_module'(R,M0), !,
|
|
|
|
M0 = M,
|
|
|
|
instance(R,T),
|
|
|
|
( T = (H :- B) -> P = H, Q = B ; P=T, Q = true).
|
2004-04-27 16:03:43 +01:00
|
|
|
'$clause'(V,M,Q,R) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error,clause(M:V,Q,R)).
|
2013-01-11 16:45:14 +00:00
|
|
|
'$clause'(C,M,Q,R) :-
|
|
|
|
number(C), !,
|
2014-10-20 09:20:56 +01:00
|
|
|
'$do_error'(type_error(callable,C),clause(M:C,Q,R)).
|
2013-01-11 16:45:14 +00:00
|
|
|
'$clause'(C,M,Q,R) :-
|
|
|
|
db_reference(C), !,
|
2014-10-20 09:20:56 +01:00
|
|
|
'$do_error'(type_error(callable,C),clause(M:R,Q,R)).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$clause'(M:P,_,Q,R) :- !,
|
|
|
|
'$clause'(P,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-11-21 16:56:20 +00:00
|
|
|
'$clause'(P,M,Q,R) :-
|
|
|
|
'$is_source'(P, M), !,
|
|
|
|
'$static_clause'(P,M,Q,R).
|
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).
|
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),
|
2002-01-08 05:22:40 +00:00
|
|
|
( '$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
|
|
|
|
2011-08-31 21:59:30 +01:00
|
|
|
'$init_preds' :-
|
|
|
|
once('$handle_throw'(_,_,_)),
|
|
|
|
fail.
|
|
|
|
'$init_preds' :-
|
|
|
|
once('$do_static_clause'(_,_,_,_,_)),
|
|
|
|
fail.
|
|
|
|
'$init_preds' :-
|
|
|
|
once('$do_log_upd_clause0'(_,_,_,_,_,_)),
|
|
|
|
fail.
|
|
|
|
'$init_preds' :-
|
|
|
|
once('$do_log_upd_clause'(_,_,_,_,_,_)),
|
|
|
|
fail.
|
|
|
|
'$init_preds' :-
|
|
|
|
once('$do_log_upd_clause_erase'(_,_,_,_,_,_)),
|
|
|
|
fail.
|
|
|
|
'$init_preds'.
|
|
|
|
|
|
|
|
:- '$init_preds'.
|
2003-11-26 18:36:35 +00:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred nth_clause(+ _H_, _I_,- _R_)
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following predicates can only be used for dynamic predicates:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-12-13 20:00:41 +00:00
|
|
|
nth_clause(V,I,R) :-
|
2002-09-23 14:43:47 +01:00
|
|
|
'$current_module'(M),
|
2013-12-09 14:16:30 +00:00
|
|
|
strip_module(M:V, M1, P), !,
|
|
|
|
'$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 retract(+ _C_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
Erases the first clause in the program that matches _C_. This
|
|
|
|
predicate may also be used for the static predicates that have been
|
|
|
|
compiled when the source mode was `on`. For more information on
|
|
|
|
source/0 ( (see Setting the Compiler)).
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
retract(M:C) :- !,
|
|
|
|
'$retract'(C,M).
|
2001-11-15 00:01:43 +00:00
|
|
|
retract(C) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$retract'(C,M).
|
|
|
|
|
|
|
|
|
|
|
|
'$retract'(V,_) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,retract(V)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$retract'(M:C,_) :- !,
|
|
|
|
'$retract'(C,M).
|
|
|
|
'$retract'(C,M) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
'$check_head_and_body'(C,H,B,retract(M:C)), !,
|
2008-01-23 17:57:56 +00:00
|
|
|
'$flags'(H, M, F, F),
|
|
|
|
'$retract2'(F, H,M,B,_).
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2008-01-23 17:57:56 +00:00
|
|
|
'$retract2'(F, H, M, B, R) :-
|
|
|
|
F /\ 0x08000000 =:= 0x08000000, !,
|
|
|
|
% '$is_log_updatable'(H, M), !,
|
2003-11-18 19:23:10 +00:00
|
|
|
'$log_update_clause'(H,M,B,R),
|
2008-01-23 17:57:56 +00:00
|
|
|
( F /\ 0x20000000 =:= 0x20000000, recorded('$mf','$mf_clause'(_,_,_,_,R),MR), erase(MR), fail ; true),
|
|
|
|
erase(R).
|
|
|
|
'$retract2'(F, H, M, B, R) :-
|
|
|
|
% '$is_dynamic'(H,M), !,
|
|
|
|
F /\ 0x00002000 =:= 0x00002000, !,
|
|
|
|
'$recordedp'(M:H,(H:-B),R),
|
2014-10-07 01:35:41 +01:00
|
|
|
( F /\ 0x20000000 =:= 0x20000000, recorded('$mf','$mf_clause'(_,_,_,_,MRef),MR), erase(MR), erase(MRef), fail ; true),
|
2003-11-18 19:23:10 +00:00
|
|
|
erase(R).
|
2008-01-23 17:57:56 +00:00
|
|
|
'$retract2'(_, H,M,_,_) :-
|
2002-06-11 06:30:47 +01:00
|
|
|
'$undefined'(H,M), !,
|
|
|
|
functor(H,Na,Ar),
|
|
|
|
'$dynamic'(Na/Ar,M),
|
|
|
|
fail.
|
2008-01-23 17:57:56 +00:00
|
|
|
'$retract2'(_, H,M,B,_) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
functor(H,Na,Ar),
|
|
|
|
'$do_error'(permission_error(modify,static_procedure,Na/Ar),retract(M:(H:-B))).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred retract(+ _C_,- _R_)
|
|
|
|
|
|
|
|
Erases from the program the clause _C_ whose
|
|
|
|
database reference is _R_. The predicate must be dynamic.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2002-10-14 17:25:38 +01:00
|
|
|
retract(M:C,R) :- !,
|
|
|
|
'$retract'(C,M,R).
|
|
|
|
retract(C,R) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
'$current_module'(M),
|
|
|
|
'$retract'(C,M,R).
|
|
|
|
|
|
|
|
'$retract'(V,M,R) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,retract(M:V,R)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$retract'(M:C,_,R) :- !,
|
|
|
|
'$retract'(C,M,R).
|
|
|
|
'$retract'(C, M, R) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_head_and_body'(C,H,B,retract(C,R)),
|
2001-11-15 00:01:43 +00:00
|
|
|
db_reference(R), '$is_dynamic'(H,M), !,
|
2001-04-09 20:54:03 +01:00
|
|
|
instance(R,(H:-B)), erase(R).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$retract'(C,M,R) :-
|
2002-06-12 17:48:35 +01:00
|
|
|
'$check_head_and_body'(C,H,B,retract(C,R)),
|
2008-01-23 17:57:56 +00:00
|
|
|
var(R), !,
|
|
|
|
'$retract2'(H, M, B, R).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$retract'(C,M,_) :-
|
2001-10-30 16:42:05 +00:00
|
|
|
'$fetch_predicate_indicator_from_clause'(C, PI),
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(permission_error(modify,static_procedure,PI),retract(M:C)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$fetch_predicate_indicator_from_clause'((C :- _), Na/Ar) :- !,
|
|
|
|
functor(C, Na, Ar).
|
|
|
|
'$fetch_predicate_indicator_from_clause'(C, Na/Ar) :-
|
|
|
|
functor(C, Na, Ar).
|
|
|
|
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred retractall(+ _G_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
Retract all the clauses whose head matches the goal _G_. Goal
|
|
|
|
_G_ must be a call to a dynamic predicate.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2003-02-12 13:18:01 +00:00
|
|
|
retractall(M:V) :- !,
|
2002-10-14 17:25:38 +01:00
|
|
|
'$retractall'(V,M).
|
2003-02-12 13:18:01 +00:00
|
|
|
retractall(V) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
'$current_module'(M),
|
|
|
|
'$retractall'(V,M).
|
|
|
|
|
|
|
|
'$retractall'(V,M) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,retract(M:V)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$retractall'(M:V,_) :- !,
|
|
|
|
'$retractall'(V,M).
|
|
|
|
'$retractall'(T,M) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
(
|
|
|
|
'$is_log_updatable'(T, M) ->
|
2008-01-23 17:57:56 +00:00
|
|
|
( '$is_multifile'(T, M) ->
|
|
|
|
'$retractall_lu_mf'(T,M)
|
|
|
|
;
|
|
|
|
'$retractall_lu'(T,M)
|
|
|
|
)
|
2014-10-23 00:35:14 +01:00
|
|
|
;
|
|
|
|
\+ callable(T) ->
|
|
|
|
'$do_error'(type_error(callable,T),retractall(T))
|
2003-08-27 14:37:10 +01:00
|
|
|
;
|
|
|
|
'$undefined'(T,M) ->
|
|
|
|
functor(T,Na,Ar),
|
|
|
|
'$dynamic'(Na/Ar,M), !
|
|
|
|
;
|
|
|
|
'$is_dynamic'(T,M) ->
|
|
|
|
'$erase_all_clauses_for_dynamic'(T, M)
|
|
|
|
;
|
|
|
|
functor(T,Na,Ar),
|
|
|
|
'$do_error'(permission_error(modify,static_procedure,Na/Ar),retractall(T))
|
|
|
|
).
|
|
|
|
|
2013-06-07 15:26:50 +01:00
|
|
|
'$retractall_lu'(T,M) :-
|
|
|
|
'$free_arguments'(T), !,
|
|
|
|
( '$purge_clauses'(T,M), fail ; true ).
|
2003-08-27 14:37:10 +01:00
|
|
|
'$retractall_lu'(T,M) :-
|
2003-11-18 19:23:10 +00:00
|
|
|
'$log_update_clause'(T,M,_,R),
|
|
|
|
erase(R),
|
2003-08-27 14:37:10 +01:00
|
|
|
fail.
|
|
|
|
'$retractall_lu'(_,_).
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2008-01-23 17:57:56 +00:00
|
|
|
'$retractall_lu_mf'(T,M) :-
|
|
|
|
'$log_update_clause'(T,M,_,R),
|
|
|
|
( recorded('$mf','$mf_clause'(_,_,_,_,R),MR), erase(MR), fail ; true),
|
|
|
|
erase(R),
|
|
|
|
fail.
|
|
|
|
'$retractall_lu_mf'(_,_).
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$erase_all_clauses_for_dynamic'(T, M) :-
|
|
|
|
'$recordedp'(M:T,(T :- _),R), erase(R), fail.
|
|
|
|
'$erase_all_clauses_for_dynamic'(T,M) :-
|
|
|
|
'$recordedp'(M:T,_,_), fail.
|
|
|
|
'$erase_all_clauses_for_dynamic'(_,_).
|
|
|
|
|
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
|
|
|
|
meta-predicate, will be lost.
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2002-03-14 19:11:42 +00:00
|
|
|
abolish(Mod:N,A) :- !,
|
|
|
|
'$abolish'(N,A,Mod).
|
2001-11-15 00:01:43 +00:00
|
|
|
abolish(N,A) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$abolish'(N,A,Mod).
|
|
|
|
|
|
|
|
'$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
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred abolish(+ _PredSpec_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
Deletes the predicate given by _PredSpec_ from the database. If
|
|
|
|
_PredSpec_ is an unbound variable, delete all predicates for the
|
|
|
|
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
|
|
|
|
dynamic procedures. Under other modes it will abolish any procedures.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2010-02-26 10:38:56 +00:00
|
|
|
abolish(V) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error,abolish(V)).
|
|
|
|
abolish(Mod:V) :- var(V), !,
|
2014-10-07 01:35:41 +01:00
|
|
|
'$do_error'(instantiation_error,abolish(Mod:V)).
|
2002-10-14 17:25:38 +01:00
|
|
|
abolish(M:X) :- !,
|
|
|
|
'$abolish'(X,M).
|
2001-04-09 20:54:03 +01:00
|
|
|
abolish(X) :-
|
2001-11-15 00:01:43 +00:00
|
|
|
'$current_module'(M),
|
2002-10-14 17:25:38 +01:00
|
|
|
'$abolish'(X,M).
|
|
|
|
|
|
|
|
'$abolish'(X,M) :-
|
|
|
|
'$access_yap_flags'(8, 2), !,
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_abolish'(X,M).
|
2002-10-14 17:25:38 +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).
|
2002-09-02 18:33:00 +01:00
|
|
|
'$new_abolish'(A,M) :- atom(A), !,
|
2001-12-11 19:53:07 +00:00
|
|
|
'$abolish_all_atoms'(A,M).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_abolish'(M:PS,_) :- !,
|
|
|
|
'$new_abolish'(PS,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), !,
|
2002-01-30 04:56:43 +00:00
|
|
|
( '$access_yap_flags'(8, 1) ->
|
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), !,
|
2002-01-30 04:56:43 +00:00
|
|
|
( '$access_yap_flags'(8, 1) ->
|
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'(M:N,_) :- !,
|
|
|
|
'$old_abolish'(N,M).
|
|
|
|
'$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)).
|
2001-04-09 20:54:03 +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
|
|
|
|
2003-11-26 18:36:35 +00:00
|
|
|
'$abolishd'(T, M) :-
|
|
|
|
'$is_multifile'(T,M),
|
|
|
|
functor(T,Name,Arity),
|
|
|
|
recorded('$mf','$mf_clause'(_,Name,Arity,M,Ref),R),
|
|
|
|
erase(R),
|
|
|
|
erase(Ref),
|
|
|
|
fail.
|
2007-10-17 00:17:04 +01:00
|
|
|
'$abolishd'(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.
|
2003-11-26 18:36:35 +00:00
|
|
|
'$abolishd'(T, M) :-
|
2005-01-14 20:55:16 +00:00
|
|
|
'$purge_clauses'(T,M), fail.
|
2007-12-23 22:48:44 +00:00
|
|
|
'$abolishd'(T, M) :-
|
|
|
|
'$kill_dynamic'(T,M), fail.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$abolishd'(_, _).
|
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) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
'$access_yap_flags'(8, 2), % 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-09-11 20:06:57 +01:00
|
|
|
/** @pred dynamic_predicate(+ _P_,+ _Semantics_)
|
|
|
|
|
|
|
|
|
|
|
|
Declares predicate _P_ or list of predicates [ _P1_,..., _Pn_]
|
|
|
|
as a dynamic predicate following either `logical` or
|
|
|
|
`immediate` semantics.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2001-04-09 20:54:03 +01:00
|
|
|
dynamic_predicate(P,Sem) :-
|
|
|
|
'$bad_if_is_semantics'(Sem, dynamic(P,Sem)).
|
|
|
|
dynamic_predicate(P,Sem) :-
|
|
|
|
'$log_upd'(OldSem),
|
|
|
|
( Sem = logical -> '$switch_log_upd'(1) ; '$switch_log_upd'(0) ),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$current_module'(M),
|
|
|
|
'$dynamic'(P, M),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$switch_log_upd'(OldSem).
|
|
|
|
|
|
|
|
'$bad_if_is_semantics'(Sem, Goal) :-
|
|
|
|
var(Sem), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,Goal).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$bad_if_is_semantics'(Sem, Goal) :-
|
|
|
|
Sem \= immediate, Sem \= logical, !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(domain_error(semantics_indicator,Sem),Goal).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
2008-08-06 01:56:11 +01:00
|
|
|
'$expand_clause'((H:-B),C1,C2,Mod,HM) :- !,
|
|
|
|
strip_module(Mod:H, HM, H1),
|
2014-10-09 10:46:09 +01:00
|
|
|
% Mod has scope over the full clause
|
|
|
|
'$module_expansion'((H1:-B), C1, C2, HM, Mod, Mod),
|
2003-08-27 14:37:10 +01:00
|
|
|
( get_value('$strict_iso',on) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
'$check_iso_strict_clause'(C1)
|
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
2008-08-06 01:56:11 +01:00
|
|
|
'$expand_clause'(H,H1,H1,Mod,HM) :-
|
|
|
|
strip_module(Mod:H, HM, H1).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$is_public'(T, Mod) :-
|
|
|
|
'$is_dynamic'(T, Mod), !. % all dynamic predicates are public.
|
|
|
|
'$is_public'(T, Mod) :-
|
|
|
|
'$flags'(T,Mod,F,F),
|
2003-12-27 00:38:53 +00:00
|
|
|
F\/0x00400000 =\= 0.
|
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.
|
|
|
|
**/
|
2012-11-25 23:36:43 +00:00
|
|
|
stash_predicate(V) :- var(V), !,
|
|
|
|
'$do_error'(instantiation_error,stash_predicate(V)).
|
|
|
|
stash_predicate(M:P) :- !,
|
|
|
|
'$stash_predicate2'(P, M).
|
|
|
|
stash_predicate(P) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$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)).
|
|
|
|
|
2014-07-27 01:14:15 +01:00
|
|
|
/** @pred @pred hide_predicate(+ _Pred_)
|
|
|
|
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
|
|
|
**/
|
2002-08-14 17:00:54 +01:00
|
|
|
hide_predicate(V) :- var(V), !,
|
2002-10-14 17:25:38 +01:00
|
|
|
'$do_error'(instantiation_error,hide_predicate(V)).
|
2002-08-14 17:00:54 +01:00
|
|
|
hide_predicate(M:P) :- !,
|
|
|
|
'$hide_predicate2'(P, M).
|
|
|
|
hide_predicate(P) :-
|
|
|
|
'$current_module'(M),
|
2008-01-23 17:57:56 +00:00
|
|
|
'$hide_predicate2'(P, M).
|
2002-08-14 17:00:54 +01:00
|
|
|
|
|
|
|
'$hide_predicate2'(V, M) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,hide_predicate(M:V)).
|
2002-08-14 17:00:54 +01:00
|
|
|
'$hide_predicate2'(N/A, M) :- !,
|
|
|
|
functor(S,N,A),
|
|
|
|
'$hide_predicate'(S, M) .
|
|
|
|
'$hide_predicate2'(PredDesc, M) :-
|
2006-03-24 16:26:31 +00:00
|
|
|
'$do_error'(type_error(predicate_indicator,PredDesc),hide_predicate(M:PredDesc)).
|
2002-08-14 17:00:54 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred predicate_property( _P_, _Prop_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
For the predicates obeying the specification _P_ unify _Prop_
|
|
|
|
with a property of _P_. These properties may be:
|
|
|
|
|
|
|
|
+ `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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2008-12-12 22:45:41 +00:00
|
|
|
predicate_property(Pred,Prop) :- var(Pred), !,
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$predicate_property2'(Pred,Prop,Mod).
|
2002-12-13 20:00:41 +00:00
|
|
|
predicate_property(Mod:Pred,Prop) :- !,
|
|
|
|
'$predicate_property2'(Pred,Prop,Mod).
|
|
|
|
predicate_property(Pred,Prop) :-
|
|
|
|
'$current_module'(Mod),
|
|
|
|
'$predicate_property2'(Pred,Prop,Mod).
|
|
|
|
|
2008-12-12 22:45:41 +00:00
|
|
|
'$predicate_property2'(Pred,Prop,M) :- var(M), !,
|
|
|
|
'$all_current_modules'(M),
|
|
|
|
'$predicate_property2'(Pred,Prop,M).
|
2009-05-29 03:51:34 +01:00
|
|
|
'$predicate_property2'(Pred,Prop,M0) :- var(Pred), !,
|
|
|
|
(M = M0 ; M = prolog), % prolog mode is 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).
|
|
|
|
'$predicate_property2'(Pred,Prop,Mod) :-
|
|
|
|
'$pred_exists'(Pred,Mod), !,
|
|
|
|
'$predicate_property'(Pred,Mod,Mod,Prop).
|
|
|
|
'$predicate_property2'(Pred,Prop,Mod) :-
|
2009-12-04 11:00:13 +00:00
|
|
|
'$imported_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) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'(Na,M,S,_),
|
|
|
|
functor(S,Na,Ar),
|
2008-09-15 04:30:09 +01:00
|
|
|
'$ifunctor'(Pred,Na,Ar).
|
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
|
|
|
|
|
|
|
'$predicate_property'(P,M,_,built_in) :-
|
2009-05-25 15:57:27 +01:00
|
|
|
'$system_predicate'(P,M).
|
2002-12-13 20:00:41 +00:00
|
|
|
'$predicate_property'(P,M,_,source) :-
|
2006-03-24 16:26:31 +00:00
|
|
|
'$flags'(P,M,F,F),
|
2003-12-18 16:38:40 +00:00
|
|
|
F /\ 0x00400000 =\= 0.
|
|
|
|
'$predicate_property'(P,M,_,tabled) :-
|
2006-03-24 16:26:31 +00:00
|
|
|
'$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),
|
2008-07-23 00:34:50 +01:00
|
|
|
'$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)) :-
|
|
|
|
'$owner_file'(P,Mod,F).
|
2002-12-13 20:00:41 +00:00
|
|
|
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred predicate_statistics( _P_, _NCls_, _Sz_, _IndexSz_)
|
|
|
|
|
|
|
|
|
|
|
|
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)).
|
2006-10-10 21:21:42 +01:00
|
|
|
predicate_statistics(M:P,NCls,Sz,ISz) :- !,
|
2003-11-12 12:33:31 +00:00
|
|
|
'$predicate_statistics'(P,M,NCls,Sz,ISz).
|
|
|
|
predicate_statistics(P,NCls,Sz,ISz) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$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,_,_,_) :-
|
2003-11-12 12:33:31 +00:00
|
|
|
'$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).
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred predicate_erased_statistics( _P_, _NCls_, _Sz_, _IndexSz_)
|
|
|
|
|
|
|
|
|
|
|
|
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) :-
|
2012-07-13 20:56:50 +01:00
|
|
|
var(P), !,
|
2010-10-26 10:07:34 +01:00
|
|
|
current_predicate(_,P),
|
|
|
|
predicate_erased_statistics(P,NCls,Sz,ISz).
|
2007-12-18 17:46:58 +00:00
|
|
|
predicate_erased_statistics(M:P,NCls,Sz,ISz) :- !,
|
|
|
|
'$predicate_erased_statistics'(M:P,NCls,Sz,_,ISz).
|
|
|
|
predicate_erased_statistics(P,NCls,Sz,ISz) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$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_)
|
|
|
|
|
2014-11-25 16:53:35 +00:00
|
|
|
Defines the relation: _P_ is a currently defined predicate whose name is the atom _A_.
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2009-04-17 01:06:49 +01:00
|
|
|
current_predicate(A,T) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$ground_module'(T, M, T0),
|
|
|
|
(
|
|
|
|
'$current_predicate'(A, M, T0, _)
|
|
|
|
;
|
|
|
|
'$imported_predicate'(A, M, A/_Arity, T0, _)
|
|
|
|
).
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred system_predicate( _A_, _P_)
|
|
|
|
|
|
|
|
Defines the relation: _P_ is a built-in predicate whose name
|
2014-11-25 16:43:43 +00:00
|
|
|
is the atom _A_.
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2014-11-25 12:03:48 +00:00
|
|
|
system_predicate(A,T) :-
|
|
|
|
'$ground_module'(T, M, T0),
|
|
|
|
(
|
|
|
|
'$current_predicate'(A, M, T0, Flags)
|
|
|
|
;
|
|
|
|
'$current_predicate'(A, prolog, T0, Flags)
|
|
|
|
),
|
|
|
|
Flags /\ 0x00004000 =\= 0,
|
2008-02-07 22:34:45 +00:00
|
|
|
\+ '$hidden'(A).
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
/** @pred system_predicate( ?_P_ )
|
|
|
|
|
|
|
|
Defines the relation: _P_ is a currently defined system predicate.
|
|
|
|
*/
|
2008-02-07 22:34:45 +00:00
|
|
|
system_predicate(P) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
system_predicate(_, P).
|
2008-02-07 22:34:45 +00:00
|
|
|
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred current_predicate( _F_) is iso
|
|
|
|
|
|
|
|
|
|
|
|
_F_ is the predicate indicator for a currently defined user or
|
|
|
|
library predicate. _F_ is of the form _Na/Ar_, where the atom
|
|
|
|
_Na_ is the name of the predicate, and _Ar_ its arity.
|
|
|
|
*/
|
2013-11-25 22:57:05 +00:00
|
|
|
current_predicate(F0) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$ground_module'(F0, M, F),
|
2013-11-25 22:57:05 +00:00
|
|
|
(
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'(N, M, S, _),
|
|
|
|
functor( S, N, Ar),
|
|
|
|
F = N/Ar
|
2013-11-25 22:57:05 +00:00
|
|
|
;
|
2014-11-25 12:03:48 +00:00
|
|
|
'$imported_predicate'(_Name, M, F, _S, _)
|
2013-11-25 22:57:05 +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),
|
|
|
|
'$flags'(G0, ExportingMod, Flags, Flags).
|
2008-02-07 22:34:45 +00:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred current_key(? _A_,? _K_)
|
|
|
|
|
|
|
|
|
|
|
|
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) :-
|
2014-11-25 12:03:48 +00:00
|
|
|
'$current_predicate'(A,idb,K,_).
|
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
|
|
|
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
/** @pred compile_predicates(: _ListOfNameArity_)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
;
|
|
|
|
'$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
|
|
|
|
;
|
|
|
|
'$instance_property'(ClauseRef, 2, FileName) ).
|
2013-11-05 17:59:19 +00:00
|
|
|
clause_property(ClauseRef, line_count(LineNumber)) :-
|
|
|
|
'$instance_property'(ClauseRef, 4, LineNumber),
|
|
|
|
LineNumber > 0.
|
|
|
|
clause_property(ClauseRef, fact) :-
|
|
|
|
'$instance_property'(ClauseRef, 3, true).
|
|
|
|
clause_property(ClauseRef, erased) :-
|
|
|
|
'$instance_property'(ClauseRef, 0, true).
|
|
|
|
clause_property(ClauseRef, predicate(PredicateIndicator)) :-
|
|
|
|
'$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
|
|
|
/**
|
|
|
|
@}
|
|
|
|
*/
|
|
|
|
|