
proc ?set {v_name val} {
 upvar $v_name v
 if {![info exists v]} {
  return -code error "error: variable $v_name doesn't exist."
 }
 set v $val
}

proc get.unique.command.name {} {
 while 1 {
  if {"" eq [info commands [set n cmd[clock clicks]]]} {
   return $n
  }
 }
}

# N E W

set ::_current_class ""

proc class name {
 #puts NAME:$name
 ?set ::_current_class $name
 set ::_${name}_methods [list]
}

proc dispatch {class obj argList} {
 set r {}
 foreach {sel msg} $argList {
  #puts "INVOKE $sel : $msg"
  set r [_${class}_${sel} $obj $msg]
 }
 set r
}

proc endclass {} {
 proc $::_current_class {} {
  set class [lindex [info level 0] 0]
  set obj [get.unique.command.name]
  proc $obj args "dispatch $class $obj \$args"
  return $obj
 }
 ?set ::_current_class ""
}

proc inherit class {
 puts INH:[set ::_${class}_methods]
 #copy all methods in $class to current_class
}

proc method {name body} {
 proc _${::_current_class}_$name {self msg} $body
 lappend ::_[set ::_current_class]_methods $name
}


# T E S T  C O D E

class Object
 method -get {
  set ::__${self}_var_${msg}
 }

 method -set {
  set ::__${self}_var_name $msg
 }

 method -to {
  set ::__${self}_var_[set ::__${self}_var_name] $msg
 }
endclass


class Funzo
 method -fust {
  puts "FUST $msg"
 } 

 method -text {
  puts "oh, if I were a text item, I'd display $msg"
 }
endclass


class Fustigate
 inherit Object
 inherit Funzo 

 method -HIHI {
  puts "HIHI $msg"
 }
endclass


proc main {} {
 set f [Funzo]

 $f -fust Hello -text "Hello World"

 set o [Object]

 $o -set var -to blah
 puts GET:[$o -get var]
}
main