View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] Mixins in XOTcl

From: Adam Turoff <aturoff_at_bna.com>
Date: Wed, 19 May 2004 11:03:30 -0400

You wrote:
> > Object instproc insert_mixin {mixin_list} {
> > my mixin [append mixin_list " " [my info
mixin]]
> > }
>
> with names like mixinappend, mixinprepend for mixins,
filters,
> instmixins, instfilters we would introduce a large number
of
> methods, which do more or less the same.

Yes. That is certainly a problem.

> what do you people think about the following "interceptor"
> method: it is more verbous, but much more powerful as
well; it
> allows appending/prepending/inserting at a certain
position and
> deletion of all kinds of interceptors:

Hm...

One minor niggle is the use of the term 'interceptor'. The
term is quite
overloaded. First, this instproc manages two kinds of
'interceptor'
interfaces for an object: mixins and filters. Second, the
proc itself
is an interceptor -- it traps calls to manage the mixin and
filter
lists. Third, as you have written this proc, it manages
both mixins and
filters, which makes them appear more similar than they
really are.


That said, I do think you are on to something. The core
problem is that
both filters and mixins are a list of classes, and there are
no good
primitives to manage that list in a natural manner. It
would be nice if
[my info mixin] and [my info filter] were mutable with list
commands, but...

So, for the sake of argument, let us assume that there are
two new
instprocs - one to manage the list of filters, and one to
manage the list
of mixins (again, better naming ideas greatly appreciated):

    Object instproc mixin_list args {
        set op [lindex $args 0]
        set classes [lrange $args 1 [llength $args]]

        switch -exact $op {
            append { my mixin [concat [my info mixin]
$classes] }
            prepend { my mixin [concat $classes [my info
mixin]] }
            set { my mixin $classes }
            get { my info mixin }
            delete { ... }
        }
    }

    Class A
    Class B
    Class C

    A a
    a mixin_list append B
    a mixin_list prepend C
    a mixin_list get
    ================
    ::C ::B

Adding new primitive operations (like a mixin_list length; a
mixin_list sort;
a mixin_list contains classname; etc.) is simple and
obvious. I haven't played
with filters yet, but this idiom should work well there,
too.

I'll leave it to you to determine whether this method should
work use
instmixin for Classes, and mixin for Objects.

-- Adam