Hello everyone,
I am having problems with destructuring in doseq.
The function below basically takes an array of arrays as its argument
and returns a mapping of the elements to the index in the outer array.
(use 'clojure.contrib.seq-utils)
(defn foobar [arr--of-arr]
(let [ acc (transient {}) ]
(doseq [ [i e] (indexed arr-of-arr) word e ]
(assoc! acc word (if-let [v (acc word)] (conj v i) [i])))
(persistent! acc)))
The above programs works fine for the following input
input => (foobar [[:a :b] [:c :d] [:a :x]])
output => {:a [0 2], :b [0], :c [1], :d [1], :x [2]}
But, for the following inputs it behaves weirdly.
input (foobar [[:a :b] [:c :d] [:e :f] [:g :h] [:i :j]]
=> {:a [0], :b [0], :c [1], :d [1], :e [2], :f [2], :g [3], :h [3]}
Note, the output does not include i and j as keys.
It has the same effect of the following inputs.
(foobar [ [:a :b :c :d :e :f :g :h :i :j] ])
=> {:a [0], :b [0], :c [0], :d [0], :e [0], :f [0], :g [0], :h [0]}
(foobar [ [:a :b :c :d] [:e :f :g :h :i :j] ])
=> {:a [0], :b [0], :c [0], :d [0], :e [1], :f [1], :g [1], :h [1]}
(Note that in cases where i and j have been skipped, the total number
of elements (symbols) are more than 8)
After trying with some more datasets, I found that if the cumulative
size of the elements exceeds 8 the destructuring seems to ignore
elements after the 9 element ( something to do with ArrayMap?).
It seems like there is a lack of consistency in the way destructuring
works. Either that, or doseq is not meant to be used in the above
fashion. Either ways, I would appreciate it if someone could clarify
things.
--
Thanks
Abhijith
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---