Well,

Once the API has defined correctly documented accessor functions, I
think that trying to protect the user from himself at any cost may
well be counter productive (in general, of course).

Indeed, by not just using regular datastructures anymore for
"essential state", you'll loose somehow the benefits of leveraging
cross-concern "technical" APIs that could do services in a very
generic manner (e.g. a generic datastore, a generic rules system,
etc.).



2009/4/21 David Nolen <[email protected]>:
> 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 <[email protected]>
> Date: Tue, Apr 21, 2009 at 6:41 AM
> Subject: Re: Abstract data types in functional languages
> To: [email protected]
>
>
>
> On Mon, Apr 20, 2009 at 11:00 AM, Timo Mihaljov <[email protected]> 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to