Hi Bryan: what are the preferred ways to deal with dependent subtraversals? So far I found two in your examples. Are there more? -- Karl ========================================== Sometimes there is an order dependence between subtraversals. Result of traversal of first part of class A influences traversal of second and third part. Solution: Traverse first part, get result and use it to manually start the traversal of the 2. or 3. part or both. Example: implementation of if-then-else statement in PL. http://www.ccs.neu.edu/home/chadwick/aosd09/exp.beh Inside the Eval class: Eval{{ static Traversal trav = new Traversal(new Eval(), Control.bypass("lang.def.body lang.ifz.thn lang.ifz.els")); public static int eval(exp e){ return eval(e, env.empty); } static int eval(exp e, env ev) { return trav.traverse(e, ev); } int combine(ifz f, int c, exp t, exp e, env ev) { return eval((c==0)?t:e, ev); } Note how field names are avoided. ================================================================ An alternative solution would be to make class A a built-in and write a new traversal from A that goes down the fields that need to be processed first and then start a second traversal that goes down the other fields that need to be traversed. The proper way to implement this is to use a onestep traversal. Example: insert into binary search tree bst = A, new traversal from bst only. http://www.ccs.neu.edu/home/chadwick/aosd09/bst.java.html // Functional Insert Implementation class Insert extends ID{ bst combine(leaf l, int nd){ return new node(nd,l,l); } bst combine(node n, int d, bst l, bst r, int nd){ if(nd < d)return new node(d,insert(l,nd),r); if(nd > d)return new node(d,l,insert(r,nd)); return n; } static Traversal trav = Traversal.onestep(new Insert()); static bst insert(bst t, int d){ return trav.traverse(t, d); } }