On Fri, May 28, 2010 at 3:09 PM, CuppoJava <[email protected]>wrote:
> d,w are arrays that are passed to me by a machine learning algorithm
> so it's not something that I have control over. There are roughly 100
> words per doc.
>
ok
> Thanks for everyone's help. I wonder if directly mutable primitives is
> something that is hard to put into Clojure? Or something that's
> explicitly avoided because it distracts from the FP paradigm. The lack
> of them is making this code somewhat awkward to write.
>
In this case there is no need for mutable primitives.
You can try a direct translation of your java code:
(let [n (alength w)]
(loop [doc (int -1) i (int 0)]
(when (< i n)
(let [new-doc (aget d i)
(when-not (= doc new-doc)
(load doc))
(when-not (malformed doc)
(process new-doc (aget w i))
(recur new-doc (inc i)))))))
You can tweeak it here and there (== and unchecked-inc for example) and
don't forget to typehint d and w if Clojure doesn't infer their type.
Christophe
--
Brussels, 23-25/6 http://conj-labs.eu/
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)
--
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