[Xotcl] Mixins in XOTcl

Gustaf Neumann neumann at wu-wien.ac.at
Tue May 18 21:45:22 CEST 2004


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



More information about the Xotcl mailing list