2 // This is a simple self-contained test of Prop's inference formalism.
7 // gcc -I<prop-include-dir> dates.cc -o dates -L<ADLib-library-dir>
8 // -lad -liostream -lg++
15 // Defines a simple relation(this should be placed in an include file).
16 // Notice that this relation is actually a variant.
17 // In general, we allow variant relations and relations
18 // with arbitrarily complex arguments, just like any ``datatypes.''
19 // In fact, an ``relation'' can be used as a datatype in Prop's
20 // other pattern matching constructs.
22 relation Person = male (char *)
26 relation Animal = animal (char *);
29 // Instantiate the relation: Prop will generate additional methods to
30 // implement the relation type.
31 // (This should be placed in an implementation file.)
33 instantiate relation Person, Animal;
36 // The inference construct defines a new inference class with
37 // a set of inference rules. Each instance of Dates should be
38 // considered an independent (deductive) database.
40 inference class Dates {};
44 // First, say hello to myself, the author.
47 -> { cout << "Hi Al\n"; };
53 -> { cout << p << " is here\n"; };
55 -> { cout << p << " is here\n"; };
58 // Print all pairs of potential couples.
59 // This is basically a simple cartesian product.
61 male (m) and female (f)
62 -> { cout << "Heterosexual couple " << m << " and " << f << '\n'; };
65 // This is the 90's, so try gays and lesbians too.
66 // But make sure we don't print duplicates.
68 male (m1) and male (m2) where (strcmp(m1,m2) < 0)
69 -> { cout << "Gay couple " << m1 << " and " << m2 << '\n'; };
71 female (f1) and female (f2) where (strcmp(f1,f2) < 0)
72 -> { cout << "Lesbian couple " << f1 << " and " << f2 << '\n'; };
77 { // Instantiate an inference object
95 // These facts will not fire any rules, of course.
97 dates << animal ("monkey")
102 // Run the inference engine until it is stable.
103 // The inference rules defined above will be fired and dating
104 // candidates will be printed. Notice that the order in which
105 // this occurs is non-deterministic.
110 // The above is actually an abbreviation for the following loop.
112 // while (! dates.is_stable()) // while not stable
113 // dates.fire(); // execute one rule
117 // Clears the database.
118 // It doesn't have any observable effect in our example, however.