On Apr 21, 11:41 am, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> 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,

I'm not sure I quite see the reason for putting that level of effort
into securing your data structures. If you wrapped the stack in a map,
that would stop people from accidentally accessing the list directly,
but still allow people access to the underlying data structure if they
really wanted to.

  (defmulti stack-push type)
  (defmethod stack-push ::list-stack [s e] (cons e (:list s)))
  (defmethod stack-push ::vec-stack [s e] (conj (:vec s) e))

Perhaps would be nice if there was a convention for multi-methods so
they don't clash with genericly named functions, as there's a lot of
those in clojure.core. For instance, ending multi-method names with a
colon (which I'm pretty sure is legal syntax):

  (defmulti name: type)
  (defmethod name: ::person [p]
    (str (:first-name p) " " (:last-name p)))

  (name: user)

Or maybe a dash or some other currently unused set of characters:

  (name- user)
  (name-> user)

Though I wonder if whether that would make it harder to tell what
functions did. The function stack-push, whilst verbose, at least
describes its use very accurately. Calling it push: or push-> might
make things harder to understand, though maybe I'm being too cautious.

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