Version 0 of Itcl in XOTcl

Updated 2004-02-22 18:54:18

GN This is an example how to implement a ITcl like language in XOTcl. Note that this is not a full implementation of itcl, but it is sufficient to run the tests from Tcl OO Bench. The only change necessary in the tests was to replace #auto by a counter based version.

 ###########################################################
 ## Small example to emulate a itcl-like language in XOTcl
 ##  -gustaf neumann            Jan. 2004
 ###########################################################
 namespace eval itcl {
   Class create class -superclass Class
   class instproc instvars {} {
     set vars [list]; set c [self]
     for {} {[string compare ::xotcl::Object $c]} {set c [$c info superclass]} {
       eval lappend vars [$c set __autovars]
     }
     return "\n\tmy instvar [lsort -unique $vars]"
   }
   class proc constructor {args} {
     if {[llength $args]==2} {
       foreach {arglist body} $args break
     } else { 
       foreach {arglist construct body} $args break
       set body $construct\n$body
     }
     my parameter [list {this [self]}]
     my proc constructor args {uplevel next $args}
     my instproc init $arglist [my instvars]\n$body
   }
   class proc method {name arglist body} {
     my proc $name args {uplevel next $args}
     my instproc $name $arglist [my instvars]\n$body
   }
   class proc inherit {class} {
     my superclass $class
   }
   class proc variable {arglist} {
     foreach v $arglist {my lappend __autovars $v}
   }
   class instproc init {classdef} {
     my set __autovars this
     namespace eval [self class] $classdef
     my class Class
   }
   proc delete {what name} {$name destroy}
 }