Skip to content

Instantly share code, notes, and snippets.

@viebel
Last active July 26, 2016 19:00
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 viebel/8c1c3ff50b0b5de317ec2a5d33581062 to your computer and use it in GitHub Desktop.
Save viebel/8c1c3ff50b0b5de317ec2a5d33581062 to your computer and use it in GitHub Desktop.
Constructing the arithmetic only with functions. This gist is used by articles inside blog.klipse.tech. Be careful not to break the articles.
(defn visual [x]
(list 'f x))
(defn view [f]
((f visual) 'x))
(deftype Lambda [f]
Object
(toString [_] (str (view f)))
IPrintWithWriter
(-pr-writer [this writer _] (-write writer (str (view f))))
IEquiv
(-equiv [this other]
(= (view this) (view other)))
IFn
(-invoke [this g]
(f g)))
(defmacro lambda [name args & body]
`(defn ~name ~args (Lambda. ~@body)))
(lambda numeral [n]
(fn [f]
(fn [x]
((apply comp (repeat n f)) x))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment