Skip to content

Instantly share code, notes, and snippets.

View astrangeguy's full-sized avatar

astrangeguy

  • base engineering GmbH
  • Hamburg, Germany
View GitHub Profile
(ns strangeness.fn-arity
(:import java.lang.reflect.Method))
(defn declared-methods [^Class class]
(filter #(= class (.getDeclaringClass ^Method %))
(.getMethods class)))
(defn has-arity? [fun arity]
(let [cls (class fun)
methods (declared-methods cls)]
(def foo (fn foo [x]
(if (zero? x)
x
(foo (dec x)))))
(dotimes [i 3]
(println "lexical binding run" i)
(time
(dotimes [i 1000]
(foo i))))
(def fib-var-obj
(fn [x]
(if (< x 2)
1
(+ (fib-var-obj (- x 1))
(fib-var-obj (- x 2))))))
(defn fib-lex-obj [x]
(if (< x 2)
1