-
Notifications
You must be signed in to change notification settings - Fork 0
/
grounding.pl
executable file
·60 lines (48 loc) · 1.04 KB
/
grounding.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
:- dynamic clause_g/1.
writegroundprogram(String) :-
all_cons(All),
ground_clauses(All, String).
ground_clauses(Atoms, String) :-
retractall( clause_g(_) ),
open(String,write,Out),
( clause(C),
% writeq(first(C)), nl,
term_variables(C, Vs),
instantiate_vs(Vs, Atoms),
% writeq(C), nl,
assert( clause_g(C) ),
write(Out, clause_g(C)),
write(Out, '.\n'),
fail
; true
),
close(Out).
instantiate_vs([], _).
instantiate_vs([X|Xs], Atoms) :-
member(X, Atoms),
instantiate_vs(Xs, Atoms).
all_cons(All) :-
current_predicate(clause/1),
setof(List, get_constants([List]), All) *-> true;
All = [aux_c].
get_constants(List) :-
clause(H :- _),
H =..[_|Atoms],
member(A, Atoms),
A \== 2,
A \== 1,
setof(A, atomic(A), List).
get_constants(List) :-
clause(H :- _),
H =..[_|[Atoms]],
Atoms \== 2,
Atoms \== 1,
setof(Atoms, atomic(Atoms), List).
get_constants(List) :-
clause(_ :- Body),
member(B, Body),
B =..[_|Atoms],
member(A, Atoms),
A \== 2,
A \== 1,
setof(A, atomic(A), List).