Skip to content

Instantly share code, notes, and snippets.

@markomanninen
Last active August 28, 2017 09:16
Show Gist options
  • Save markomanninen/fe98d3d66a6f09c77bb83329911e3fc1 to your computer and use it in GitHub Desktop.
Save markomanninen/fe98d3d66a6f09c77bb83329911e3fc1 to your computer and use it in GitHub Desktop.
(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))))
@markomanninen
Copy link
Author

markomanninen commented Aug 28, 2017

To define L: (defmacro L [&rest expr] (lprint expr))
To define lprint: (defn lprint [expr] ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment