Peano Revisited

We could represent Peano numbers by lists.


; Represent Peano number by a list of n pairs
(define (number->peano n)
  (if (zero? n)
      '()
      (cons '() (number->peano (1- n))) ) )

; Change a Peano list to a number (define (peano->number lst) (length lst))

; append adds Peano lists (define (peano+ x y) (append x y))

; Add integers using Peano arithmetic (define (p+ x y) (peano->number (peano+ (number->peano x) (number->peano y)) ) )


> (number->peano 4)
(() () () ())

> (p+ 3 4) 7

Contents    Page-10    Prev    Next    Page+10    Index