Thanks Alex. That was the problem. I have wrapped the results in anonymous function. I overuse anonymous functions due to my small experience with common lisp lambdas.
On Monday, 25 January 2016 15:59:57 UTC, Alex Miller wrote: > > I think your most immediate issue is the "#" after result - that makes > this into an anonymous function instance. Instead, you want to actually > evaluate that expression in the let: > > (let [result (.getStatements c nil nil nil (into-array Resource '[]))] > (log/debug (format "Result class: %s" (type result))) > (map #(log/debug "Element: " %1) result)) > > However, as far as I can tell, you will not be able to use the > CloseableIteration result as an input to map in the last line as > CloseableIteration is not something Clojure understands - that library > seems to have its own iterator hierarchy without any ties to the standard > Java iterators (seems like a questionable design choice to me). Due to this > you either need to create a wrapper to turn their iterator into a sequence, > something like this: > > (defn seq-iteration [^CloseableIteration iter] > (lazy-seq > (if (.hasNext iter) > (cons (.next iter) (seq-iteration iter)) > (do (.close iter) > nil)))) > > Here, I'm not handling iterator exceptions if they occur - they will just > bubble out during use. There's probably more that would need to be done to > ensure .close is called on the iter in the case of an exception during > .next. > > Or you need to traverse the iterator in a loop/recur: > > (let [result ^CloseableIteration (.getStatements c nil nil nil (into-array > Resource '[]))] > (try > (loop [] > (when (.hasNext result) > (log/debug "Element: " (.next result)) > (recur))) > (catch Exception e > (log/debug "Exception: " (.getMessage e))) > (finally > (.close result))) > > Because the CloseableIteration can throw exceptions, I wrapped the whole > thing in a try/catch and a finally to .close the result. If you want to > accumulate some state during this recursion, you can add a loop binding to > collect info and return it at the end instead. > > > > On Monday, January 25, 2016 at 9:38:28 AM UTC-6, Jacek Grzebyta wrote: >> >> Hi All, >> >> Sorry for trivial question but I am a newbe in Clojure. >> I need to manage some object which is created by calling java method: >> >> >> (let [result #(.getStatements c nil nil nil (into-array Resource '[]))] >>> (log/debug (format "Result class: %s" (type result))) >>> (map #(log/debug "Element: " %1) result) >>> ) >>> >> >> I know the result should be type of "CloseableIteration >> <http://www.google.com/url?q=http%3A%2F%2Frdf4j.org%2Fdoc%2F4%2Fapidocs%2Finfo%2Faduna%2Fiteration%2FCloseableIteration.html&sa=D&sntz=1&usg=AFQjCNEKEPHoxbdwlQIaFE_1zCUlJ1e1Fw><? >> >> extends Statement >> <http://rdf4j.org/doc/4/apidocs/org/openrdf/model/Statement.html>, >> SailException >> <http://rdf4j.org/doc/4/apidocs/org/openrdf/sail/SailException.html>>" >> but Clojure shows me the error that class >> "triple.loader_test$test_repository$result__849" cannot be processed. As >> a Java programmer I would say that clojure wraps/makes internal proxy from/ >> the origin object. >> I have added all required class names into file head by namespace >> declaration. >> >> How can I "unpack" the pack? Maybe my approach is totally wrong? I am >> even do not know what is the name of that issues so google is helpless in >> my case. >> Thanks a lot for help. >> >> Best regards, >> Jacek >> >> >> -- 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 --- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
