i have 2 lists:
(def xxa ["olp" "xyz"]) (def xxb ["ulove" "alove" "holp" "sholp"])
and function trying elements of 1st list parts of elements of 2nd list:
(defn in-array [array1 array2] (for [s1 array1 :when (some #(.contains %1 s1) array2)] s1))
(in-array xxa xxb) should return ["olp"]
but get:
illegalargumentexception key must integer clojure.lang.apersistentvector.invoke
i don't understand means. can gives me light?
here's attempt make discussion above clear answer come along later. if i've missed please let me know or edit:
starting original example:
user> (def xxa ["olp" "xyz"]) #'user/xxa user> (def xxb ["ulove" "alove" "holp" "sholp"]) #'user/xxb user> (defn in-array [array1 array2] (for [s1 array1 :when (some #(.contains %1 s1) array2)] s1)) #'user/in-array
and peter points out, set of ()
cause error:
user> (in-array (xxa xxb)) illegalargumentexception key must integer clojure.lang.apersistentvector.invoke (apersistentvector.java:284)
which contains more code required show situation, can trim down to:
user> (xxa xxb) illegalargumentexception key must integer clojure.lang.apersistentvector.invoke (apersistentvector.java:284)
which minimal case show problem. if change example pass expected type can see vectors, when called function, take number , number in themselves.
user> (xxa 1) "xyz"
so can correct call , expected output, exactly:
user> (in-array xxa xxb) ("olp")
the result (lazy) sequence for
expression , user3166747 had asked vector (non lazy, , random access) can adding call vec
:
user> (defn in-array [array1 array2] (vec (for [s1 array1 :when (some #(.contains %1 s1) array2)] s1))) #'user/in-array user> (in-array xxa xxb) ["olp"]
and matches exactly.