Ah, interesting. You'll notice that the gensym is created outside the defn and captured, so I'm not sure speed is important.
On Mar 21, 11:26 am, Mikhail Kryshen <mikh...@kryshen.net> wrote: > On Mon, 21 Mar 2011 07:52:45 -0700 (PDT) > > Jonathan Smith <jonathansmith...@gmail.com> wrote: > > Here is a way that should work. > > > (let [missing (gensym)] > > (defn get-with-exception [map key] > > (let [res (get map key missing)] > > (if (= res missing) > > (throw (new Exception "my-exception")) > > res)))) > > > Gensyms are unique so you also don't have the problem of 'what happens > > if I put an exception in the map' in this case. > > You don't want to be executing the gensym more than once, or the > > exception more than once. > > Symbol comparison should also be reasonably fast, which is good. > > The fastest way to create unique object is to call the constructor of > java.lang.Object: > > (let [missing (Object.)] > ...) > > -- > Mikhail -- 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