13
14:- module(general, [
15 mgh/2,
16 built_in/1,
17 repeat_n_times/2,
18 repeat_n_times_loop/2,
19 all/1,
20 prolog_iteration_via_backtracking/1,
21 has_property/3,
22 iso_predicate/4
23]). 24
25:- use_module(library(apply)). 26:- use_module(library(charsio)). 27
33mgh(Mod:Term, Mod:Term_mgh):-
34 !,
35 functor(Term, Functor, Arity),
36 functor(Term_mgh, Functor, Arity).
37
38mgh(Term, Term_mgh):-
39 functor(Term, Functor, Arity),
40 functor(Term_mgh, Functor, Arity).
41
42
50built_in(Head) :-
51 predicate_property(Head, built_in).
52
53
57repeat_n_times(Goal,N) :- 58 nb_setval(repeat_counter,0),
59 repeat_n_times_loop(Goal,N).
60
61repeat_n_times_loop(_,N) :- 62 nb_getval(repeat_counter,V),
63 V == N,
64 !.
65repeat_n_times_loop(Goal,N) :- 66 once(Goal), 67 nb_getval(repeat_counter, I),
68 I2 is I + 1,
69 nb_setval(repeat_counter,I2), 70 repeat_n_times_loop(Goal,N). 71
72
73:- module_transparent prolog_iteration_via_backtracking/1, all/1. 74
75all(G) :- prolog_iteration_via_backtracking(G) .
76
77prolog_iteration_via_backtracking(G) :- (call(G), fail) ; true .
78
79
86has_property(Pred,Prop,1) :-
87 predicate_property(Pred,Prop),
88 !.
89has_property(_Pred,_Prop,0).
90
91
108
109iso_predicate(Name, Arity, Head, MetaHead) :-
110 iso_predicate_(Name, Arity, Head, MetaHead).
111
112:- dynamic(iso_predicate_/4). 113
114collect_iso_predicates :-
115 retractall(iso_predicate_(_, _, _, _)),
116 current_predicate(Name/Arity),
117 Name \== (:),
118 functor(Head, Name, Arity),
119 predicate_property(Head, iso),
120 ( predicate_property(Head, meta_predicate(MetaHead))
121 -> true
122 ; MetaHead = []
123 ),
124 ( iso_predicate_(Name, Arity, _, _)
125 -> true
126 ; assertz(iso_predicate_(Name, Arity, Head, MetaHead))
127 ),
128 fail.
129collect_iso_predicates.
130
131:- initialization(collect_iso_predicates).