1

Am getting the subject error when trying to do a simple thread macro.

Keyword defines

(def entityType (keyword "name"))
(def entityURI (keyword "uri"))

I have the following 'lazy' sequence:

(def m1
    (({:uri "...#OWLClass_82601afd_b43d_43b4_94fe_2836f40009ca", :name "foo"} 
    {:uri "...#OWLClass_8c6759f0_a165_4a09_a9d8_2603bb106fc6", :name "bar"}))

Here is the REPL thread:

(->> (first m1)
     (map (fn [rec] (rec entityType))))

And the resulting error:

IllegalArgumentException Key must be integer  clojure.lang.APersistentVector.invoke (APersistentVector.java:265)

Anyone with any insight?

1
  • Actually you are supposed to get NullPointerException once you meet the definition of m1 Commented Jan 29, 2014 at 14:21

2 Answers 2

3

Based on your code I am guessing you want m1 to be declared like this:

(def m1
  (list (list {:uri "...#OWLClass_82601afd_b43d_43b4_94fe_2836f40009ca", :name "foo"} 
              {:uri "...#OWLClass_8c6759f0_a165_4a09_a9d8_2603bb106fc6", :name "bar"})))

Thus:

(->> (first m1)
     (map (fn [rec] (rec entityType))))
;=> ("foo" "bar")

Is this what you were after?

EDIT:

Based on your comment I've understood that the structure of m1 is flatter, like this:

(def m1
  (list {:uri "...#OWLClass_82601afd_b43d_43b4_94fe_2836f40009ca", :name "foo"} 
        {:uri "...#OWLClass_8c6759f0_a165_4a09_a9d8_2603bb106fc6", :name "bar"}))

Based on this you can just do (map (fn [rec] (rec entityType)) m1) and drop the ->>.

Sign up to request clarification or add additional context in comments.

4 Comments

m1 (which is actually generated from another call) is (type m1) clojure.lang.LazySeq and (type (first m1)) is clojure.lang.PersistentArrayMap. If I write (->> (first m1) (map (fn [rec] (type rec))))… Frank: there are other 'keys' that I didn't show in the question/post. I get: (clojure.lang.MapEntry clojure.lang.MapEntry clojure.lang.MapEntry clojure.lang.MapEntry clojure.lang.MapEntry clojure.lang.MapEntry clojure.lang.MapEntry)
In that case instead of a ->> you can just use (map (fn [rec] (rec entityType)) m1).
but I'm building up the thread to process the entire list (m1) so I need the macro.
Then just do (->> m1 (map (fn [rec] (rec entityType)))).
0

For those who wind up on this post after searching this error string, be careful you are not accidentlly trying to assoc a (keyword ...) to a vector:'

(def foo [])

(assoc-in foo [:aaa (keyword "b-bb")] ["obj"] )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.