Reputation: 3519
This seems paradoxical:
(def foo ["some" "list" "of" "strings"])
`[ ~@(apply concat (map (fn [a] [a (symbol a)]) foo)) ]
; ["some" some "list" list "of" of "strings" strings]
; Changing only the outer [] into {}
`{ ~@(apply concat (map (fn [a] [a (symbol a)]) foo)) }
; RuntimeException Map literal must contain an even number of forms
; However, this works:
`{"some" some "list" list "of" of "strings" strings}
; {"list" clojure.core/list, "of" user/of, "strings" user/strings, "some" clojure.core/some}
Whats going on?
Upvotes: 2
Views: 269
Reputation: 29958
Unless you are writing a macro, it may be easiest to say:
(into {} (map (fn [a] [a (symbol a)]) foo))
;=> {"some" some, "list" list, "of" of, "strings" strings}
Upvotes: 0
Reputation: 9266
The exception is triggered by the reader because it can't read a literal map with one element which is your unsplice form before evaluation.
Workaround:
`{~@(apply concat (map (fn [a] [a (symbol a)]) foo)) ~@[]}
Upvotes: 2