add compile_predicates/1.

This commit is contained in:
Vítor Santos Costa 2011-10-21 23:02:07 +01:00
parent c052b195e5
commit 8d4c9160eb
2 changed files with 45 additions and 0 deletions

View File

@ -5900,6 +5900,19 @@ asserted before being defined.
Declares predicate @var{P} or list of predicates [@var{P1},...,@var{Pn}]
as a dynamic predicate following either @code{logical} or
@code{immediate} semantics.
@item compile_predicates(:@var{ListOfNameArity})
@findex compile_predicates/1
@snindex compile_predicates/1
@cnindex compile_predicates/1
Compile a list of specified dynamic predicates (see @code{dynamic/1} and
@code{assert/1} into normal static predicates. This call tells the
Prolog environment the definition will not change anymore and further
calls to @code{assert/1} or @code{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.
@menu

View File

@ -1019,3 +1019,35 @@ current_key(A,K) :-
;
Pred = Na
).
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'([], _, _).
'$compile_predicates'(P.Ps, M, Call) :-
'$compile_predicate'(P, M, Call).
'$compile_predicates'(Ps, M, Call).
'$compile_predicate'(P, M, Call) :-
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).