Hi Konrad, On 22 Okt., 12:49, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > However, there is one point that is not clear to me: how does Clojure > deal with data types in general, and abstract data types in > particular? How would one implement a library for tree operations, a > graph library, or a numerical library for operations on complex > numbers? > > In OO languages, one would uses classes and interfaces for that. In > functional languages of the ML family, one would use algebraic data > types and modules/packages to hide a particular implementation. In > standard Lisps, everything would be represented by cons nodes, with > little to no abstraction. > > Clojure knows about abstractions and interfaces, but all I have seen > until now is the use of interfaces on the client side, with data types > already implemented. I can also see how one would implement classes > and interfaces in Java and use them from Clojure. But who would one > define interfaces and concrete implementations in Clojure itself?
Well on the one hand you can define interfaces "by documentation". Define the interface in the documentation and export the functions which do things as advertised from your namespace. Private helper functions can be declared and are not exported (defn vs. defn-). Whatever the functions return should be treated opaque. As long as the opaqueness is respected you can change the underlying implementation without customer impact. An example is the interface of clojure.zip. It returns a "location" in the tree, which is sufficiently vague to tell you "Leave your hands off!". Of course you may inspect a location and change it as you like (it's a normal vector). But well, don't complain afterwards. If you are more the "Give a programmer a tree and rope and he will use them!" type, you can use gen-class from clojure itself and gen-interface from clojure.contrib to define an opaque interface and a class implementing the interface. I think the later is good idea when you expect different implementations to be plugged in at run-time, which may also come from the user of your library. If it's just the implementation of the library's functionality I would go with the first way. Just my 0.02$ Sincerely Meikel --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---