It doesn't make sense to mix map and println. If you want side
effects, use doseq instead of map:
(doseq [{a :a} [ {:a 1 :b 11} {:a 2 :b 22} {:a 3 :b 33}]] (println a))
{:a 1, :b 11}
{:a 2, :b 22}
{:a 3, :b 33}
If you don't want side effects, use str instead of println (you could
also use identity):
(map #(str (:a %1)) [ {:a 1 :b 11} {:a 2 :b 22} {:a 3 :b 33}])
-> ("1" "2" "3")
If you want to destructure, use the longer anonymous fn form instead
of the % bindings:
(map (fn [{a :a}] a) [ {:a 1 :b 11} {:a 2 :b 22} {:a 3 :b 33}])
-> (1 2 3)
Cheers,
Stu
>
>
> (map #(println %) [1 2 3 4]) prints 1 2 3 and 4
>
> But what if the vector element is a hash with
> [ {:a 1 :b 11} {:a 2 :b 22} {:a 3 :b 33}]?
> can we dereference :a using %1, like (:a %1)?
> If not, any alternative? maybe destructuring or something?
>
> thanks
> -sun
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---