public static PeanoNumber fromInteger(int num) { // System.Console.WriteLine("fromInteger({0})", num); if (num == 0) { // System.Console.WriteLine("zero"); return(new Zero()); } else { // System.Console.WriteLine("entering recursive call"); PeanoNumber tPNum = PeanoNumber.fromInteger(num - 1); return(of(tPNum)); } }
public static void Main() { PeanoNumber pNum = PeanoNumber.fromInteger(2); System.Console.WriteLine("PeanoNumber set to 2"); pNum.print(); System.Console.WriteLine(""); PeanoNumber tNum = PeanoNumber.fromInteger(1); System.Console.WriteLine("PeanoNumber set to 1"); tNum.print(); System.Console.WriteLine(""); System.Console.WriteLine("add 2 and 1"); PeanoNumber total = pNum + tNum; total.print(); System.Console.WriteLine(""); }