@@ -7,61 +7,187 @@ import io.github.kelvindev15.prolog.core.{Constant, Prolog, Struct, Term}
7
7
8
8
import scala .annotation .targetName
9
9
10
- enum AssociativitySpec extends Atom :
10
+ protected enum AssociativitySpec extends Atom :
11
11
case fx, fy, xf, xfx, xfy, yfx, yfy
12
12
override val value : String = toString
13
13
override val unquotedValue : String = value
14
14
15
- trait DSLPrologBuiltins :
15
+ protected trait DSLPrologBuiltins :
16
16
dsl : PrologDSL =>
17
17
export AssociativitySpec .*
18
18
19
+ /** Returns a [[Directive ]]
20
+ *
21
+ * @param terms the arguments of the directive.
22
+ */
19
23
@ targetName(" iff" )
20
24
def :- (terms : Term * ): Directive = Directive (terms * )
21
25
26
+ /** Builds a var(X) [[Struct ]].
27
+ *
28
+ * @param term the argument of the structure
29
+ */
22
30
def `var` (term : Term ): Struct = Struct (Atom (" var" ), term)
31
+
32
+ /** Builds a nonvar(X) [[Struct ]].
33
+ *
34
+ * @param term the argument of the structure
35
+ */
23
36
def nonvar (term : Term ): Struct = Struct (Atom (" nonvar" ), term)
37
+
38
+ /** Builds a atom(X) [[Struct ]].
39
+ *
40
+ * @param term the argument of the structure
41
+ */
24
42
def atom (term : Term ): Struct = Struct (Atom (" atom" ), term)
43
+
44
+ /** Builds a number(X) [[Struct ]].
45
+ *
46
+ * @param term the argument of the structure
47
+ */
25
48
def number (term : Term ): Struct = Struct (Atom (" number" ), term)
49
+
50
+ /** Builds an atomic(X) [[Struct ]].
51
+ *
52
+ * @param term the argument of the structure
53
+ */
26
54
def atomic (term : Term ): Struct = Struct (Atom (" atomic" ), term)
55
+
56
+ /** Builds a ground(X) [[Struct ]].
57
+ *
58
+ * @param term the argument of the structure
59
+ */
27
60
def ground (term : Term ): Struct = Struct (Atom (" ground" ), term)
28
61
62
+ /** Returns a member(t, l) [[Struct ]].
63
+ *
64
+ * @param term a term
65
+ * @param l a term that should unify to a list.
66
+ */
29
67
def member (term : Term , l : Term ): Struct = Struct (Atom (" member" ), term, l)
68
+
69
+ /** Returns an append(l1, l2) [[Struct ]].
70
+ *
71
+ * @param l1 a term that should unify to a list
72
+ * @param l2 a term that should unify to a list.
73
+ */
30
74
def append (l1 : Term , l2 : Term ): Struct = Struct (Atom (" append" ), l1, l2)
31
75
76
+ /** Returns a dynamic(t1, t2, ...) [[Struct ]].
77
+ *
78
+ * @param indicators the indicators of the predicates.
79
+ */
32
80
def dynamic (indicators : Indicator * ): Struct =
33
81
Directive (Struct (Atom (" dynamic" ), Conjunction .wrapIfNecessary(indicators* )))
34
82
35
83
def clause (head : Term , body : Term ): Struct = Struct (Atom (" clause" ), head, body)
84
+
85
+ /** Returns an asserta(X) [[Struct ]].
86
+ *
87
+ * @param clause the clause to assert.
88
+ */
36
89
def asserta (clause : Term ): Struct = Struct (Atom (" asserta" ), clause)
90
+
91
+ /** Returns an assertz(X) [[Struct ]].
92
+ *
93
+ * @param clause the clause to assert.
94
+ */
37
95
def assertz (clause : Term ): Struct = Struct (Atom (" assertz" ), clause)
96
+
97
+ /** Returns an retract(X) [[Struct ]].
98
+ *
99
+ * @param clause the clause to retract.
100
+ */
101
+
38
102
def retract (clause : Term ): Struct = Struct (Atom (" retract" ), clause)
39
103
104
+ /** Returns a functor(T, F, N) [[Struct ]].
105
+ *
106
+ * @param term a term.
107
+ * @param functor a term that should unify with the of the [[term ]] functor.
108
+ * @param arity a term that should unify with the arity of the [[term ]].
109
+ */
40
110
def functor (term : Term , functor : Term , arity : Term ): Struct =
41
111
Struct (Atom (" functor" ), term, functor, arity)
42
112
113
+ /** Returns an arg(N, T, L) [[Struct ]].
114
+ *
115
+ * @param number a term that should unify with the position of the [[arg ]] in [[term ]].
116
+ * @param term a term
117
+ * @param arg a term that should unify the with [[number ]]-th argument in [[term ]].
118
+ */
43
119
def arg (number : Term , term : Struct , arg : Term ): Struct = Struct (Atom (" arg" ), number, term, arg)
44
120
121
+ /** Returns an atom_chars(A, L) [[Struct ]].
122
+ *
123
+ * @param atom a term that should unify to an atom.
124
+ * @param list a term that should unify to a list containing the characters of [[atom ]].
125
+ */
45
126
def atom_chars (atom : Term , list : Term ): Struct = Struct (Atom (" atom_chars" ), atom, list)
127
+
128
+ /** Returns an number_chars(A, L) [[Struct ]].
129
+ *
130
+ * @param atom a term that should unify to an numeric constant
131
+ * @param list a term that should unify with a list containing the characters composing the constant.
132
+ */
46
133
def number_chars (atom : Term , list : Term ): Struct = Struct (Atom (" number_chars" ), atom, list)
47
134
135
+ /** The cut predicate */
48
136
@ targetName(" cut" )
49
137
val `!` : Atom = Atom (" !" )
50
138
139
+ /** The repeat predicate */
51
140
val repeat : Atom = Atom (" repeat" )
52
141
142
+ /** Builds a goal(G) [[Struct ]].
143
+ *
144
+ * @param goal the argument of the structure
145
+ */
53
146
def call (goal : Term ): Struct = Struct (Atom (" call" ), goal)
147
+
148
+ /** Builds a once(G) [[Struct ]].
149
+ *
150
+ * @param goal the argument of the structure
151
+ */
54
152
def once (goal : Term ): Struct = Struct (Atom (" once" ), goal)
153
+
154
+ /** Builds a not(G) [[Struct ]].
155
+ *
156
+ * @param goal the argument of the structure
157
+ */
55
158
def not (goal : Term ): Struct = Struct (Atom (" not" ), goal)
56
159
160
+ /** Returns a findall(T, G, L) [[Struct ]].
161
+ *
162
+ * @param res
163
+ * @param goal
164
+ * @param list a term that should unify to a list containing ???
165
+ */
57
166
def findall (res : Term , goal : Term , list : Term ): Struct = Struct (Atom (" findall" ), res, goal, list)
58
-
167
+
168
+ /** Builds a \+(X) [[Struct ]].
169
+ *
170
+ * @param goal the argument of the structure
171
+ */
59
172
@ targetName(" naf" )
60
173
def ! (goal : Term ): Struct = Struct (Atom (" \\ +" ), goal)
61
174
175
+ /** Returns an op(I, A, N) [[Struct ]].
176
+ *
177
+ * @param precedence
178
+ * @param associativity
179
+ * @param name
180
+ */
62
181
def op (precedence : Constant .Numeric , associativity : AssociativitySpec , name : Atom ): Struct =
63
182
Struct (Atom (" op" ), precedence, associativity, name)
64
183
184
+ /** Returns a length(T, L) [[Struct ]].
185
+ *
186
+ * @param term
187
+ * @param len
188
+ */
65
189
def length (term : Term , len : Term ): Struct = Struct (Atom (" length" ), term, len)
190
+
191
+ /** An empty list functor */
66
192
val `[]` : Atom = Prolog .Functors .EMPTY_LIST
67
193
0 commit comments