Last active
July 26, 2016 19:00
-
-
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.
This file contains 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
(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