'amap' issue after extending a protocol to a primitive array type

2013-06-13 Thread Jim - FooBar();

more weirdness!


try this at your REPL:

-extend any protocol to some primitive array type - let's say 'doubles'
-while in the same namespace, try to use amap passing it an array of 
floats and also type-hint it with ^floats

*
**IllegalArgumentException No matching method found: aset 
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)*


the same would have happened if the protocol had been extended to floats 
and tried to use amap with doubles. In fact any combination of primitive 
types will fail. Only the type that has been extended will work. In the 
above case that would be doubles. If we extended the protocol to longs 
then only longs would work and so forth...


I'm almost certain that this is not intentional...any opinions?

Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'amap' issue after extending a protocol to a primitive array type

2013-06-13 Thread Aaron Cohen
Are you sure?

user= (defprotocol A (foo [a b]))
A
user= (extend-protocol A (Class/forName [D) (foo [a b] [a b]))
nil
user= (pprint (foo (double-array [1 2 3]) 1))
[[1.0, 2.0, 3.0] 1]
user= (pprint (amap (float-array [1 2 3]) i ret (float (* 2 (aget ret
i)
[2.0, 4.0, 6.0]

My guess is you're not remembering to cast to the appropriate type in your
loop expression in amap.

For instance:
user= (amap (float-array [1 2 3]) i ret i)
IllegalArgumentException No matching method found: aset
 clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)

Whereas you need:
user= (amap (float-array [1 2 3]) i ret (float i))
#float[] [F@6a636064

--Aaron

On Thu, Jun 13, 2013 at 12:57 PM, Jim - FooBar(); jimpil1...@gmail.comwrote:

  more weirdness!


 try this at your REPL:

 -extend any protocol to some primitive array type - let's say 'doubles'
 -while in the same namespace, try to use amap passing it an array of
 floats and also type-hint it with ^floats
 *
 **IllegalArgumentException No matching method found: aset
 clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)*

 the same would have happened if the protocol had been extended to floats
 and tried to use amap with doubles. In fact any combination of primitive
 types will fail. Only the type that has been extended will work. In the
 above case that would be doubles. If we extended the protocol to longs then
 only longs would work and so forth...

 I'm almost certain that this is not intentional...any opinions?

 Jim

 --
 --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.