YAP 7.1.0
preds.yap
1 /*************************************************************************
2* *
3 * YAP Prolog *
4 * *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: preds.yap *
12* Last rev: 8/2/88 *
13* mods: *
14* comments: Predicate Manipulation for YAP *
15* *
16*************************************************************************/
17
18/**
19 * @{
20 * @defgroup Database The Clausal Data Base
21 * @ingroup builtins
22
23Predicates in YAP may be dynamic or static. By default, when
24consulting or reconsulting, predicates are assumed to be static:
25execution is faster and the code will probably use less space.
26Static predicates impose some restrictions: in general there can be no
27addition or removal of clauses for a procedure if it is being used in the
28current execution.
29
30Dynamic predicates allow programmers to change the Clausal Data Base with
31the same flexibility as in C-Prolog. With dynamic predicates it is
32always possible to add or remove clauses during execution and the
33semantics will be the same as for C-Prolog. But the programmer should be
34aware of the fact that asserting or retracting are still expensive operations,
35and therefore he should try to avoid them whenever possible.
36
37*/
38
39:- system_module( '$_preds', [abolish/1,
52 clause_property/2,
69 unknown/2], ['$assert_static'/5,
70 '$assertz_dynamic'/4,
71 '$clause'/4,
72 '$current_predicate'/4,
73 '$init_preds'/0,
74 '$noprofile'/2,
75 '$public'/2,
76 '$unknown_error'/1,
77 '$unknown_warning'/1]).
78
79:- '$check_head_and_body'/4'$check_if_reconsulted'/2'$head_and_body'/3'$inform_as_reconsulted'/2use_system_module( '$_boot', [,
80 ,
81 ,
82 ]).
83
84:- '$do_error'/2use_system_module( '$_errors', []).
85
86:- '$do_log_upd_clause'/6'$do_log_upd_clause0'/6'$do_log_upd_clause_erase'/6'$do_static_clause'/5use_system_module( '$_init', [,
87 ,
88 ,
89 ]).
90
91:- '$imported_pred'/4'$meta_predicate'/4'$module_expansion'/5use_system_module( '$_modules', [,
92 ,
93 ]).
94
95:- '$check_multifile_pred'/3'$dynamic'/2use_system_module( '$_preddecls', [,
96 ]).
97
98:- '$check_iso_strict_clause'/1use_system_module( '$_strict_iso', []).
99
100
101
102/** @pred assert_static(: _C_)
103
104
105Adds clause _C_ to a static procedure. Asserting a static clause
106for a predicate while choice-points for the predicate are available has
107undefined results.
108
109
110*/
111assert_static(MC) :-
112 strip_module(MC, M, C),
113 '$compile'(C , assertz_static, C, M, _ ).
114
115/** @pred asserta_static(: _C_)
116
117
118Adds clause _C_ as the first clause for a static procedure.
119
120
121*/
122asserta_static(MC) :-
123 strip_module(MC, M, C),
124 '$compile'(C , asserta_static, C, M, _ ).
125
126
127/** @pred assertz_static(: _C_)
128
129
130Adds clause _C_ to the end of a static procedure. Asserting a
131static clause for a predicate while choice-points for the predicate are
132available has undefined results.
133
134
135
136The following predicates can be used for dynamic predicates and for
137static predicates, if source mode was on when they were compiled:
138
139
140
141
142*/
143assertz_static(MC) :-
144 strip_module(MC, M, C),
145 '$compile'(C , assertz_static, C, M, _ ).
146
147/** @pred clause(+ _H_, _B_) is iso
148
149
150A clause whose head matches _H_ is searched for in the
151program. Its head and body are respectively unified with _H_ and
152 _B_. If the clause is a unit clause, _B_ is unified with
153 _true_.
154
155This predicate is applicable to static procedures compiled with
156`source` active, and to all dynamic procedures.
157
158
159*/
160clause(V0,Q) :-
161 '$yap_strip_module'(V0, M, V),
162 must_be_of_type( callable, V ),
163 '$predicate_type'(V,M,Type),
164 '$clause'(Type,V,M,Q,_R).
165
166/** @pred clause(+ _H_, _B_,- _R_)
167
168The same as clause/2, plus _R_ is unified with the
169reference to the clause in the database. You can use instance/2
170to access the reference's value. Note that you may not use
171erase/1 on the reference on static procedures.
172*/
173clause(P,Q,R) :-
174 '$instance_module'(R,M0), '$instance_module',
175 instance(R,T0),
176 ( T0 = (H :- B) -> Q = B ; H=T0, Q = true),
177 '$yap_strip_module'(P, M, T),
178 '$yap_strip_module'(M0:H, M1, H1),
179 (
180 M == M1
181 ->
182 H1 = T
183 ;
184 M1:H1 = T
185 ).
186clause(V0,Q,R) :-
187 '$yap_strip_module'(V0, M, V),
188 '$follow_import_chain'(M,V,ExportingMod,V0),
189 must_be_of_type( callable, V0 ),
190 '$predicate_type'(V0,ExportingMod,Type),
191 '$clause'(Type,V0,ExportingMod,Q,R).
192
193'$clause'(exo_procedure,P,M,_Q,exo(P)) :-
194 '$execute0'(P, M).
195'$clause'(mega_procedure,P,M,_Q,mega(P)) :-
196 '$execute0'(P, M).
197'$clause'(updatable_procedure, P,M,Q,R) :-
198 '$log_update_clause'(P,M,Q,R).
199'$clause'(source_procedure,P,M,Q,R) :-
200 '$static_clause'(P,M,Q,R).
201'$clause'(dynamic_procedure,P,M,Q,R) :-
202 '$some_recordedp'(M:P), '$some_recordedp',
203 '$recordedp'(M:P,(P:-Q),R).
204'$clause'(system_procedure,P,M,Q,R) :-
205 \+ '$undefined'(P,M),
206 functor(P,Name,Arity),
207 '$do_error'(permission_error(access,private_procedure,Name/Arity),
208 clause(M:P,Q,R)).
209'$clause'(private_procedure,P,M,Q,R) :-
210 functor(P,Name,Arity),
211 '$do_error'(permission_error(access,private_procedure,Name/Arity),
212 clause(M:P,Q,R)).
213'$clause'(static_procedure,P,M,Q,R) :-
214 functor(P,Name,Arity),
215 '$do_error'(permission_error(access,private_procedure,Name/Arity),
216 clause(M:P,Q,R)).
217'$clause'(undefined,P,M,Q,R) :-
218 functor(P,Name,Arity),
219 '$do_error'(permission_error(access,private_procedure,Name/Arity),
220 clause(M:P,Q,R)).
221
222'$init_preds' :-
223 once('$do_static_clause'(_,_,_,_,_)),
224 once.
225'$init_preds' :-
226 once('$do_log_upd_clause0'(_,_,_,_,_,_)),
227 once.
228'$init_preds' :-
229 once('$do_log_upd_clause'(_,_,_,_,_,_)),
230 once.
231'$init_preds' :-
232 once('$do_log_upd_clause_erase'(_,_,_,_,_,_)),
233 once.
234
235'$init_preds'.
236
237:- '$init_preds'.
238
239/** @pred nth_clause(+ _H_, _I_,- _R_)
240
241
242Find the _I_th clause in the predicate defining _H_, and give
243a reference to the clause. Alternatively, if the reference _R_ is
244given the head _H_ is unified with a description of the predicate
245and _I_ is bound to its position.
246
247
248*/
249nth_clause(V,I,R) :-
250 strip_module(V, M1, P), strip_module,
251 '$follow_import_chain'(M1,P,M2,P2),
252 '$nth_clause'(P2, M2, I, R).
253
254
255'$nth_clause'(P,M,I,R) :-
256 var(I), var(R), var,
257 '$clause'(_,P,M,_,R),
258 '$fetch_nth_clause'(P,M,I,R).
259'$nth_clause'(P,M,I,R) :-
260 '$fetch_nth_clause'(P,M,I,R).
261
262/** @pred abolish(+ _P_,+ _N_)
263
264Completely delete the predicate with name _P_ and arity _N_. It will
265remove both static and dynamic predicates. All state on the predicate,
266including whether it is dynamic or static, multifile, or
267meta-predicate, will be lost.
268*/
269abolish(N0,A) :-
270 strip_module(N0, Mod, N), strip_module,
271 '$abolish'(N,A,Mod).
272
273'$abolish'(N,A,M) :- var(N), var,
274 '$do_error'(instantiation_error,abolish(M:N,A)).
275'$abolish'(N,A,M) :- var(A), var,
276 '$do_error'(instantiation_error,abolish(M:N,A)).
277'$abolish'(N,A,M) :-
278 ( recorded('$predicate_defs','$predicate_defs'(N,A,M,_),R) -> erase(R) ),
279 fail.
280'$abolish'(N,A,M) :- functor(T,N,A),
281 ( '$is_dynamic'(T, M) -> '$abolishd'(T,M) ;
282 /* else */ '$abolishs'(T,M) ).
283
284/** @pred abolish(+ _PredSpec_) is iso
285
286
287Deletes the predicate given by _PredSpec_ from the database. If
288ยงยง _PredSpec_ is an unbound variable, delete all predicates for the
289current module. The
290specification must include the name and arity, and it may include module
291information. Under <tt>iso</tt> language mode this built-in will only abolish
292dynamic procedures. Under other modes it will abolish any procedures.
293
294
295*/
296abolish(X0) :-
297 strip_module(X0,M,X),
298 '$abolish'(X,M).
299
300'$abolish'(X,M) :-
301 current_prolog_flag(language,iso), current_prolog_flag,
302 '$new_abolish'(X,M).
303'$abolish'(X, M) :-
304 '$old_abolish'(X,M).
305
306'$new_abolish'(V,M) :- var(V), var,
307 '$do_error'(instantiation_error,abolish(M:V)).
308'$new_abolish'(A/V,M) :- atom(A), var(V), var,
309 '$do_error'(instantiation_error,abolish(M:A/V)).
310'$new_abolish'(Na//Ar1, M) :-
311 integer(Ar1),
312 integer,
313 Ar is Ar1+2,
314 '$new_abolish'(Na//Ar, M).
315'$new_abolish'(Na/Ar, M) :-
316 functor(H, Na, Ar),
317 '$is_dynamic'(H, M), '$is_dynamic',
318 '$abolishd'(H, M).
319'$new_abolish'(Na/Ar, M) :- % succeed for undefined procedures.
320 functor(T, Na, Ar),
321 '$undefined'(T, M), '$undefined'.
322'$new_abolish'(Na/Ar, M) :-
323 '$do_error'(permission_error(modify,static_procedure,Na/Ar),abolish(M:Na/Ar)).
324'$new_abolish'(T, M) :-
325 '$do_error'(type_error(predicate_indicator,T),abolish(M:T)).
326
327'$abolish_all'(M) :-
328 '$current_predicate'(Na, M, S, _),
329 functor(S, Na, Ar),
330 '$new_abolish'(Na/Ar, M),
331 '$new_abolish'.
332'$abolish_all'(_).
333
334'$abolish_all_atoms'(Na, M) :-
335 '$current_predicate'(Na,M,S,_),
336 functor(S, Na, Ar),
337 '$new_abolish'(Na/Ar, M),
338 '$new_abolish'.
339'$abolish_all_atoms'(_,_).
340
341'$check_error_in_predicate_indicator'(V, Msg) :-
342 var(V), var,
343 '$do_error'(instantiation_error, Msg).
344'$check_error_in_predicate_indicator'(M:S, Msg) :- '$check_error_in_predicate_indicator',
345 '$check_error_in_module'(M, Msg),
346 '$check_error_in_predicate_indicator'(S, Msg).
347'$check_error_in_predicate_indicator'(S, Msg) :-
348 S \= _/_,
349 S \= _//_, '$check_error_in_predicate_indicator',
350 '$do_error'(type_error(predicate_indicator,S), Msg).
351'$check_error_in_predicate_indicator'(Na/_, Msg) :-
352 var(Na), var,
353 '$do_error'(instantiation_error, Msg).
354'$check_error_in_predicate_indicator'(Na/_, Msg) :-
355 \+ atom(Na), atom,
356 '$do_error'(type_error(atom,Na), Msg).
357'$check_error_in_predicate_indicator'(_/Ar, Msg) :-
358 var(Ar), var,
359 '$do_error'(instantiation_error, Msg).
360'$check_error_in_predicate_indicator'(_/Ar, Msg) :-
361 \+ integer(Ar), integer,
362 '$do_error'(type_error(integer,Ar), Msg).
363'$check_error_in_predicate_indicator'(_/Ar, Msg) :-
364 Ar < 0, '$check_error_in_predicate_indicator',
365 '$do_error'(domain_error(not_less_than_zero,Ar), Msg).
366% not yet implemented!
367%'$check_error_in_predicate_indicator'(Na/Ar, Msg) :-
368% Ar < maxarity, !,
369% '$do_error'(type_error(representation_error(max_arity),Ar), Msg).
370
371'$check_error_in_module'(M, Msg) :-
372 var(M), var,
373 '$do_error'(instantiation_error, Msg).
374'$check_error_in_module'(M, Msg) :-
375 \+ atom(M), atom,
376 '$do_error'(type_error(atom,M), Msg).
377
378'$old_abolish'(V,M) :- var(V), var,
379 ( true -> % current_prolog_flag(language, sicstus) ->
380 '$do_error'(instantiation_error,abolish(M:V))
381 ;
382 '$abolish_all_old'(M)
383 ).
384'$old_abolish'(N/A, M) :- '$old_abolish',
385 '$abolish'(N, A, M).
386'$old_abolish'(A,M) :- atom(A), atom,
387 ( current_prolog_flag(language, iso) ->
388 '$do_error'(type_error(predicate_indicator,A),abolish(M:A))
389 ;
390 '$abolish_all_atoms_old'(A,M)
391 ).
392'$old_abolish'([], _) :- '$old_abolish'.
393'$old_abolish'([H|T], M) :- '$old_abolish', '$old_abolish'(H, M), '$old_abolish'(T, M).
394'$old_abolish'(T, M) :-
395 '$do_error'(type_error(predicate_indicator,T),abolish(M:T)).
396
397'$abolish_all_old'(M) :-
398 '$current_predicate'(Na, M, S, _),
399 functor( S, Na, Ar ),
400 '$abolish'(Na, Ar, M),
401 '$abolish'.
402'$abolish_all_old'(_).
403
404'$abolish_all_atoms_old'(Na, M) :-
405 '$current_predicate'(Na, M, S, _),
406 functor(S, Na, Ar),
407 '$abolish'(Na, Ar, M),
408 '$abolish'.
409'$abolish_all_atoms_old'(_,_).
410
411'$abolishs'(G, M) :- '$system_predicate'(G,M), '$system_predicate',
412 functor(G,Name,Arity),
413 '$do_error'(permission_error(modify,static_procedure,Name/Arity),abolish(M:G)).
414'$abolishs'(G, Module) :-
415 current_prolog_flag(language, sicstus), % only do this in sicstus mode
416 '$undefined'(G, Module),
417 functor(G,Name,Arity),
418 print_message(warning,no_match(abolish(Module:Name/Arity))).
419'$abolishs'(G, M) :-
420 '$is_multifile'(G,M),
421 functor(G,Name,Arity),
422 recorded('$mf','$mf_clause'(_,Name,Arity,M,_Ref),R),
423 erase(R),
424% no need erase(Ref),
425 erase.
426'$abolishs'(T, M) :-
427 recorded('$import','$import'(_,M,_,T,_,_),R),
428 '$purge_clauses'(T,M),
429 erase(R),
430 erase.
431'$abolishs'(G, M) :-
432 '$purge_clauses'(G, M), '$purge_clauses'.
433'$abolishs'(_, _).
434
435/** @pred stash_predicate(+ _Pred_)
436Make predicate _Pred_ invisible to new code, and to `current_predicate/2`,
437`listing`, and friends. New predicates with the same name and
438functor can be declared.
439 **/
440stash_predicate(P0) :-
441 strip_module(P0, M, P),
442 '$stash_predicate2'(P, M).
443
444'$stash_predicate2'(V, M) :- var(V), var,
445 '$do_error'(instantiation_error,stash_predicate(M:V)).
446'$stash_predicate2'(N/A, M) :- '$stash_predicate2',
447 functor(S,N,A),
448 '$stash_predicate'(S, M) .
449'$stash_predicate2'(PredDesc, M) :-
450 '$do_error'(type_error(predicate_indicator,PredDesc),stash_predicate(M:PredDesc)).
451
452/** @pred hide_predicate(+ _Pred_)
453Make predicate _Pred_ invisible to `current_predicate/2`,
454`listing`, and friends.
455
456 **/
457
458
459/** @pred predicate_property( _P_, _Prop_) is iso
460
461
462For the predicates obeying the specification _P_ unify _Prop_
463 with a property of _P_. These properties may be:
464
465+ `built_in `
466true for built-in predicates,
467
468+ `dynamic`
469true if the predicate is dynamic
470
471+ `static `
472true if the predicate is static
473
474+ `meta_predicate( _M_) `
475true if the predicate has a meta_predicate declaration _M_.
476
477+ `multifile `
478true if the predicate was declared to be multifile
479
480+ `
481imported_from( _Mod_) `
482true if the predicate was imported from module _Mod_.
483
484+ `exported `
485true if the predicate is exported in the current module.
486
487+ `public`
488true if the predicate is public; note that all dynamic predicates are
489public.
490
491+ `tabled `
492true if the predicate is tabled; note that only static predicates can
493be tabled in YAP.
494
495+ `source (predicate_property flag) `
496true if source for the predicate is available.
497
498+ `number_of_clauses( _ClauseCount_) `
499Number of clauses in the predicate definition. Always one if external
500or built-in.
501
502*/
503predicate_property(Pred,Prop) :-
504 strip_module(Pred, Mod, TruePred),
505 is_callable(TruePred),
506 '$predicate_property2'(TruePred,Prop0,Mod),
507 Prop0 = Prop.
508
509'$predicate_property2'(Pred, Prop, Mod) :-
510 var(Mod), var,
511 '$all_current_modules'(Mod),
512 '$predicate_property2'(Pred, Prop, Mod).
513'$predicate_property2'(Pred,Prop,M0) :-
514 var(Pred), var,
515 (M = M0 ;
516 M0 \= prolog, M = prolog ;
517 M0 \= user, M = user), % prolog and user modules are automatically incorporate in every other module
518 '$generate_all_preds_from_mod'(Pred, SourceMod, M),
519 '$predicate_property'(Pred,SourceMod,M,Prop).
520'$predicate_property2'(M:Pred,Prop,_) :- '$predicate_property2',
521 '$predicate_property2'(Pred,Prop,M).
522'$predicate_property2'(Pred,Prop,Mod) :-
523 '$pred_exists'(Pred,Mod), '$pred_exists',
524 '$predicate_property'(Pred,Mod,Mod,Prop).
525'$predicate_property2'(Pred,Prop,Mod) :-
526 '$import_chain'(Mod,Pred,M,NPred),
527 M \= Mod,
528 (
529 Prop = imported_from(M)
530 ;
531 '$predicate_property'(NPred,M,Mod,Prop),
532 Prop \= '$predicate_property'
533 ).
534
535'$generate_all_preds_from_mod'(Pred, M, M) :-
536 '$current_predicate'(_Na,M,Pred,_).
537
538'$predicate_property'(P,M,_,built_in) :-
539 '$is_system_predicate'(P,M).
540'$predicate_property'(P,M,_,source) :-
541 '$predicate_flags'(P,M,F,F),
542 F /\ 0'$predicate_flags' =\= 0.
543'$predicate_property'(P,M,_,tabled) :-
544 '$predicate_flags'(P,M,F,F),
545 F /\ 0'$predicate_flags' =\= 0.
546'$predicate_property'(P,M,_,dynamic) :-
547 '$is_dynamic'(P,M).
548'$predicate_property'(P,M,_,static) :-
549 \+ '$is_dynamic'(P,M),
550 \+ '$undefined'(P,M).
551'$predicate_property'(P,M,_,meta_predicate(Q)) :-
552 functor(P,Na,Ar),
553 functor(Q,Na,Ar),
554 (recorded('$m', meta_predicate(M,Q),_);recorded('$m', meta_predicate(prolog,Q),_)).
555
556'$predicate_property'(P,M,_,multifile) :-
557 '$is_multifile'(P,M).
558'$predicate_property'(P,M,_,public) :-
559 '$is_public'(P,M).
560'$predicate_property'(P,M,_,thread_local) :-
561 '$is_thread_local'(P,M).
562'$predicate_property'(P,M,M,exported) :-
563 functor(P,N,A),
564 once(recorded('$module','$module'(_TFN,M,_S,Publics,_L),_)),
565 once:memberchk(N/A,Publics).
566'$predicate_property'(P,Mod,_,number_of_clauses(NCl)) :-
567 '$number_of_clauses'(P,Mod,
568 NCl).
569'$predicate_property'(P,ContextMod,_,imported_from(Mod)) :-
570 recorded('$import','$import'(Mod,ContextMod,_G0,P,_N1,_K),_).
571
572/**
573 @pred predicate_statistics( _P_, _NCls_, _Sz_, _IndexSz_)
574
575Given predicate _P_, _NCls_ is the number of clauses for
576 _P_, _Sz_ is the amount of space taken to store those clauses
577(in bytes), and _IndexSz_ is the amount of space required to store
578indices to those clauses (in bytes).
579*/
580predicate_statistics(V,NCls,Sz,ISz) :- var(V), var,
581 '$do_error'(instantiation_error,predicate_statistics(V,NCls,Sz,ISz)).
582predicate_statistics(P0,NCls,Sz,ISz) :-
583 strip_module(P0, M, P),
584 '$predicate_statistics'(P,M,NCls,Sz,ISz).
585
586'$predicate_statistics'(M:P,_,NCls,Sz,ISz) :- '$predicate_statistics',
587 '$predicate_statistics'(P,M,NCls,Sz,ISz).
588'$predicate_statistics'(P,M,NCls,Sz,ISz) :-
589 '$is_log_updatable'(P, M), '$is_log_updatable',
590 '$lu_statistics'(P,NCls,Sz,ISz,M).
591'$predicate_statistics'(P,M,_,_,_) :-
592 '$is_system_predicate'(P,M), '$is_system_predicate', '$is_system_predicate'.
593'$predicate_statistics'(P,M,_,_,_) :-
594 '$undefined'(P,M), '$undefined', '$undefined'.
595'$predicate_statistics'(P,M,NCls,Sz,ISz) :-
596 '$static_pred_statistics'(P,M,NCls,Sz,ISz).
597
598/** @pred predicate_erased_statistics( _P_, _NCls_, _Sz_, _IndexSz_)
599
600
601Given predicate _P_, _NCls_ is the number of erased clauses for
602 _P_ that could not be discarded yet, _Sz_ is the amount of space
603taken to store those clauses (in bytes), and _IndexSz_ is the amount
604of space required to store indices to those clauses (in bytes).
605
606 */
607predicate_erased_statistics(P,NCls,Sz,ISz) :-
608 var(P), var,
610 predicate_erased_statistics(P,NCls,Sz,ISz).
611predicate_erased_statistics(P0,NCls,Sz,ISz) :-
612 strip_module(P0,M,P),
613 '$predicate_erased_statistics'(M:P,NCls,Sz,_,ISz).
614
615/** @pred current_predicate( _A_, _P_)
616
617Defines the relation: _P_ is a currently defined predicate whose name is the atom _A_.
618*/
619current_predicate(A,T0) :-
620 '$yap_strip_module'(T0, M, T),
621 ( var(M) -> '$all_current_modules'(M) ; '$all_current_modules' ),
622 (nonvar(T) -> functor(T, A, _) ; functor ),
623 '$current_predicate'(A,M, T, user),
624 '$follow_import_chain'(M,T,M00,G00),
625 '$pred_exists'(G00,M00).
626
627/** @pred system_predicate( ?_P_ )
628
629Defines the relation: indicator _P_ refers to a currently defined system predicate.
630*/
631system_predicate(P0) :-
632 '$yap_strip_module'(P0, M0, P),
633 ( M= M0 ; M0 \= user, M = user ; M0 \= prolog, M = prolog ),
634 (
635 var(P)
636 ->
637 P = A/Arity,
638 '$current_predicate'(A, M, T, system),
639 functor(T, A, Arity),
640 '$is_system_predicate'( T, M)
641 ;
642 ground(P), P = A/Arity
643 ->
644 functor(T, A, Arity),
645 '$current_predicate'(A, M, T, system),
646 '$is_system_predicate'( T, M)
647 ;
648 ground(P), P = A//Arity2
649 ->
650 Arity is Arity2+2,
651 functor(T, A, Arity),
652 '$current_predicate'(A, M, T, system),
653 '$is_system_predicate'( T, M)
654 ;
655 P = A/Arity
656 ->
657 '$current_predicate'(A, M, T, system),
658 '$is_system_predicate'( T, M),
659 functor(T, A, Arity)
660 ;
661 P = A//Arity2
662 ->
663 '$current_predicate'(A, M, T, system),
664 '$is_system_predicate'( T, M),
665 functor(T, A, Arity),
666 Arity >= 2,
667 Arity2 is Arity-2
668 ;
669 '$do_error'(type_error(predicate_indicator,P),
670 system_predicate(P0))
671 ).
672
673/** @pred system_predicate( ?A, ?P )
674
675 Succeeds if _A_ is the name of the system predicate _P_. It can be used to test and to enumerate all system predicates.
676
677 YAP also supports the ISO standard built-in system_predicate/1, that
678 provides similar functionality and is compatible with most other Prolog
679 systems.
680
681*/
682system_predicate(A, P0) :-
683 '$yap_strip_module'(P0, M, P),
684 (
685 nonvar(P)
686 ->
687 '$current_predicate'(A, M, P, system),
688 '$is_system_predicate'( P, M)
689 ;
690 '$current_predicate'(A, M, P, system)
691 ).
692
693
694/**
695 @pred current_predicate( F ) is iso
696
697 True if _F_ is the predicate indicator for a currently defined user or
698 library predicate.The indicator _F_ is of the form _Mod_:_Na_/_Ar_ or _Na/Ar_,
699 where the atom _Mod_ is the module of the predicate,
700 _Na_ is the name of the predicate, and _Ar_ its arity.
701*/
703 '$yap_strip_module'(F0, M, F),
704 must_bind_to_type( predicate_indicator, F ),
705 '$c_i_predicate'( F, M ).
706
707'$c_i_predicate'( A/N, M ) :-
708 '$c_i_predicate',
709 (
710 ground(A/N)
711 ->
712 atom(A), integer(N),
713 functor(S, A, N),
714 current_predicate(A, M:S)
715 ;
716 current_predicate(A, M:S),
717 functor(S, A, N)
718 ).
719'$c_i_predicate'( A//N, M ) :-
720 (
721 ground(A)
722 ->
723 atom(A), integer(N),
724 N2 is N+2,
725 functor(S, A, N2),
726 current_predicate(A, M:S)
727 ;
728 current_predicate(A, M:S),
729 functor(S, A, N2),
730 N is N2-2
731 ).
732
733/** @pred current_key(? _A_,? _K_)
734
735
736Defines the relation: _K_ is a currently defined database key whose
737name is the atom _A_. It can be used to generate all the keys for
738 the internal data-base.
739*/
740current_key(A,K) :-
741 '$current_predicate'(A,idb,K,user).
742
743% do nothing for now.
744'$noprofile'(_, _).
745
746'$ifunctor'(Pred,Na,Ar) :-
747 (Ar > 0 ->
748 functor(Pred, Na, Ar)
749 ;
750 Pred = Na
751 ).
752
753
754/** @pred compile_predicates(: _ListOfNameArity_)
755
756
757
758Compile a list of specified dynamic predicates (see dynamic/1 and
759assert/1 into normal static predicates. This call tells the
760Prolog environment the definition will not change anymore and further
761calls to assert/1 or retract/1 on the named predicates
762raise a permission error. This predicate is designed to deal with parts
763of the program that is generated at runtime but does not change during
764the remainder of the program execution.
765 */
767 '$current_module'(Mod),
768 '$compile_predicates'(Ps, Mod, compile_predicates(Ps)).
769
770'$compile_predicates'(V, _, Call) :-
771 var(V), var,
772 '$do_error'(instantiation_error,Call).
773'$compile_predicates'(M:Ps, _, Call) :-
774 '$compile_predicates'(Ps, M, Call).
775'$compile_predicates'([], _, _).
776'$compile_predicates'([P|Ps], M, Call) :-
777 '$compile_predicate'(P, M, Call),
778 '$compile_predicates'(Ps, M, Call).
779
780'$compile_predicate'(P, _M, Call) :-
781 var(P), var,
782 '$do_error'(instantiation_error,Call).
783'$compile_predicate'(M:P, _, Call) :-
784 '$compile_predicate'(P, M, Call).
785'$compile_predicate'(Na/Ar, Mod, _Call) :-
786 functor(G, Na, Ar),
787 findall([G|B],clause(Mod:G,B),Cls),
788 abolish(Mod:Na,Ar),
789 '$add_all'(Cls, Mod).
790
791'$add_all'([], _).
792'$add_all'([[G|B]|Cls], Mod) :-
793 assert_static(Mod:(G:-B)),
794 '$add_all'(Cls, Mod).
795
796
797clause_property(ClauseRef, file(FileName)) :-
798 ( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R)
799 -> recorded
800 ;
801 instance_property(ClauseRef, 2, FileName) ).
802clause_property(ClauseRef, source(FileName)) :-
803 ( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R)
804 -> recorded
805 ;
806 instance_property(ClauseRef, 2, FileName) ).
807clause_property(ClauseRef, line_count(LineNumber)) :-
808 instance_property(ClauseRef, 4, LineNumber),
809 LineNumber > 0.
810clause_property(ClauseRef, fact) :-
811 instance_property(ClauseRef, 3, true).
812clause_property(ClauseRef, erased) :-
813 instance_property(ClauseRef, 0, true).
814clause_property(ClauseRef, predicate(PredicateIndicator)) :-
815 instance_property(ClauseRef, 1, PredicateIndicator).
816
817'$set_predicate_attribute'(M:N/Ar, Flag, V) :-
818 functor(P, N, Ar),
819 '$set_flag'(P, M, Flag, V).
820
821%% '$set_flag'(P, M, trace, off) :-
822% set a predicate flag
823%
824'$set_flag'(P, M, trace, off) :-
825 '$predicate_flags'(P,M,F,F),
826 FN is F \/ 0'$predicate_flags',
827 '$predicate_flags'(P,M,F,FN).
828
829/**
830@}
831*/
832
abolish(+ PredSpec)
abolish(+ P,+ N)
assert_static(: C)
asserta_static(: C)
assertz_static(: C)
clause(+ H, B)
clause(+ H, B,- R)
compile_predicates(: ListOfNameArity)
current_key(? A,? K)
current_predicate( F )
current_predicate( A, P)
hide_predicate(+ Pred)
is_callable( ?_Goal_ )
nth_clause(+ H, I,- R)
Definition: preds.yap:176
predicate_erased_statistics( P, NCls, Sz, IndexSz)
predicate_property( P, Prop)
predicate_statistics( P, NCls, Sz, IndexSz)
stash_predicate(+ Pred)
system_predicate( ?_P_ )
system_predicate( ?A, ?P )
assert(+ C)
assert(+ C,- R)
asserta(+ C)
asserta(+ C,- R)
Definition: preddyns.yap:59
assertz(+ C)
assertz(+ C,- R)
dynamic_predicate(+ P,+ Semantics)
retract(+ C)
retract(+ C,- R)
retractall(+ G)
erase(+ R)
instance(+ R,- T)
findall( T,+ G,- L)
Definition: setof.yap:70
no need for code at this point
once( 0:G)
current_prolog_flag(? Flag,- Value)
print_message(+ Severity, +Term)
ground( T)
atom( T)
functor( T, F, N)
integer( T)
nonvar( T)
var( T)
memberchk(+ Element, + Set)