Using maps as namespaces

2010-01-22 Thread Jacek Generowicz
I'm trying to create a utility which allows the use of maps as namespaces. For example (defmacro in-map [m & body] (let [bindings (apply concat (map (fn [k] [(symbol (name k)) (m k)]) (keys m)))] `(let [...@bindings] ~...@body))) would allow (in-map {:a 1 :b 2 :c 3} (+ a (* b c)))

Using docs effectively (Ratio)

2010-01-21 Thread Jacek Generowicz
Clojure has a Ratio type; presumably there should be an easy way to find the numerator and denominator of a Ratio object. I didn't have much luck on clojure.org or with find-doc, but (show 1/2) taught me that there are numerator and denominator methods on Ratio's underlying Java implementati

Re: Multimethod attribute maps

2010-01-21 Thread Jacek Generowicz
On Jan 20, 1:02 pm, Jacek Generowicz wrote: > clojure.core/defmulti > ([name docstring? attr-map? dispatch-fn & options]) > What is the purpose of the attribute map [...] ? Answering my own question: It's not specific to multimethods. It's the metadata, and most

Multimethod attribute maps

2010-01-20 Thread Jacek Generowicz
In Clojure 1.1.0, the documentation states: clojure.core/defmulti ([name docstring? attr-map? dispatch-fn & options]) Macro Creates a new multimethod with the associated dispatch function. The docstring and attribute-map are optional. Options are key-value pairs and may be one of: :defa

Inspecting multimethods

2010-01-19 Thread Jacek Generowicz
Is there a way to (programatically) discover the set of methods belonging to a multimethod? Thank you. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are

Some vars protected from binding?

2010-01-19 Thread Jacek Generowicz
(def ++ +) (defn foo-core [a b] (+ a b)) (defn foo-user [a b] (++ a b)) (binding [+ - ++ -] [(foo-core 1 1) (foo-user 1 1)]) Gives the result: [2 0] which suggests that some vars are immune to binding. Could someone please point me to the chapter and verse describing this? Th