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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to