Skip to content

Instantly share code, notes, and snippets.

@timmc
Forked from sritchie/inline.clj
Created January 2, 2012 18:41
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 timmc/1551676 to your computer and use it in GitHub Desktop.
Save timmc/1551676 to your computer and use it in GitHub Desktop.
;; This evaluates properly...
(defn barr=
([x] true)
([^bytes x ^bytes y]
(java.util.Arrays/equals x y))
([x y & more]
(if (barr= x y)
(if (next more)
(recur y (first more) (next more))
(barr= y (first more)))
false)))
;; This evaluates properly the first time, but throws an exception the
;; second time:
;;
;; CompilerException java.lang.IllegalArgumentException: Unable to resolve classname:
;; clojure.core/bytes, compiling:(NO_SOURCE_PATH:54)
(defn barr=
{:inline-arities #{2}
:inline (fn [x y] `(let [^bytes x# ~x
^bytes y# ~y]
(java.util.Arrays/equals x# y#)))}
([x] true)
([^bytes x ^bytes y]
(java.util.Arrays/equals x y))
([x y & more]
(if (barr= x y)
(if (next more)
(recur y (first more) (next more))
(barr= y (first more)))
false)))
;; Are type hints allowed inline? Why does this work the first time but not the second?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment