Last active
August 28, 2017 09:16
-
-
Save markomanninen/fe98d3d66a6f09c77bb83329911e3fc1 to your computer and use it in GitHub Desktop.
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
(eval-and-compile | |
; pretty print utility | |
(defn lprint [expr] | |
(if (coll? expr) | |
(+ "(" (.join " " (list-comp (lprint x) [x expr])) ")") | |
(str expr))) | |
; church number body generator: (N 3 m n) ; -> (m (m (m n))) | |
(defn N [n x y] | |
(if (zero? n) y | |
(+ (% "(%s " x) (N (dec n) x y) ")")))) | |
; lambda expression | |
(defmacro L [&rest expr] (lprint expr)) | |
; church number generator: (NUM 3) ; -> (L x y , (x (x (x y)))) | |
(defmacro NUM [n &optional [x "x"][y "y"]] | |
`(L ~x ~y , ~(read_str (N n x y)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To define L:
(defmacro L [&rest expr] (lprint expr))
To define lprint:
(defn lprint [expr] ...)