Old wrong solution to the inlaws problem: ========================================= Boaz helped me work out the details. Precise definitions will be ready soon in the paper. > From Mike Werner: >I am wondering if the latest formulation of a "strategy" >would allow an elegant strategy for the inlaws problem I >presented last year: > >A person object has a reference, spouse to another person object, >and siblings to a set of Person objects. An inlaw is either the >spouse of a sibling or the sibling of a spouse. The task is >to find all the inlaws of a given person. Excellent question. Here are some possibilities: Class graph: Person = [ Person] [ NList(Person)]. NList(S) ~ S {S}. ========================================================== Wrong solution 1: ========================================================== The strategy graph is cyclic and has one node labeled Person. Person . ( through -> *,spouse,* Person . through -> *,siblings,* Person + through -> *,siblings,* Person . through -> *,spouse,* Person ) Why wrong: There is no state information in the strategy graph which remembers what has already been traversed. Notice that in Demeter/C++ and in Demeter/Java the above expression would result in 5 nodes labeled Person. We have now a different semantics! ========================================================== Wrong solution 2: ========================================================== The strategy graph is acyclic and has 4 distict nodes labeled Person. start#Person . ( through -> *,spouse,* sp#Person . through -> *,siblings,* inlaw#Person + through -> *,siblings,* si#Person . through -> *,spouse,* inlaw#Person ) Why wrong: The spouse relation is symmetric. We can go from Person through spouse to Person through spouse to Person through siblings to Person ending up with your sister which is definitely not one of your inlaws. ========================================================== Correct solution (still incorrect): ========================================================== The strategy graph is acyclic and has 4 distict nodes labeled Person. through! means that the edge may be taken only once. start#Person . ( - through! -> *,spouse,* sp#Person . - through -> *,siblings,* inlaw#Person + - through -> *,siblings,* si#Person . - through! -> *,spouse,* inlaw#Person ) Variation: start#Person . ( through-odd -> *,spouse,* sp#Person . through -> *,siblings,* inlaw#Person + through -> *,siblings,* si#Person . through-odd -> *,spouse,* inlaw#Person ) We know that the spouse relation is symmetric. through-odd means that the edge may be taken an odd number of times. It is ok to allow to go through spouse an odd number of times. Also notice that siblings is transitive. Therefore it is ok to traverse siblings multiple times. ========================================================== Wrong solution 3: ========================================================== The strategy graph is cyclic and has one node labeled Person. through! means that the edge may be taken only once. Person . ( through! -> *,spouse,* Person . through! -> *,siblings,* Person + through! -> *,siblings,* Person . through! -> *,spouse,* Person ) ========================================================== Why wrong: same reason as for wrong solution 1. > > Mike >