On Nov 30, 2008, at 12:59 PM, Chouser wrote:
>
> ns-publics already calls 'the-ns' on its arg,
Right.
> and 'for' is handy for
> destructuring.
>
> (defn ns-var-metas [ns-name]
> (into {} (for [[n v] (ns-publics ns-name)] [n ^v])))
>
> Both 'into' and 'apply conj' allow you to specify nil instead of a
> pair if you wanted conditionally exclude a key.
>
Including nils is a bit subtle. If you are using 'for' you can put the
conditional in a :when clause.
Hmm... I can write mine on one line too :)
(defn ns-var-metas [ns]
(reduce (fn [m [n v]] (assoc m n ^v)) {} (ns-publics ns-name)))
More to the original question, this won't create additional
intermediate vectors.
Either is fine, whatever makes more sense in the situation, or
personal preference.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---