Hi again,
quick question:
Is it at all possible to extend a protocol to a particular primitive
array type but also handle nesting of arrays? A double[] is not the same
class as double[][] which in turn is not the same Class as double[][][]
etc etc and there is no interface tying them together.... So this means
I can't do the regular trick that I can do with any other Collection type.
example:
(defprotocol Normalisable
(normalise [this transformer]))
(extend-protocol Normalisable
Number
(normalise [this transform]
(transform this))
String
(normalise [this stem]
(stem this))
java.util.List ;;if this fires, we're dealing with a Java list-like
collection - return a vector
(normalise [this transform]
(if (instance? java.util.Collection (first this)) ;;handle nesting at
the top interface and pray that an extension-point for that type exists
(mapv #(normalise % transform) this)
(let [top (delay (apply max this))
bottom (delay (apply min this))]
(mapv (fn [x] (normalise x #(transform % [top bottom]))) this))) )
and so forth for Collections... for arrays it's the same story (but with
amap) but it will only work for 1d arrays. Extending to object-arrays,
thinking that the outer array is an Object[], fails miserably. How on
earth am I supposed to handle nesting in a general way?
thanks in advance...
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.