add compile_predicates/1.
This commit is contained in:
parent
c052b195e5
commit
8d4c9160eb
13
docs/yap.tex
13
docs/yap.tex
@ -5900,6 +5900,19 @@ asserted before being defined.
|
|||||||
Declares predicate @var{P} or list of predicates [@var{P1},...,@var{Pn}]
|
Declares predicate @var{P} or list of predicates [@var{P1},...,@var{Pn}]
|
||||||
as a dynamic predicate following either @code{logical} or
|
as a dynamic predicate following either @code{logical} or
|
||||||
@code{immediate} semantics.
|
@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
|
@menu
|
||||||
|
|
||||||
|
32
pl/preds.yap
32
pl/preds.yap
@ -1019,3 +1019,35 @@ current_key(A,K) :-
|
|||||||
;
|
;
|
||||||
Pred = Na
|
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).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user