Version 0 of Mixins and vars in TclOO

Updated 2013-01-08 12:31:20 by jima

jima (2013-01-08) notices a useful interaction between objects of a class and mixins in TclOO regarding how variables are accesed.

Example code:

 oo::class create Class {
  variable var
  constructor {} {
   set var wea
   oo::objdefine [self] mixin Mixin
  }
 }

 oo::class create Mixin {
  variable var
  method read {} {
   puts VAR($var)
  }
  method write {val} {
   set var $val
  }
 }

 Class create c
 c read
 c write foo
 c read
 c write bar
 c read

The interesting bit is that one can assign dynamically different mixins to a instance of a class and use in the code of the methods of the mixin variables that have been "declared" with variable both in the class and in the mixin.

To me it wasn't trivial that both var references in the example code would resolve to the same underlying variable.