At this point you have to roll your own, I have an experimental thing I plan
on fleshing out temporarily called CLJOS. I've implemented field
inheritance, type inheritance, basic multiple inheritance, basic
introspection.  Search the mailing list for CLJOS and you'll see more
details.  It only took 200 lines of code
You mention in particular field inheritance.  In CLJOS, you can define
default initializers for fields.  When you inherit from a class(es), a look
up table of default initializers is consulted, the values are merged in the
direction of the inheritance chain.

Admittedly, it is a bit of a toy example at this point, but it shows that
without too much effort you could build a very powerful object system based
on structs, and I've already found CLJOS to useful in my own hacking.  In
fact I would be happy to collaborate on something more substantial.
http://github.com/swannodette/cljos/blob/8167d3b58f536f89011a811d270a3cc72a289b1a/cljos.clj

Examples here and here:
http://github.com/swannodette/cljos/blob/8167d3b58f536f89011a811d270a3cc72a289b1a/cljos_example.clj
http://github.com/swannodette/cljos/blob/8167d3b58f536f89011a811d270a3cc72a289b1a/cljos_example_two.clj

Not too many people are doing heavy or fancy GUI related stuff (as far as I
can tell) so I can understand why this hasn't come up often.  I note that
you work with weblocks so I can see where you're coming from and I'm glad
you're bringing it up.

That said, I imagine if a decent, useful, and complete lightweight object
system could be designed I'm sure it could get rolled into clojure-contrib
without too much brouhaha.

On Fri, Jan 30, 2009 at 1:09 PM, Jan Rychter <j...@rychter.com> wrote:

>
> There is something I don't understand about Clojure. There are
> multimethods (great), but I can't seem to find objects they can operate
> on. I come to Clojure from a Common Lisp background, having done a fair
> bit of CLOS programming. Mind you, I am not necessarily a fan of overly
> complex object hierarchies. But still -- I've been trying and I just
> can't seem to make objects in Clojure work.
>
> 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'm against overusing objects, but there are things which quite
> naturally map into the object-oriented paradigm. Let's take windowing
> systems for example -- let's assume you have various kinds of windows,
> each with its own unique attributes and attributes which are inherited
> (e.g. a window-id attribute is common to all windows). I can't see how
> you'd implement that in Clojure when you can't inherit structmap
> attributes. How do I build my-special-window which is a kind of window
> and also inherits window's window-id attribute? I know how to inherit
> behavior, but there is behavior that requires data, and I have no idea
> how to store and inherit that data. I looked at merge, but it seems you
> can't merge structure basis objects.
>
> Unfortunately, all discussion on Clojure polymorphism, multimethods and
> objects that I could find seems to use overly simplified examples (it
> really only shows that there are multimethods which can do multiple
> dispatch on anything), and doesn't really help. Even Stuart Halloway's
> beta "Programming Clojure" book has very simple examples that don't
> inherit attributes, just use different type tags for the same
> information.
>
> --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