YAP
7.1.0
Toggle main menu visibility
Main Page
Related Pages
Modules
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
y
~
Functions
a
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
y
~
Variables
a
c
e
f
g
i
k
m
n
o
p
q
r
s
t
v
Files
File List
File Members
All
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
y
Functions
c
e
m
y
Variables
Typedefs
Enumerations
Enumerator
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
y
Macros
•
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
clauses.yap
Go to the documentation of this file.
1
/**
2
* @file clauses.yap
3
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
4
* @date Tue Nov 17 14:51:30 2015
5
*
6
* @brief Utilities for clause manipulation.
7
*
8
*
9
*/
10
11
:- module(
clauses
,
12
[
list2conj/2,
13
conj2list/2,
14
clauselength/2]).
15
16
17
/**
18
* @defgroup clauses Clause Manipulation
19
* @ingroup YAPLibrary
20
* @{
21
22
This library supports a number of useful utilities that come up over and
23
over again when manipulating Prolog programs. This will include
24
operations and conversion to other structures.
25
26
*/
27
28
/** conj2list( +Conj, -List) is det
29
Generate a list from a conjunction of literals.
30
31
It is often easier to apply operations on lists than on clauses
32
*/
33
conj2list(
M
:
Conj
,
List
)
:-
34
conj2list_(
Conj
,
M
,
List
, [] ).
35
36
conj2list(
Conj
,
List
)
:-
37
conj2list_(
Conj
,
List
, [] ).
38
39
40
conj2list_(
C
)
-->
41
{
var
(
C
) },
42
!,
43
[
C
].
44
conj2list_( true )
-->
conj2list_.
45
conj2list_( (
C1
,
C2
) )
-->
46
conj2list_,
47
conj2list_(
C1
),
48
conj2list_(
C2
).
49
conj2list_(
C
)
-->
50
[
C
].
51
52
conj2list_(
C
,
M
)
-->
53
{
var
(
C
) },
54
!,
55
[
M
:
C
].
56
conj2list_( true ,
_
)
-->
conj2list_.
57
conj2list_( (
C1
,
C2
),
M
)
-->
58
conj2list_,
59
conj2list_(
C1
,
M
),
60
conj2list_(
C2
,
M
).
61
conj2list_(
C
,
M
)
-->
62
{
strip_module(
M
:
C
,
NM
,
NC
) },
63
[
NM
:
NC
].
64
65
/** list2conj( +List, -Conj) is det
66
Generate a conjunction from a list of literals.
67
68
Notice Mthat this relies on indexing within the list to avoid creating
69
choice-points.
70
*/
71
list2conj([], true).
72
list2conj([
Last
],
Last
).
73
list2conj([
Head
,
Next
|
Tail
], (
Head
,
Goals
))
:-
74
list2conj([
Next
|
Tail
],
Goals
).
75
76
/** clauselength( +Clause, -Length) is det
77
Count the number of literals in a clause (head counts as one).
78
79
Notice that this is 1+length(conj2list), as we ignore disjunctions.
80
*/
81
clauselength( (
_Head
:-
Conj
),
Length
)
:-
82
clauselength(
Conj
,
Length
,
1
).
83
84
85
clauselength(
C
,
I1
,
I
)
:-
86
var
(
C
),
87
var,
88
I1
is
I
+
1
.
89
clauselength( (
C1
,
C2
),
I2
,
I
)
:-
clauselength,
90
clauselength(
C1
,
I1
,
I
),
91
clauselength(
C2
,
I2
,
I1
).
92
clauselength(
_C
,
I1
,
I
)
:-
93
I1
is
I
+
1
.
94
95
%% @}
96
var/1
var( T)
library
clauses.yap
Generated by
1.9.3