Skip to content

Instantly share code, notes, and snippets.

@sasaki-shigeo
Created September 6, 2020 15:43
Show Gist options
  • Save sasaki-shigeo/727b8a2a97ed7644c3798d1f3b809d31 to your computer and use it in GitHub Desktop.
Save sasaki-shigeo/727b8a2a97ed7644c3798d1f3b809d31 to your computer and use it in GitHub Desktop.
Natural Number Encoding (Zermelo Style)
;;;;
;;;; 自然数の符号化
;;;; ツェルメロ (Zermelo) による方法
;;;;
;;;; ノイマンの方式と比べると,順序の判定をするのに減算が必要なところが不便である。
;;;;
(define (succ x)
(list x))
(define zero '())
(define one (succ zero)) ; => (list zero) => (())
(define two (succ one)) ; => (list one) => ((()))
(define three (succ two)) ; => (list two) => (((())))
(define four (succ three)) ; => (list three) => ((((()))))
(define five (succ four))
(define six (succ five))
(define seven (succ six))
(define eight (succ seven))
(define nine (succ eight))
(define ten (succ nine))
(define (pred x)
(car x))
(define (number->code n)
(if (zero? n)
zero
(succ (number->code (- n 1)))))
;;;
;;; Question: define code->number that is the inverse of number->code.
;;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment