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 *
* *
*************************************************************************/
% The next predicates are applicable only
% to dynamic code
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
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
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)).
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) :-
'$is_log_updatable'(H, Mod), !,
2005-01-28 23:14:41 +00:00
'$compile_dynamic'(H, Where, H, Mod, R).
2003-08-27 14:37:10 +01:00
'$assert_fact'(H,Mod,Where,R) :-
( '$is_dynamic'(H, Mod) ->
'$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).
2001-11-15 00:01:43 +00: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
).
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
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)).
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).
'$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 /\ 0x00400000 =\= 0 -> '$erase_source'(Head,Mod) ; true ),
( 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) ->
2007-11-26 23:43:10 +00:00
nb_getval('$consulting_file',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 /\ 0x00400000 =\= 0 -> '$erase_source'(Head,Mod) ; true ),
( 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) ->
2003-08-27 14:37:10 +01:00
get_value('$consulting_file',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) :-
2001-04-09 20:54:03 +01: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) :-
2003-08-27 14:37:10 +01:00
get_value('$consulting_file',F),
2001-04-09 20:54:03 +01:00
'$recorded'('$multifile_dynamic'(_,_,_), '$mf'(Na,A,M,F,R), R1),
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
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
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
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)).
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
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)).
'$clause'(C,M,Q,R) :- number(C), !,
'$do_error'(type_error(callable,C),clause(M:C,Q,R)).
'$clause'(R,M,Q,R) :- db_reference(R), !,
'$do_error'(type_error(callable,R),clause(M:R,Q,R)).
2002-12-13 20:00:41 +00:00
'$clause'(M:P,_,Q,R) :- !,
'$clause'(P,M,Q,R).
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
2003-08-27 14:37:10 +01:00
% just create a choice-point
2006-10-10 15:08:17 +01:00
% the 6th argument marks the time-stamp.
'$do_log_upd_clause'(_,_,_,_,_,_).
'$do_log_upd_clause'(A,B,C,D,E,_) :-
2003-08-27 14:37:10 +01:00
'$continue_log_update_clause'(A,B,C,D,E).
2006-10-10 15:08:17 +01:00
'$do_log_upd_clause'(_,_,_,_,_,_).
2003-08-27 14:37:10 +01:00
2006-10-10 15:08:17 +01:00
:- '$do_log_upd_clause'(_,_,_,_,_,_), !.
2003-11-26 18:36:35 +00:00
2008-01-23 17:57:56 +00:00
'$do_log_upd_clause_erase'(_,_,_,_,_,_).
'$do_log_upd_clause_erase'(A,B,C,D,E,_) :-
'$continue_log_update_clause_erase'(A,B,C,D,E).
'$do_log_upd_clause_erase'(_,_,_,_,_,_).
:- '$do_log_upd_clause_erase'(_,_,_,_,_,_), !.
2006-10-10 15:08:17 +01:00
'$do_log_upd_clause0'(_,_,_,_,_,_).
'$do_log_upd_clause0'(A,B,C,D,_,_) :-
2003-08-27 14:37:10 +01:00
'$continue_log_update_clause'(A,B,C,D).
2006-10-10 15:08:17 +01:00
'$do_log_upd_clause0'(_,_,_,_,_,_).
2003-08-27 14:37:10 +01:00
2006-10-10 15:08:17 +01:00
:- '$do_log_upd_clause0'(_,_,_,_,_,_), !.
2003-11-26 18:36:35 +00:00
2003-11-21 16:56:20 +00:00
'$do_static_clause'(_,_,_,_,_).
'$do_static_clause'(A,B,C,D,E) :-
'$continue_static_clause'(A,B,C,D,E).
2006-03-24 16:26:31 +00:00
'$do_static_clause'(_,_,_,_,_).
2003-08-27 14:37:10 +01:00
2003-11-26 18:36:35 +00:00
:- '$do_static_clause'(_,_,_,_,_), !.
2003-12-02 00:36:27 +00:00
nth_clause(V,I,R) :- var(V), var(R), !,
2006-03-24 16:26:31 +00:00
'$do_error'(instantiation_error,nth_clause(V,I,R)).
2002-12-13 20:00:41 +00:00
nth_clause(M:V,I,R) :- !,
'$nth_clause'(V,M,I,R).
nth_clause(V,I,R) :-
2002-09-23 14:43:47 +01:00
'$current_module'(M),
2002-12-13 20:00:41 +00:00
'$nth_clause'(V,M,I,R).
2003-12-02 00:36:27 +00:00
'$nth_clause'(V,M,I,R) :- var(V), var(R), !,
2002-12-13 20:00:41 +00:00
'$do_error'(instantiation_error,M:nth_clause(V,I,R)).
2003-12-02 00:36:27 +00:00
'$nth_clause'(P1,_,I,R) :- nonvar(P1), P1 = M:P, !,
'$nth_clause'(P,M,I,R).
'$nth_clause'(P,M,I,R) :- nonvar(R), !,
'$nth_clause_ref'(P,M,I,R).
2002-12-13 20:00:41 +00:00
'$nth_clause'(C,M,I,R) :- number(C), !,
'$do_error'(type_error(callable,C),M:nth_clause(C,I,R)).
'$nth_clause'(R,M,I,R) :- db_reference(R), !,
'$do_error'(type_error(callable,R),M:nth_clause(R,I,R)).
'$nth_clause'(P,M,I,R) :-
2003-12-01 19:22:01 +00:00
( '$is_log_updatable'(P,M) ; '$is_source'(P,M) ), !,
'$p_nth_clause'(P,M,I,R).
'$nth_clause'(P,M,I,R) :-
2006-03-24 16:26:31 +00:00
'$is_dynamic'(P,M), !,
2002-12-13 20:00:41 +00:00
'$nth_instancep'(M:P,I,R).
'$nth_clause'(P,M,I,R) :-
( '$system_predicate'(P,M) -> true ;
2003-12-01 19:22:01 +00:00
'$number_of_clauses'(P,M,N), N > 0 ),
2002-12-13 20:00:41 +00:00
functor(P,Name,Arity),
'$do_error'(permission_error(access,private_procedure,Name/Arity),
nth_clause(M:P,I,R)).
2001-11-15 00:01:43 +00:00
2003-12-02 00:36:27 +00:00
'$nth_clause_ref'(Cl,M,I,R) :-
2006-03-24 16:26:31 +00:00
'$pred_for_code'(R, _, _, M1, I), I > 0, !,
2003-12-02 00:36:27 +00:00
instance(R, Cl),
M1 = M.
'$nth_clause_ref'(P,M,I,R) :-
'$nth_instancep'(M:P,I,R).
2005-02-08 04:05:39 +00:00
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),
( F /\ 0x20000000 =:= 0x20000000, recorded('$mf','$mf_clause'(_,_,_,_,MRef),MR), erase(MR), 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
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).
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)
)
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))
).
'$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'(_,_).
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
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).
'$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) :-
2001-12-11 19:53:07 +00:00
'$current_predicate'(M,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) :-
2002-09-02 18:33:00 +01:00
'$current_predicate_for_atom'(Na,M,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) :-
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) :-
2001-12-28 16:42:18 +00:00
'$current_predicate'(M, Na, Ar),
'$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) :-
2002-09-02 18:33:00 +01:00
'$current_predicate_for_atom'(Na, M, 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))).
2001-04-09 20:54:03 +01:00
% I cannot allow modifying static procedures in YAPOR
% this code has to be here because of abolish/2
2001-11-15 00:01:43 +00:00
'$abolishs'(G, Module) :-
2001-04-09 20:54:03 +01:00
'$has_yap_or', !,
2001-10-30 16:42:05 +00:00
functor(G,A,N),
2002-09-09 18:40:12 +01:00
'$do_error'(permission_error(modify,static_procedure,A/N),abolish(Module:G)).
2003-11-26 18:36:35 +00:00
'$abolishs'(G, M) :-
'$is_multifile'(G,M), !,
functor(G,Name,Arity),
recorded('$mf','$mf_clause'(_,Name,Arity,M,Ref),R),
erase(R),
erase(Ref),
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
%
% can only do as goal in YAP mode.
%
dynamic(X) :- '$access_yap_flags'(8, 0), !,
2001-11-15 00:01:43 +00:00
'$current_module'(M),
'$dynamic'(X, M).
2001-04-09 20:54:03 +01:00
dynamic(X) :-
2002-09-09 18:40:12 +01:00
'$do_error'(context_error(dynamic(X),declaration),query).
2001-04-09 20:54:03 +01:00
2002-01-02 16:55:24 +00:00
'$dynamic'(X,M) :- var(X), !,
2002-09-09 18:40:12 +01:00
'$do_error'(instantiation_error,dynamic(M:X)).
2001-11-15 00:01:43 +00:00
'$dynamic'(Mod:Spec,_) :- !,
'$dynamic'(Spec,Mod).
'$dynamic'([], _) :- !.
'$dynamic'([H|L], M) :- !, '$dynamic'(H, M), '$dynamic'(L, M).
'$dynamic'((A,B),M) :- !, '$dynamic'(A,M), '$dynamic'(B,M).
2004-09-10 22:04:46 +01:00
'$dynamic'(X,M) :-
2001-11-15 00:01:43 +00:00
'$dynamic2'(X,M).
'$dynamic2'(X, Mod) :- '$log_upd'(Stat), Stat\=0, !,
'$logical_updatable'(X, Mod).
2004-09-10 22:04:46 +01:00
'$dynamic2'(A/N, Mod) :-
integer(N), atom(A), !,
2001-11-15 00:01:43 +00:00
functor(T,A,N), '$flags'(T,Mod,F,F),
2003-12-04 18:12:26 +00:00
% LogUpd,BinaryTest,Safe,C,Dynamic,Compiled,Standard,Asm,
2008-04-29 00:02:32 +01:00
( F/\ 0x19D1FA80 =:= 0, '$undefined'(T,Mod) -> NF is F \/ 0x00002000, '$flags'(T, Mod, F, NF), '$mk_d'(T,Mod);
F /\ 0x00002000 =:= 0x00002000 -> '$mk_d'(T,Mod); % dynamic
F /\ 0x08000000 =:= 0x08000000 -> '$mk_d'(T,Mod) ; % LU
F /\ 0x00000400 =:= 0x00000400, '$undefined'(T,Mod) -> F1 is F /\ \(0x400), N1F is F1 \/ 0x00002000, NF is N1F /\ \(0x00400000), '$flags'(T,Mod,F,NF), '$mk_d'(T,Mod);
2002-09-09 18:40:12 +01:00
'$do_error'(permission_error(modify,static_procedure,A/N),dynamic(Mod:A/N))
2001-11-15 00:01:43 +00:00
).
'$dynamic2'(X,Mod) :-
2002-09-09 18:40:12 +01:00
'$do_error'(type_error(callable,X),dynamic(Mod:X)).
2001-04-09 20:54:03 +01:00
2001-11-15 00:01:43 +00:00
'$logical_updatable'(A/N,Mod) :- integer(N), atom(A), !,
functor(T,A,N), '$flags'(T,Mod,F,F),
2003-12-04 18:12:26 +00:00
(
2008-04-29 00:02:32 +01:00
F/\ 0x19D1FA80 =:= 0, '$undefined'(T,Mod) -> NF is F \/ 0x08000400, '$flags'(T,Mod,F,NF), '$mk_d'(T,Mod);
F /\ 0x08000000 =:= 0x08000000 -> '$mk_d'(T,Mod) ; % LU
F /\ 0x00002000 =:= 0x00002000 -> '$mk_d'(T,Mod); % dynamic
F /\ 0x00000400 =:= 0x00000400 , '$undefined'(T,Mod) -> N1F is F \/ 0x08000000, NF is N1F /\ \(0x00400000), '$flags'(T,Mod,F,NF), '$mk_d'(T,Mod);
2002-09-09 18:40:12 +01:00
'$do_error'(permission_error(modify,static_procedure,A/N),dynamic(Mod:A/N))
2001-04-09 20:54:03 +01:00
).
2001-11-15 00:01:43 +00:00
'$logical_updatable'(X,Mod) :-
2002-09-09 18:40:12 +01:00
'$do_error'(type_error(callable,X),dynamic(Mod:X)).
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),
'$module_expansion'((H1:-B), C1, C2, Mod, HM),
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
'$public'(X, _) :- var(X), !,
2002-09-09 18:40:12 +01:00
'$do_error'(instantiation_error,public(X)).
2001-11-15 00:01:43 +00:00
'$public'(Mod:Spec, _) :- !,
'$public'(Spec,Mod).
'$public'((A,B), M) :- !, '$public'(A,M), '$public'(B,M).
'$public'([],_) :- !.
'$public'([H|L], M) :- !, '$public'(H, M), '$public'(L, M).
'$public'(A/N, Mod) :- integer(N), atom(A), !,
2002-01-02 16:55:24 +00:00
functor(T,A,N),
2001-11-15 00:01:43 +00:00
'$do_make_public'(T, Mod).
'$public'(X, Mod) :-
2002-09-09 18:40:12 +01:00
'$do_error'(type_error(callable,X),dynamic(Mod:X)).
2001-11-15 00:01:43 +00:00
'$do_make_public'(T, Mod) :-
'$is_dynamic'(T, Mod), !. % all dynamic predicates are public.
'$do_make_public'(T, Mod) :-
'$flags'(T,Mod,F,F),
2003-12-04 18:12:26 +00:00
NF is F\/0x00400000,
2001-11-15 00:01:43 +00:00
'$flags'(T,Mod,F,NF).
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
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
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-03 16:33:44 +00:00
'$imported_predicate'(M,Mod,NPred,Pred),
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) :-
'$current_predicate'(M,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) :-
2007-12-05 12:17:25 +00:00
recorded('$import','$import'(SourceMod,Mod,_,Pred,_,_),_).
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).
'$predicate_property'(P,M,M,exported) :-
functor(P,N,A),
2008-05-22 22:48:04 +01:00
once(recorded('$module','$module'(_TFN,M,Publics),_)),
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).
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).
2007-12-18 17:46:58 +00:00
predicate_erased_statistics(V,NCls,Sz,ISz) :- var(V), !,
'$do_error'(instantiation_error,predicate_statistics(V,NCls,Sz,ISz)).
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
2009-04-17 01:06:49 +01:00
current_predicate(A,T) :-
'$current_predicate_inside'(A,T).
'$current_predicate_inside'(A,T) :-
var(T), !, % only for the predicate
2008-02-07 22:34:45 +00:00
'$current_module'(M),
'$current_predicate_no_modules'(M,A,T).
2009-04-17 01:06:49 +01:00
'$current_predicate_inside'(A,M:T) :- % module specified
2008-02-07 22:34:45 +00:00
var(M), !,
2009-04-17 01:06:49 +01:00
'$current_predicate_var'(A,M,T).
'$current_predicate_inside'(A,M:T) :- % module specified
2008-02-07 22:34:45 +00:00
nonvar(T),
!,
functor(T,A,_),
'$pred_exists'(T,M).
2009-04-17 01:06:49 +01:00
'$current_predicate_inside'(A,M:T) :- % module specified
2008-02-07 22:34:45 +00:00
!,
'$current_predicate_no_modules'(M,A,T).
2009-04-17 01:06:49 +01:00
'$current_predicate_inside'(A,T) :- % only for the predicate
2008-02-07 22:34:45 +00:00
'$current_module'(M),
'$current_predicate_no_modules'(M,A,T).
2009-04-17 01:06:49 +01:00
'$current_predicate_var'(A,M,T) :-
var(T), !,
current_module(M),
M \= prolog,
'$current_predicate_no_modules'(M,A,T).
'$current_predicate_var'(A,M,T) :-
functor(T,A,_),
current_module(M),
M \= prolog,
2009-04-17 20:18:05 +01:00
'$pred_exists'(T,M).
2009-04-17 01:06:49 +01:00
current_predicate(A) :-
'$current_predicate_inside'(A).
'$current_predicate_inside'(F) :- var(F), !, % only for the predicate
2008-02-07 22:34:45 +00:00
'$current_module'(M),
'$current_predicate3'(M,F).
2009-04-17 01:06:49 +01:00
'$current_predicate_inside'(M:F) :- % module specified
2008-02-07 22:34:45 +00:00
var(M), !,
'$current_module'(M),
M \= prolog,
'$current_predicate3'(M,F).
2009-04-17 01:06:49 +01:00
'$current_predicate_inside'(M:F) :- % module specified
2008-02-07 22:34:45 +00:00
!,
'$current_predicate3'(M,F).
2009-04-17 01:06:49 +01:00
'$current_predicate_inside'(S) :- % only for the predicate
2008-02-07 22:34:45 +00:00
'$current_module'(M),
'$current_predicate3'(M,S).
system_predicate(A,P) :-
'$current_predicate_no_modules'(prolog,A,P),
\+ '$hidden'(A).
system_predicate(P) :-
'$current_module'(M),
'$system_predicate'(P,M).
'$current_predicate_no_modules'(M,A,T) :-
'$current_predicate'(M,A,Arity),
2008-09-15 04:30:09 +01:00
'$ifunctor'(T,A,Arity),
2008-02-07 22:34:45 +00:00
'$pred_exists'(T,M).
'$current_predicate3'(M,A/Arity) :- nonvar(A), nonvar(Arity), !,
(
'$current_predicate'(M,A,Arity)
->
2008-09-18 17:48:01 +01:00
'$ifunctor'(T,A,Arity),
2008-02-07 22:34:45 +00:00
'$pred_exists'(T,M)
2008-02-08 09:49:21 +00:00
% ;
2008-02-07 23:09:13 +00:00
% '$current_predicate'(prolog,A,Arity)
% ->
% functor(T,A,Arity),
% '$pred_exists'(T,M)
% ;
2008-02-08 09:49:21 +00:00
% recorded('$import','$import'(NM,M,G,T,A,Arity),_)
% ->
% '$pred_exists'(G,NM)
2008-02-07 22:34:45 +00:00
).
'$current_predicate3'(M,A/Arity) :- !,
(
'$current_predicate'(M,A,Arity),
2008-09-15 04:30:09 +01:00
'$ifunctor'(T,A,Arity),
2009-04-17 01:06:49 +01:00
'$pred_exists'(T,M)
2008-02-08 09:49:21 +00:00
% ;
2008-02-07 23:09:13 +00:00
% '$current_predicate'(prolog,A,Arity),
% functor(T,A,Arity),
% '$pred_exists'(T,M)
% ;
2008-02-08 09:49:21 +00:00
% recorded('$import','$import'(NM,M,G,T,A,Arity),_),
% functor(T,A,Arity),
% '$pred_exists'(G,NM)
2008-02-07 22:34:45 +00:00
).
'$current_predicate3'(M,BadSpec) :- % only for the predicate
'$do_error'(type_error(predicate_indicator,BadSpec),current_predicate(M:BadSpec)).
current_key(A,K) :-
'$current_predicate'(idb,A,Arity),
2008-09-15 04:30:09 +01:00
'$ifunctor'(K,A,Arity).
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
).