Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created January 2, 2012 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sritchie/1551640 to your computer and use it in GitHub Desktop.
Save sritchie/1551640 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)))
;; Type hinting the inline args throws an exception:
;;
;; 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