Reputation: 971
i'm getting the error IllegalArgumentException Don't know how to create ISeq from: java.lang.Long clojure.lang.RT.seqFrom (RT.java:487)
when executing the following code:
(defn phrase-length [phr]
(loop [n 0 b () s ()]
(if (= n (count phr))
(concat #(reduce + b) #(reduce + s))
(recur (inc n)
(cons (nth (nth (nth phr n) 1) 0) b)
(cons (nth (nth (nth phr n) 1) 1) s)))))
The error is occurring in the line of the concat
. It must be something with trying to reduce while also concatting.
Upvotes: 4
Views: 144
Reputation: 15673
You're trying to concat #(reduce + b)
and #(reduce + s)
. That doesn't work, #(reduce + b)
expands to (fn* [] (clojure.core/reduce clojure.core/+ your-namespace/b))
. You can't concat functions. Maybe you meant (reduce + b)
but that doesn't make any sense either because the result of that is a number, and you can't concat numbers either. Maybe you meant
[(reduce + b) (reduce + s)]
or (map + b s)
or (+ (reduce + b) (reduce + s))
but I can't do more than blindly guess here without knowing what you're actually trying to achieve.
These lines:
(cons (nth (nth (nth phr n) 1) 0) b)
(cons (nth (nth (nth phr n) 1) 1) s)
are weird too. Is phr a seq of seqs of seqs of longs?
Is your collection of this form [[[0 0 ,,,] [0 1 ,,,] ,,,] ,,,]
(you'd cons 0 to b and 1 to s here)? If so, you should probably write functions for accessing those values, as it is it's a chore to find out what's going on.
Upvotes: 1
Reputation: 672
nth returns a value.
When you do (cons (nth (nth (nth phr n) 1) 0) b)
, after the evaluation of the (nth phr n)
you will apply the next nth
in a value, not in a Seq.
Testing your code with something like (phrase-length "123")
will raise the error that you are getting.
Upvotes: 0