peano.scm 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. (use-modules (trs examples))
  2. (use-modules (srfi srfi-64))
  3. (define (number->peano n)
  4. (if (= n 0)
  5. '(z)
  6. `(s ,(number->peano (- n 1)))))
  7. (test-begin "peano")
  8. (test-equal (peano `(+ ,(number->peano 10)
  9. ,(number->peano 4)))
  10. (number->peano 14))
  11. (test-equal (peano `(* ,(number->peano 8)
  12. ,(number->peano 7)))
  13. (number->peano 56))
  14. (test-equal (peano `(* ,(number->peano 10)
  15. ,(number->peano 7)))
  16. (number->peano 70))
  17. (test-equal (peano `(* ,(number->peano 8)
  18. ,(number->peano 10)))
  19. (number->peano 80))
  20. (test-equal (peano `(* ,(number->peano 12)
  21. ,(number->peano 10)))
  22. (number->peano 120))
  23. (test-equal (peano `(* ,(number->peano 11)
  24. ,(number->peano 13)))
  25. (number->peano 143))
  26. (test-equal (peano `(* ,(number->peano 21)
  27. ,(number->peano 23)))
  28. (number->peano 483))
  29. (test-equal (peano `(* ,(number->peano 28)
  30. ,(number->peano 27)))
  31. (number->peano 756))
  32. (test-end "peano")