About AFP The following Oz code is derived from the examples provided in the book:
      "A Little Java, A Few Patterns" by Matthias Felleisen and Daniel P. Friedman.
      http://www.ccs.neu.edu/home/matthias/BALJ/

Chapter #4 Examples in Oz
%%%%%%%%%%%%%%%%%%% Chapter - 4 %%%%%%%%%%%%%%%%%%%%%%

% 4.4
class OnlyOnionsV
   meth init skip end
   meth forSkewer(?$) true end
   meth forOnion(S ?$) {S onlyOnions($)} end
   meth forLamb(S ?$) false end
   meth forTomato(S ?$) false end
end

% 4.36
class IsVegetarianV
   meth init skip end
   meth forSkewer(?$) true end
   meth forOnion(S ?$) {S isVegetarian($)} end
   meth forLamb(S ?$) false end
   meth forTomato(S ?$) {S isVegetarian($)} end
end

% 4.16
class ShishD
   feat
      ooFn : {New OnlyOnionsV init}
      ivFn : {New IsVegetarianV init}
   meth init skip end
   meth onlyOnions(?$) raise abstract() end end
   meth isVegetarian(?$) raise abstract() end end
end
class Skewer from ShishD
   meth init skip end
   meth onlyOnions(?$) {self.ooFn forSkewer($)} end
   meth isVegetarian(?$) {self.ivFn forSkewer($)} end
end
class Onion from ShishD
   feat Shish
   meth init(S) self.Shish = S end
   meth onlyOnions(?$) {self.ooFn forOnion(self.Shish $)} end
   meth isVegetarian(?$) {self.ivFn forOnion(self.Shish $)} end
end
class Lamb from ShishD
   feat Shish
   meth init(S) self.Shish = S end
   meth onlyOnions(?$) {self.ooFn forLamb(self.Shish $)} end
   meth isVegetarian(?$) {self.ivFn forLamb(self.Shish $)} end
end
class Tomato from ShishD
   feat Shish
   meth init(S) self.Shish = S end
   meth onlyOnions(?$) {self.ooFn forTomato(self.Shish $)} end
   meth isVegetarian(?$) {self.ivFn forTomato(self.Shish $)} end
end

% 4.43
class RemoveAnchovyV
   meth init skip end
   meth forCrust(?$) {New Crust init} end
   meth forCheese(P ?$) {New Cheese init({P removeAnchovy($)})} end
   meth forOlive(P ?$) {New Olive init({P removeAnchovy($)})} end
   meth forAnchovy(P ?$) {P removeAnchovy($)} end
   meth forSausage(P ?$) {New Sausage init({P removeAnchovy($)})} end
end
class TopAnchovyWithCheeseV
   meth init skip end
   meth forCrust(?$) {New Crust init} end
   meth forCheese(P ?$) {New Cheese init({P topAnchovyWithCheese($)})} end
   meth forOlive(P ?$) {New Olive init({P topAnchovyWithCheese($)})} end
   meth forAnchovy(P ?$) {New Cheese init({New Anchovy init({P topAnchovyWithCheese($)})})} end
   meth forSausage(P ?$) {New Sausage init({P topAnchovyWithCheese($)})} end
end
class SubstituteAnchovyByCheeseV
   meth init skip end
   meth forCrust(?$) {New Crust init} end
   meth forCheese(P ?$) {New Cheese init({P substituteAnchovyByCheese($)})} end
   meth forOlive(P ?$) {New Olive init({P substituteAnchovyByCheese($)})} end
   meth forAnchovy(P ?$) {New Cheese init({P substituteAnchovyByCheese($)})} end
   meth forSausage(P ?$) {New Sausage init({P substituteAnchovyByCheese($)})} end
end

% 4.41
class PizzaD
   feat
      remFn : {New RemoveAnchovyV init}
      topFn : {New TopAnchovyWithCheeseV init}
      subFn : {New SubstituteAnchovyByCheeseV init}
   meth removeAnchovy(?$) raise abstract() end end
   meth topAnchovyWithCheese(?$) raise abstract() end end
   meth substituteAnchovyByCheese(?$) raise abstract() end end
end
class Crust from PizzaD
   meth init skip end
   meth removeAnchovy(?$) {self.remFn forCrust($)} end
   meth topAnchovyWithCheese(?$) {self.topFn forCrust($)} end
   meth substituteAnchovyByCheese(?$) {self.subFn forCrust($)} end
end
class Cheese from PizzaD
   feat P
   meth init(Pi) self.P = Pi end
   meth removeAnchovy(?$) {self.remFn forCheese(self.P $)} end
   meth topAnchovyWithCheese(?$) {self.topFn forCheese(self.P $)} end
   meth substituteAnchovyByCheese(?$) {self.subFn forCheese(self.P $)} end
end
class Olive from PizzaD
   feat P
   meth init(Pi) self.P = Pi end
   meth removeAnchovy(?$) {self.remFn forOlive(self.P $)} end
   meth topAnchovyWithCheese(?$) {self.topFn forOlive(self.P $)} end
   meth substituteAnchovyByCheese(?$) {self.subFn forOlive(self.P $)} end
end
class Anchovy from PizzaD
   feat P
   meth init(Pi) self.P = Pi end
   meth removeAnchovy(?$) {self.remFn forAnchovy(self.P $)} end
   meth topAnchovyWithCheese(?$) {self.topFn forAnchovy(self.P $)} end
   meth substituteAnchovyByCheese(?$) {self.subFn forAnchovy(self.P $)} end
end
class Sausage from PizzaD
   feat P
   meth init(Pi) self.P = Pi end
   meth removeAnchovy(?$) {self.remFn forSausage(self.P $)} end
   meth topAnchovyWithCheese(?$) {self.topFn forSausage(self.P $)} end
   meth substituteAnchovyByCheese(?$) {self.subFn forSausage(self.P $)} end
end

Chris Rathman / Chris.Rathman@tx.rr.com