10000 prep for external functions · Z80coder/datalog-cpp@01d8615 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01d8615

Browse files
author
wright
committed
prep for external functions
1 parent 5aa0b17 commit 01d8615

File tree

2 files changed

+70
-20
lines changed

2 files changed

+70
-20
lines changed

src/Datalog.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,6 @@ static AtomTypeSpecifier<RELATION_TYPE, Us...> atom(Us&&... args) {
145145
return AtomTypeSpecifier<RELATION_TYPE, Us...>{atom(args...)};
146146
}
147147

148-
#if 0
149-
template <typename RELATION_TYPE, typename ... Us>
150-
static AtomTypeSpecifier<RELATION_TYPE, Us...> head(Us&&... args) {
151-
return atom<RELATION_TYPE, Us...>(args...);
152-
}
153-
154-
template <typename RELATION_TYPE, typename ... Us>
155-
static AtomTypeSpecifier<RELATION_TYPE, Us...> clause(Us&&... args) {
156-
return atom<RELATION_TYPE, Us...>(args...);
157-
}
158-
#endif
159-
160148
template <typename... Ts>
161149
struct Relation
162150
{
@@ -665,7 +653,7 @@ static State<RELATIONs...> fixPoint(RuleSet<RULE_TYPEs...> &ruleSet, const State
665653
applyRuleSet(iteration, stateSizeDelta, ruleSet, newState);
666654
iteration++;
667655
} while (StateType::size(stateSizeDelta) > 0);
668-
cout << "fix point in " << iteration + 1 << " iterations" << endl;
656+
cout << "fix point in " << iteration << " iterations" << endl;
669657
return newState;
670658
}
671659

tests/types_test.cpp

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ bool test2()
7474
{rod, alan},
7575
{robin, alan}};
7676

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>();
8080

8181
// TODO
8282
//auto inDirectAcademicAncestor = atom<AcademicAncestor>(x, z) <= atom<Adviser>(x, y) && atom<AcademicAncestor>(y, z);
@@ -186,19 +186,81 @@ bool po1()
186186
}
187187
#endif
188188

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+
189251
int main()
190252
{
191253
bool ok1 = test1();
192-
bool ok2= test2();
193-
#if 1
254+
bool ok2 = test2();
194255
bool ok3 = po1();
195-
if (!(ok1 and ok2 and ok3)) {
256+
bool ok4 = test4();
257+
258+
if (!(ok1 and ok2 and ok3 and ok4)) {
196259
cout << "FAIL" << endl;
197260
return 1;
198261
} else {
199262
cout << "PASSED" << endl;
200263
return 0;
201264
}
202-
#endif
203265
return 1;
204266
}

0 commit comments

Comments
 (0)
0