peano.matzo 640 B

123456789101112131415161718192021222324252627282930313233
  1. isZero := { [Z] => True; [<S,_>] => False };
  2. add := { [Z] => { [y] => y }
  3. ; [<S,x>] => { [y] => add[x][<S,y>] } };
  4. incr := add[<S,Z>];
  5. two := <S,<S,Z>>;
  6. four := <S,<S,<S,<S,Z>>>>;
  7. if := { [True] => { [x] => { [_] => x } }
  8. ; [False] => { [_] => { [y] => y } }
  9. };
  10. minusOne := { [Z] => Z; [<S,x>] => x };
  11. puts "S is " S;
  12. puts "Z is " Z;
  13. puts "True is " True;
  14. puts "False is " False;
  15. puts "Is 0 zero?";
  16. puts isZero[Z];
  17. puts "Is 4 zero?";
  18. puts isZero[four];
  19. puts "2 + 4 = ";
  20. puts add[four][two];
  21. puts "Is zero zero?";
  22. puts if[isZero[Z]]["yes"]["no"];
  23. puts "Is 0+1 zero?";
  24. puts if[isZero[incr[Z]]]["yes"]["no"];