tags:

views:

73

answers:

2
(defn get-doc-list [a-term]
     (map #(Integer/parseInt %)(take-nth 3 (take (* 3 3)(rest (rest a-term))))))

This function works on small lists but returns and empty sequence on larger ones. What is the problem?

+1  A: 

This is certainly an input issue, as your function will parse at most 3 integers:

user=> (get-doc-list (repeat "1"))
(1 1 1)

And only return empty sequence if less than 3 strings are supplied:

user=> (get-doc-list ["1" "1"])
()

And throw an exception if a non string is given:

user=> (get-doc-list [1 1 1])
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

I suggest checking what the input it "fails" with really is... maybe you are passing in something like [["1" "1" "1" ...]]

user=> (get-doc-list [["1" "1" "1"]])
()

This is a vector of vectors, as you can see nothing is processed so there is no error or sequence to generate.

Timothy Pratley
A: 

The issue is your use of the take function, which returns only the first n items of the collection. Regardless of how big a collection you pass get-doc-list, only the first 9 get passed on to take-nth.

Tim Clemons
I think I've misread your question. On running your code I find that I get a list of 3 parsed integers regardless of how big a list I pass in. I wonder if the problem is your `df` method. Would you mind including that with your question?
Tim Clemons
On reading the previous version of your question, I think seeing the definition of `df` would shed some light on the situation as `a-term` is passed in as an argument to that function as well.
Tim Clemons