The exception is because (into-array [0 1 -7 2 -1 -3 4 5 -10])
is not an array of longs, use long-array instead.
In the areduce, we also have to return ret after each computation, like so:
(defn aremove [pred ^longs ns]
(areduce ns i ret (long-array (alength ns))
(let [v (aget ns i)]
(when-not (pred v)
(aset ret i v))
ret)))
(seq (aremove pos? (long-array [0 1 -7 2 -1 -3 4 5 -10])))
;=> (0 0 -7 0 -1 -3 0 0 -10)
The next problem is all the zeroes. I don't know how to solve this problem
with arrays. :)
Jonathan
On Fri, Nov 23, 2012 at 9:43 PM, Jim - FooBar(); <[email protected]>wrote:
> (defn aremove [pred ^longs ns]
> (areduce ns i ret (long-array (alength ns))
> (when-not (pred (aget ns i))
> (aset ret i (aget ns i) ))))
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en