@@ -74,9 +74,9 @@ bool test2()
74
74
{rod, alan},
75
75
{robin, alan}};
76
76
77
- auto x = new Variable <Name>();
78
- auto y = new Variable <Name>();
79
- auto z = new Variable <Name>();
77
+ auto x = var <Name>();
78
+ auto y = var <Name>();
79
+ auto z = var <Name>();
80
80
81
81
// TODO
82
82
// auto inDirectAcademicAncestor = atom<AcademicAncestor>(x, z) <= atom<Adviser>(x, y) && atom<AcademicAncestor>(y, z);
@@ -186,19 +186,81 @@ bool po1()
186
186
}
187
187
#endif
188
188
189
+ bool test4 ()
190
+ {
191
+ // Relations
192
+ typedef const char * Name;
193
+ typedef unsigned int Age;
194
+ enum Gender {male, female, NA};
195
+ enum Country {england, scotland, wales, france, germany, netherlands, spain};
196
+ struct Person : Relation<Name, Age, Gender, Country>{};
197
+
198
+ // Extensional data
199
+ Name ian{" Ian" };
200
+ Name anna{" Anna" };
201
+ Name albert{" Albert" };
202
+ Name henry{" Henry" };
203
+ Name rhiannon{" Rhiannon" };
204
+ Name jean{" Jean" };
205
+ Name bas{" Bas" };
206
+
207
+ Person::Set people{
208
+ {ian, 48u , male, scotland},
209
+ {anna, 25u , female, england},
210
+ {albert, 25u , male, germany},
211
+ {henry, 25u , male, england},
212
+ {rhiannon, 25u , female, wales},
213
+ {jean, 25u , male, france},
214
+ {bas, 25u , male, netherlands}
215
+ };
216
+
217
+ auto name = var<Name>();
218
+ auto age = var<Age>();
219
+ auto country = var<Country>();
220
+ auto gender = var<Gender>();
221
+
222
+ struct Female : Relation<Name>{};
223
+ auto females = rule (
224
+ atom<Female>(name),
225
+ atom<Person>(name, age, female, country)
226
+ );
227
+
228
+ #if 0
229
+ typedef float Height;
230
+ struct Height : Relation<Name, Height>{};
231
+
232
+ auto height = rule(
233
+ atom<Height>(name, height),
234
+ bind(height, external(f, atom<Person>(name, age, gender, country)))
235
+ );
236
+ #endif
237
+
238
+ // Apply rules
239
+ State<Person, Female> state{people, {}};
240
+ RuleSet<decltype (females)> rules{
241
+ {females}
242
+ };
243
+
244
+ cout << " before = " << state << endl;
245
+ state = fixPoint (rules, state);
246
+ cout << " after = " << state << endl;
247
+
248
+ return true ;
249
+ }
250
+
189
251
int main ()
190
252
{
191
253
bool ok1 = test1 ();
192
- bool ok2= test2 ();
193
- #if 1
254
+ bool ok2 = test2 ();
194
255
bool ok3 = po1 ();
195
- if (!(ok1 and ok2 and ok3)) {
256
+ bool ok4 = test4 ();
257
+
258
+ if (!(ok1 and ok2 and ok3 and ok4)) {
196
259
cout << " FAIL" << endl;
197
260
return 1 ;
198
261
} else {
199
262
cout << " PASSED" << endl;
200
263
return 0 ;
201
264
}
202
- #endif
203
265
return 1 ;
204
266
}
0 commit comments