You're missing the clever hack ;) I'm hashing the private data structure and associating it to the map. This is what is used in the equality test. You can verify yourself that it works. my-object ;; -> {:private -1261861093} my-other-object ;; -> {:private -1261861093}
Make sense? A few quick tests show that the hash of a data structure will match on any VM. On Wed, Apr 22, 2009 at 1:01 PM, Victor Rodriguez <vict...@gmail.com> wrote: > > On Tue, Apr 21, 2009 at 12:01 PM, David Nolen <dnolen.li...@gmail.com> > wrote: > > Nice post thanks for putting it together. My gut feeling is that the > need > > for information hiding is still overinflated, but... until someone builds > a > > 200k LOC Clojure program who will know for sure? > > Here's my shot at a solution for private data: > > (defn set-private [m k x] > > (let [the-meta (meta m) > > new-private (assoc (:private the-meta) k x)] > > (with-meta > > (assoc m :private (hash new-private)) > > (assoc the-meta :private new-private)))) > > (defn get-private [m k] > > (get (:private (meta m)) k)) > > (def my-object (set-private {} :first "Bob")) > > (def my-other-object (set-private {} :first "Bob")) > > (get-private my-object :first) ; -> "Bob" > > (= my-object my-other-object) ; -> true > > No secret keys, no other libraries, and I believe this supports equality > > just fine. Since we're using metadata the data travels around easily > > This won't work, since metadata is not used for equality tests, isn't > that right? > > Regards, > > Victor Rodriguez. > > > between operations. > > ---------- Forwarded message ---------- > > From: Mark Engelberg <mark.engelb...@gmail.com> > > Date: Tue, Apr 21, 2009 at 6:41 AM > > Subject: Re: Abstract data types in functional languages > > To: clojure@googlegroups.com > > > > > > > > On Mon, Apr 20, 2009 at 11:00 AM, Timo Mihaljov <noid....@gmail.com> > wrote: > >> Is the concept of Abstract Data Types [1] useful in Clojure? > >> > >> If yes, how would you implement one? > > > > I have composed a lengthy response to this question, and added it to my > > blog: > > http://programming-puzzler.blogspot.com/2009/04/adts-in-clojure.html > > > > I look forward to everyone's comments, > > > > Mark > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---