Stuart Sierra <the.stuart.sie...@gmail.com> writes:
> On Jan 30, 1:09 pm, Jan Rychter <j...@rychter.com> wrote:
>> From what I read, the reasoning is that Clojure provides extremely
>> general multimethods where you have to define a dispatch function. On
>> the object side, there is metadata and you can do with it whatever you
>> want. But this seems to leave a gaping hole saying "fill me with an
>> object system". Is the goal for everyone to roll their own?
>
> I think the goal is to provide object-like capabilities without
> needing actual objects.  The emerging pattern is to use maps, with
> a :tag key identifying the type.  Types are usually namespace-
> qualified keywords.  You can create any kind of inheritance hierarchy
> with "derive".
>
> (defn make-window [id]
>   {:tag ::window, :id id})
>
> (defn make-color-window [id color]
>   (assoc (make-window id)
>     :tag ::color-window
>     :color color))
[...]

Let's focus on this part for now. As I mentioned, I do understand
multimethods and derive, and my post was not about them. In fact, I
noticed that multimethods and ad-hoc hierarchies are the only thing
people discuss, forgetting totally about attribute inheritance.

Phrased differently, I don't understand the utility of StructMaps. If
your example above is the preferred way to create objects that inherit
attributes from other objects, then this means inheritance is instance
(or prototype) based. I can extend the set of keys using assoc on a
particular instance.

But if that is so, what's the point of having StructMaps? You can use
defstruct to define your base object, but you can't use it to define
objects that extend the set of attributes (keys) -- you can only do that
to instances. So while I can use defstruct to define my base window
object and use struct-map afterwards, I can't define color-window this
way -- I always have to call make-color-window to create a color-window.

Let's follow the StructMap example from http://clojure.org/data_structures
  -- I guess what I'm looking for is a way to do this (whatever the
actual syntax ends up being):

(defstruct desilu () (:tag ::desilu) :fred :ricky)
(defstruct extended-desilu (::desilu) (:tag ::extended-desilu) :lucy :ethel)

... instead of extending the set of attributes of a particular instance.

I guess I would be fine with delegating all responsibility to
constructor functions, but then I don't understand the point of having
StructMaps.

I have a nagging feeling that this amount of liberty will result in many
mutually incompatible object systems being created.

Another thing which I found very useful in CLOS were method
combinations, in particular the standard method combination with
:before, :after and :around method types. I am not sure if that is
implementable using the current Clojure multimethod system.

Any pointers or hints are very welcome.

--J.

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