Hi, On Aug 31, 11:27 am, Timo Mihaljov <noid....@gmail.com> wrote: > When defining a map literal, is it possible to reference the map that is > being defined?
I don't think this is possible. > I have some code that looks like this: > > (let [radius 20 > diameter (* 2 radius) > circumference (* pi diameter)] > {:radius radius > :diameter diameter > :circumference circumference}) > > I would like to simplify it to something like: > > {:radius 20 > :diameter (* 2 (% :radius)) > :circumference (* pi (% :diameter))} > > where % is the map itself. > > Is this possible with the {}-syntax, or is there a macro to do this in > the standard library or contrib? Simply define a helper: (defn make-circle [radius] {:radius radius :diameter (* 2 radius) :circumference (* 2 pi radius)}) If you are concerned about the double calculation of the diameter you can use a let as you did. Or can have a look here: http://github.com/francoisdevlin/devlinsf-clojure-utils/ and here the discussion: http://groups.google.com/group/clojure-dev/browse_thread/thread/4b20e40d83095c67. Look for a function named trans*. Hope this helps. Sincerely Meikel --~--~---------~--~----~------------~-------~--~----~ 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 moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---