Skip to content

Instantly share code, notes, and snippets.

@World2LiveBy
Last active December 14, 2017 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save World2LiveBy/4c6b28b2701ad5e74ed90681b600a342 to your computer and use it in GitHub Desktop.
Save World2LiveBy/4c6b28b2701ad5e74ed90681b600a342 to your computer and use it in GitHub Desktop.
Basic implementation of Church Numerals and Compound date in Scheme utilizing lambda calculus
#lang scheme
;;---Lambda Calculus---
(define I
(λ (x) x))
(define K
(λ (x) (λ (y) x)))
(define KI
(λ (x) ((K I) x)))
(define V
(λ (x) (λ (y) (λ (f) ((f x) y)))))
;;---Constructor and Selector Functions---
(define cons
(λ (x y) ((V x) y)))
(define car
(λ (l) (l K)))
(define cdr
(λ (l) (l KI)))
;;---Church Numerals and Arithmetic---
(define zero
(λ (f) (λ (x) x)))
(define succ
(λ (n)
(λ (f) (λ (x)
(f ((n f) x))))))
(define add
(λ (m) (λ (n)
(λ (f) (λ (x)
((m f) ((n f) x)))))))
(define one (λ (f) (λ (x) (f x))))
(define two (λ (f) (λ (x) (f (f x)))))
(define three (λ (f) (λ (x) (f (f (f x))))))
;;---Printing and Output Functions---
(define printPair
(λ (p) (begin
newline
(display "(")
(display (car p))
(display ",")
(display (cdr p))
(display ")"))))
(define printNumeral
(λ (n) (display
((n (λ (x) (+ x 1))) 0))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment