IllegalArguementException in clojure when trying to reduce and reduce

I get an 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))))) 

An error occurs on the concat line. It should be something that could be minimized, as well as persuaded.

+4
source share
2 answers

You are trying to execute #(reduce + b) and #(reduce + s) . This does not work, #(reduce + b) expands to (fn* [] (clojure.core/reduce clojure.core/+ your-namespace/b)) . You cannot perform functions. Maybe you meant (reduce + b) , but that doesn't make any sense, because the result is a number, and you can't specify numbers either. Perhaps you meant [(reduce + b) (reduce + s)] or (map + bs) or (+ (reduce + b) (reduce + s)) , but I cannot do more than blindly assume here without knowing what you are really trying to achieve.

These lines are:

  (cons (nth (nth (nth phr n) 1) 0) b) (cons (nth (nth (nth phr n) 1) 1) s) 

strange too. Is part of seqs seqs longs?

Is your collection of this form [[[0 0 ,,,] [0 1 ,,,] ,,,] ,,,] (would you be from 0 to b and from 1 to s)? If so, you should probably write functions to access these values, since it is not an easy task to find out what is going on.

+1
source

nth returns a value.

When you execute (cons (nth (nth (nth phr n) 1) 0) b) , after evaluating (nth phr n) you apply the following nth in value, not in Seq.

Testing your code with something like (phrase-length "123") will result in the error you are getting.

0
source

Source: https://habr.com/ru/post/1441928/


All Articles