You're right, it's macro more than inlining. Tag metadata doesn't throw an
error, but it doesn't fix the reflection warning either (assuming I'm doing
it correctly):

(defmacro barr= [^{:tag bytes} x ^{:tag bytes} y]
  `(java.util.Arrays/equals ~x ~y))

(defmacro barr= [ x  y]
  `(java.util.Arrays/equals ^{:tag bytes} ~x
                            ^{:tag bytes} ~y))


As for the approach, I wanted to start out by mimicking the implementation
of clojure.core/=. I haven't written inlined functions before, and was
curious about the potential speedup. I do like the idea of a generic arr=.

On Mon, Jan 2, 2012 at 11:27 AM, David Nolen <dnolen.li...@gmail.com> wrote:

> I suspect this has more to do with type-hinting inside a macro. Did you
> try adding :tag metadata to those symbols?
>
> As a side note I do find this approach a bit strange. Why not just define
> a generic arr= that with multi-arity inlining?
>
> David
>
> On Mon, Jan 2, 2012 at 1:43 PM, Sam Ritchie <sritchi...@gmail.com> wrote:
>
>> Hey all,
>>
>> I'm writing a function called barr= that looks just like clojure.core/=,
>> but uses java.util.Arrays/equals instead of equiv. To speed up the function
>> I tried adding type hints to both the function definition and the
>> 2-argument inlined version. Type hinting the inline function threw an
>> exception that makes me think the compiler is interpreting Here's the gist:
>> https://gist.github.com/1551640
>>
>> Type hints on the function definition work great:
>>
>> (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)))
>>
>> But hinting the inline version causes an exception:
>>
>> (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)))
>>
>> ;; CompilerException java.lang.IllegalArgumentException: Unable to
>> resolve classname:
>> ;; clojure.core/bytes, compiling:(NO_SOURCE_PATH:54)
>>
>> The compiler seems to be interpreting this type hint as a var. Are type
>> hints not allowed inside of inline definitions for some reason?
>>
>> Cheers,
>> --
>> Sam Ritchie, Twitter Inc
>> 703.662.1337
>> @sritchie09
>>
>> (Too brief? Here's why! http://emailcharter.org)
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en




-- 
Sam Ritchie, Twitter Inc
703.662.1337
@sritchie09

(Too brief? Here's why! http://emailcharter.org)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to