About LML The following Oz code is derived from the examples provided in the book:
      "The Little MLer" by Matthias Felleisen and Daniel P. Friedman.
      http://www.ccs.neu.edu/home/matthias/BTML/

Chapter #5 Examples in Oz
%%%%%%%%%%%%%%%%%%% Chapter - 5 %%%%%%%%%%%%%%%%%%%%%%

% 5.4
{Browse 4#topping(anchovy topping(tuna topping(anchovy bottom)))}

% 5.5
{Browse 5#topping(tuna topping(anchovy bottom))}

% 5.6
{Browse 6#topping(anchovy bottom)}

% 5.7
{Browse 7#bottom}

% 5.11
fun {RemoveAnchovy P}
   case P
   of bottom             then bottom
   [] topping(anchovy X) then {RemoveAnchovy X}
   [] topping(tuna X)    then topping(tuna {RemoveAnchovy X})
   [] topping(lox X)     then topping(lox {RemoveAnchovy X})
   end
end

% 5.8
{Browse 8#{RemoveAnchovy topping(lox topping(anchovy topping(tuna topping(anchovy bottom))))}}

% 5.9
{Browse 9#{RemoveAnchovy topping(lox topping(tuna bottom))}}

% 5.13
fun {RemoveAnchovy_ P}
   case P
   of bottom             then bottom
   [] topping(anchovy X) then {RemoveAnchovy_ X}
   [] topping(T X)       then topping(T {RemoveAnchovy_ X})
   end
end

% 5.14
fun {RemoveTuna P}
   case P
   of bottom             then bottom
   [] topping(anchovy X) then topping(anchovy {RemoveTuna X})
   [] topping(tuna X)    then {RemoveTuna X}
   [] topping(lox X)     then topping(lox {RemoveTuna X})
   end
end

% 5.21
fun {RemoveTuna_ P}
   case P
   of bottom             then bottom
   [] topping(anchovy X) then topping(anchovy {RemoveTuna_ X})
   [] topping(tuna X)    then {RemoveTuna_ X}
   [] topping(T X)       then topping(T {RemoveTuna_ X})
   end
end

% 5.28
fun {RemoveFish1 F P}
   case F#P
   of _#bottom                   then bottom
   [] tuna#topping(tuna X)       then {RemoveFish1 tuna X}
   [] tuna#topping(T X)          then topping(T {RemoveFish1 tuna X})
   [] anchovy#topping(anchovy X) then {RemoveFish1 anchovy X}
   [] anchovy#topping(T X)       then topping(T {RemoveFish1 anchovy X})
   [] lox#topping(lox X)         then {RemoveFish1 lox X}
   [] lox#topping(T X)           then topping(T {RemoveFish1 lox X})
   end
end

% 5.30
fun {RemoveFish2 F P}
   case F#P
   of _#bottom                   then bottom
   [] tuna#topping(tuna X)       then {RemoveFish2 tuna X}
   [] tuna#topping(anchovy X)    then topping(anchovy {RemoveFish2 tuna X})
   [] tuna#topping(lox X)        then topping(lox {RemoveFish2 tuna X})
   [] anchovy#topping(tuna X)    then topping(tuna {RemoveFish2 anchovy X})
   [] anchovy#topping(anchovy X) then {RemoveFish2 anchovy X}
   [] anchovy#topping(lox X)     then topping(lox {RemoveFish2 anchovy X})
   [] lox#topping(tuna X)        then topping(tuna {RemoveFish2 lox X})
   [] lox#topping(anchovy X)     then topping(anchovy {RemoveFish2 lox X})
   [] lox#topping(lox X)         then {RemoveFish2 lox X}
   end
end

% 5.35
fun {RemoveFish3 F P}
   case P
   of bottom then bottom
   [] topping(T X) then
      if T == F
         then {RemoveFish3 F X}
         else topping(T {RemoveFish3 F X})
      end
   end
end

% 5.38
fun {EqFish_ X Y}
   case X#Y
   of anchovy#anchovy then true
   [] anchovy#tuna    then false
   [] anchovy#lox     then false
   [] tuna#anchovy    then false
   [] tuna#tuna       then true
   [] tuna#lox        then false
   [] lox#anchovy     then false
   [] lox#tuna        then false
   [] lox#lox         then true
   end
end
fun {EqFish X Y}
   case X#Y
   of anchovy#anchovy then true
   [] tuna#tuna       then true
   [] lox#lox         then true
   [] _#_             then false
   end
end

% 5.39
{Browse 39#{EqFish anchovy anchovy}}

% 5.40
fun {RemoveFish F P}
   case P
   of bottom then bottom
   [] topping(T X) then
      if {EqFish T F}
         then {RemoveFish F X}
         else topping(T {RemoveFish F X})
      end
   end
end

% 5.44
{Browse 44#{RemoveFish anchovy topping(anchovy bottom)}}

% 5.48
{Browse 48#{RemoveFish tuna topping(anchovy topping(tuna topping(anchovy bottom)))}}

% 5.49
{Browse 49#{EqFish anchovy tuna}}

% 5.50
{Browse 50#topping(anchovy {RemoveFish tuna topping(tuna topping(anchovy bottom))})}

% 5.51
{Browse 51#{RemoveFish tuna topping(tuna topping(anchovy bottom))}}

% 5.53
{Browse 53#{RemoveFish tuna topping(anchovy bottom)}}

% 5.57
fun {EqInt X Y} X == Y end
fun {RemoveInt I P}
   case P
   of bottom then bottom
   [] topping(T X) then
      if {EqInt T I}
         then {RemoveInt I X}
         else topping(T {RemoveInt I X})
      end
   end
end

% 5.55
{Browse 55#{RemoveInt 3 topping(2 topping(3 topping(2 bottom)))}}

% 5.66
fun {SubstituteFish N A P}
   case P
   of bottom then bottom
   [] topping(T X) then
      if {EqFish T A}
         then topping(N {SubstituteFish N A X})
         else topping(T {SubstituteFish N A X})
      end
   end
end
fun {SubstituteInt N A P}
   case P
   of bottom then bottom
   [] topping(T X) then
      if {EqFish T A}
         then topping(N {SubstituteInt N A X})
         else topping(T {SubstituteInt N A X})
      end
   end
end

% 5.60
{Browse 60#{SubstituteFish lox anchovy topping(anchovy topping(tuna topping(anchovy bottom)))}}

% 5.63
{Browse 63#{SubstituteInt 5 3 topping(3 topping(2 topping(3 bottom)))}}

% 5.67
{Browse 67#{EqInt 17 0}}

% 5.68
{Browse 68#{EqInt 17 tuna}}

% 5.70
fun {EqNum_ X Y}
   case X#Y
   of zero#zero then true
   [] one_more_than(N)#zero then false
   [] zero#one_more_than(M) then false
   [] one_more_than(N)#one_more_than(M) then {EqNum_ N M}
   end
end

% 5.71
fun {EqNum X Y}
   case X#Y
   of zero#zero then true
   [] one_more_than(N)#one_more_than(M) then {EqNum N M}
   [] _#_ then false
   end
end

% 5.69
{Browse 69#{EqNum one_more_than(zero) one_more_than(zero)}}

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