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)))
to evaluate to 7 because the names a, b and c are bound to the the
values associated with the keys :a, :b and :c in the given map.
But in-map, as it stands, only works on literal maps,
because it relies on the availability of the keys at macroexpansion
time.
This shortcoming is trivially demonstrated by
(in-map (hash-map :a 1 :b 2 :c 3)
(+ a (* b c)))
which, in theory, is identical to the previous example, but, in
practice, crashes.
Am I reinventing some wheel?
If not, does Clojure provide any run-time binding mechanisms which
would allow this concept be made to work with maps which do not become
available until run-time?
Thank you for you for all the fine responses I have been getting to my
questions.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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