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

Re: [Xotcl] Mixins in XOTcl

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Tue, 18 May 2004 21:45:22 +0200

Hi there,

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

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:

================================================
  Object instproc interceptor {op kind name {pos 0}} {
    switch -exact $op {
        add {my $kind [linsert [my info $kind] $pos $name]}
        delete {
            set old [my info $kind]
            set p [lsearch -glob $old $name]
            if {$p>-1} {my $kind [lreplace $old $p $p]} else {
               error "$name not in $old"
            }
        }
    }
    puts "$kind list: [my info $kind]"
  }

  Class A
  Class B
  Class C

  Object o
  o interceptor add mixin A
  o interceptor add mixin B
  o interceptor add mixin C end
  o interceptor delete mixin *A
================================================
The output of this script is:

mixin list: ::A
mixin list: ::B ::A
mixin list: ::B ::A ::C
mixin list: ::B ::C

best regards
-gustaf neumann

-- 
Univ.Prof. Dr.Gustaf Neumann
Abteilung für Wirtschaftsinformatik
WU-Wien, Augasse 2-6, 1090 Wien