-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlanguage_prolog_clause.pro
42 lines (34 loc) · 1.24 KB
/
language_prolog_clause.pro
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
:- module(language_prolog_clause, [
clause_conjuncts/2,
clause_disjuncts/2,
conjuncts_clause/2,
disjuncts_clause/2,
clause_disjunct/2
]).
/** <module> Prolog clause manipulation; part of language_prolog.pro
*/
/**
clause_conjuncts(+Clause, --List).
clause_disjuncts(+Clause, --List).
conjuncts_clause(+List, --Clause).
disjuncts_clause(+List, --Clause).
List must not be empty.
These predicates only work in one direction.
The output argument must be an unbound variable.
Violation of this assumption results in wrong result or non-termination.
*/
clause_conjuncts((A,B),C) :- !, clause_conjuncts(A,AA), clause_conjuncts(B,BB), append(AA,BB,C).
clause_conjuncts(A,[A]) :- A \= (_,_).
conjuncts_clause([J], J) :- !.
conjuncts_clause([JA|JB], (JA,CB)) :- !, conjuncts_clause(JB,CB).
clause_disjuncts((A;B),C) :- !, clause_disjuncts(A,AA), clause_disjuncts(B,BB), append(AA,BB,C).
clause_disjuncts(A,[A]) :- A \= (_;_).
disjuncts_clause([J], J) :- !.
disjuncts_clause([JA|JB], (JA;CB)) :- disjuncts_clause(JB,CB).
/**
clause_disjunct(+Clause, -Disjunct).
Enumerate the outermost disjuncts in Clause.
*/
clause_disjunct((A;_),B) :- clause_disjunct(A,B).
clause_disjunct((_;A),B) :- clause_disjunct(A,B).
clause_disjunct(A,B) :- A \= (_;_), A = B.