[FM] Using TclOO to create "typed lists" ====== oo::class create typedlist { constructor {args} { my variable Liste my variable Type my variable counter -1 if {[lindex $args 1] eq "-namespace"} { set namespace [lindex $args 2] namespace eval ::$namespace {} set List [lindex $args 0] } else { set namespace [] set Liste $args } set i [string last : [namespace tail [self]]] set Type [string range [namespace tail [self]] 0 $i-1] oo::objdefine [self] [subst { method unknown {args} { my variable counter typedlist create [self]:\[incr counter\] {*}\$args } }] } method get {} { my variable Liste return $Liste } method type {} { my variable Type return $Type } method lappend {args} { my variable Liste lappend Liste {*}$args } method append {args} { my variable Liste set e [lindex $Liste end] lset Liste end [append e {*}$args] } method transmute {type} { my variable Type if {[set n [llength [info command ${type}*]]]} { if {[info object class $type] eq "::typedlist"} { set Type $type after idle [list rename [self] ${type}:[incr n]] return ${type}:$n } } else { puts "le type $type n'existe pas" } } method -- {args} { my variable counter typedlist create [self]:[incr counter] {*}$args } export -- } ====== What does it ? An object containing a type and a list. Quick démo : ====== typedlist create rectangle set A [rectangle -- 100 100 200 200] $A get; # 100 100 200 200 $A type; # rectangle $A lappend 300 100; # 100 100 200 200 300 100 typedlist create triangle $A transmute ::triangle $A type; # triangle $A get; # 100 100 200 200 300 100 ====== Applications : * [megawidget framework with tclOO (1)] * [parsing with coroutine] ---- !!!!!! %|[Category Object Orientation]|[Category Package]|% !!!!!!