Created
January 16, 2025 00:27
-
-
Save michelesr/3fd03d9a605662dee2aa6c2f6e47eb7e to your computer and use it in GitHub Desktop.
Boolean logic and Church numerals in Scheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (true a b) a) | |
| (define (false a b) b) | |
| (define (not b) (b false true)) | |
| (define (and a b) (a b false)) | |
| (define (or a b) (a true b)) | |
| (define zero (lambda (f) (lambda (x) x))) | |
| (define one (lambda (f) (lambda (x) (f x)))) | |
| (define two (lambda (f) (lambda (x) (f (f x))))) | |
| (define three (lambda (f) (lambda (x) (f (f (f x)))))) | |
| (define (add-1 n) | |
| (lambda (f) (lambda (x) (f ((n f) x))))) | |
| (define (add m n) | |
| (lambda (f) (lambda (x) ((m f) ((n f) x))))) | |
| (define (mul m n) | |
| (lambda (f) (lambda (x) ((m (n f)) x)))) | |
| (define (church-to-number cn) | |
| ((cn (lambda (x) (+ x 1))) 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment