I extracted the code below from a very large XOTcl program that I am developing right now. The output of the last line 'puts "uuuuu guest_bathroom3 [guest_bathroom3 currTemp]"' puzzles me! If I uncomment the line 'set temp [Celsius2Kelvin 20]' the output is even weirder (an error message). Any helpful comments?
Regards, - Florian
My code:
package require XOTcl namespace import xotcl::my xotcl::self xotcl::next xotcl::Class xotcl::@ namespace eval tih { Class Floor -parameter { {cubicles {}} } Class Room -parameter { {cubicles {}} } Room instparametercmd currTemp # --- 'unknown'-mechanism. Floor proc createRoom01 {floor aName args} { #set temp [Celsius2Kelvin 20] set room [eval {Room create $aName} $args] $floor lappend cubicles $aName $room set Floor $floor } Floor instproc rooms {{a {}}} { ;# getter/setter my instvar cubicles if {[llength $a]} { set itp [self]_createRoom01 interp create $itp interp alias $itp unknown {} ::tih::Floor createRoom01 [self] set rval [$itp eval $a] interp delete $itp return } set rval [list] foreach i $cubicles { # xxx verbessern! if {[$i istype Room]} { lappend rval $i } } set rval } proc Celsius2Kelvin {a} { expr {$a+273.15} } Floor floor3 -rooms { guest_room guest_bathroom3 -currTemp [Celsius2Kelvin 30] } #puts "uuuuu guest_room [guest_room currTemp]" puts "uuuuu guest_bathroom3 [guest_bathroom3 currTemp]" }
i am somewhat confused be the code (why are you creating and deleting interpreters?) is the following code doing, what you are trying? (aggregates rooms on floors with a simple syntax)
-gustaf =================================================== package require XOTcl namespace import -force ::xotcl::*
namespace eval tih { Class Floor \ -instproc has cmds {eval $cmds}
Class Room -superclass Class \ -parameter {{count 0} currTemp} \ -instproc new args { set name "[self callingobject]::[namespace tail [self]]-[my incr count]" eval [self] create $name $args }
Room room -parameter {{currTemp 300}} Room guestRoom -superclass room Room bathRoom -superclass room Room guestBathRoom -superclass bathRoom
proc Celsius2Kelvin {a} { expr {$a+273.15} }
Floor floor3 -has { guestRoom new guestBathRoom new -currTemp [Celsius2Kelvin 30] }
puts "rooms on floor 3: [floor3 info children]" foreach c [floor3 info children] { puts "temperature in room $c is [$c currTemp]" }
} exit