Dear XOTcl community,
since someone asked for it, here comes a simple implementation of delegation similar as done in snit (unknown calls are delegated). Maybe, someone can use it.
best regards -gustaf neumann
############################################################## # define a deletate method and a default behavior for unknown ############################################################## Object instproc delegate {method obj} { my set delegate($method) $obj } Object instproc unknown {m args} { if {[my exists delegate($m)]} { eval [my set delegate($m)] $m $args } elseif {[my exists delegate(*)]} { eval [my set delegate(*)] $m $args } }
############################################################## # some syntactic sugar for defining methods ############################################################## Class instproc methods list { foreach {name arguments body} $list { my instproc $name $arguments $body } }
############################################################## # example from the snit homepage: A dog with a tail.... ############################################################## Class Tail -parameter {{length 5}} -methods { wag {} { puts "[my info parent] Wag, wag, wag." } }
Class Dog -methods { init {} { set tail [Tail new -childof [self]] my delegate * $tail } bark {} { puts "[self] Bark, bark, bark." } }
Dog fido fido wag fido bark
==========================================================