Skip to content

Instantly share code, notes, and snippets.

@Bronsa
Created August 4, 2012 21:22
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 Bronsa/3260037 to your computer and use it in GitHub Desktop.
Save Bronsa/3260037 to your computer and use it in GitHub Desktop.
(defn throw-arity [this n]
(let [name (-> this .getClass .getSmpleName)
suffix (.lastIndexOf name "__")
elided-name (if (= suffix -1) name (.substring name 0 suffix))]
(throw (clojure.lang.ArityException. n (.replace elided-name \_ \-)))))
(def AFn
(list
'java.lang.Callable
'(call [this]
(try (-invoke this)
(catch Exception e
(throw e))))
'java.lang.Runnable
'(run [this] (-invoke this))
'IFn
(map (fn [args] (list '-invoke (vec (cons 'this args))
(list 'throw-arity 'this (count args))))
(cons [] (take-while seq (iterate rest (repeat 18 '_)))))
'(-apply [this arglist]
(let [arglist-len (count arglist)]
(if (< arglist-len 19)
(eval `(-invoke ~this ~@arglist))
(eval `(-invoke ~this ~@(take 19 arglist) '~(drop 19 arglist))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment