Is this comparator called when get is called? How does this allow calling get on the reverse of a valid key?
Geoff On Friday, July 25, 2014 7:58:47 PM UTC-4, Ambrose Bonnaire-Sergeant wrote: > > The function basically returns 0 if the keys are equivalent, or -1 > otherwise. > > It satisfies a comparator, see > http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html#compare(T,%20T) > > Thanks, > Ambrose > > > On Sat, Jul 26, 2014 at 7:52 AM, Geoff Little <fifo...@gmail.com > <javascript:>> wrote: > >> Thanks so much Ambrose! I know that function is simple, but I don't >> understand how it provides the functionality I'm after. Do you mind >> explaining what's going on? I'm playing with it now in my repl. >> >> Thanks!! >> >> >> On Friday, July 25, 2014 6:48:06 PM UTC-4, Ambrose Bonnaire-Sergeant >> wrote: >> >>> Hi Geoff, >>> >>> You probably want a sorted-map-by: >>> >>> user=> (sorted-map-by (fn [a b] (or (when (every? coll? [a b]) (when (= >>> a (reverse b)) 0)) -1)) [1 2] 42 [2 1] 42) >>> {[1 2] 42} >>> >>> Thanks, >>> Ambrose >>> >>> >>> On Fri, Jul 25, 2014 at 9:52 AM, Geoff Little <fifo...@gmail.com> wrote: >>> >>>> I'm attempting to proxy PersistentHashmap so that "get"ting an existing >>>> key or its reverse returns the same value. >>>> >>>> Here's the code that I have >>>> >>>> (defn sym-key-hash-map [] >>>> (proxy [clojure.lang.PersistentHashMap] [nil 0 nil false nil] >>>> (valAt [key] >>>> (or (proxy-super valAt key) >>>> (proxy-super valAt (reverse key)))))) >>>> >>>> (let [key (list 1 2)] >>>> (get (assoc (sym-key-hash-map) key "sweet") >>>> (reverse key))) >>>> >>>> But unfortunately, the test code returns nil instead of "sweet". >>>> >>>> Does anyone with knowledge of proxy and PersistentHashmap know how to >>>> solve this? >>>> >>>> Thanks. >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Clojure" group. >>>> To post to this group, send email to clo...@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+u...@googlegroups.com >>>> >>>> For more options, visit this group at >>>> http://groups.google.com/group/clojure?hl=en >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "Clojure" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to clojure+u...@googlegroups.com. >>>> >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> <javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.