Skip to content

Instantly share code, notes, and snippets.

@odyssomay
Created May 5, 2011 21:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odyssomay/958001 to your computer and use it in GitHub Desktop.
Save odyssomay/958001 to your computer and use it in GitHub Desktop.
Comparable function type
(deftype CFn [f form]
clojure.lang.IFn
(invoke [this x1] ((.f this) x1))
(invoke [this x1 x2] ((.f this) x1 x2))
(invoke [this x1 x2 x3] ((.f this) x1 x2 x3))
(invoke [this x1 x2 x3 x4] ((.f this) x1 x2 x3 x4))
(invoke [this x1 x2 x3 x4 x5] ((.f this) x1 x2 x3 x4 x5))
(invoke [this x1 x2 x3 x4 x5 x6] ((.f this) x1 x2 x3 x4 x5 x6))
(invoke [this x1 x2 x3 x4 x5 x6 x7] ((.f this) x1 x2 x3 x4 x5 x6 x7))
; and so on....
(applyTo [this arglist]
(apply (.f this) arglist))
java.lang.Object
(equals [this other_fn]
(if (and (= (class other_fn) (class this))
(= (.form this) (.form other_fn)))
true false)))
(defmacro c-fn [& forms]
`(CFn. (fn ~@forms) '~forms))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment