<br>I am passing an array name by reference across an instproc. <br><br>The vanilla version works just fine (see creation of x1 midway through the code segment). <br><br>To add some debugging in, I essentially used the trace example from the tutorial, and funnily,
<br>the upvar stopped doing it's job (see error on creating x2 towards the end of the code segment). <br><br>To get rudimentary debug control of the parray proc, I copied it into a proc called barray. None of the logic is changed -
<br>just my crude attempt at adding breadcrumbs. <br><br>I have included the output at the end of the code segment. <br><br>Running Windows XP Pro + Active Tcl 8.4.13 + XoTcl 1.4.0. <br><br>thanks for all help. <br>-shishir
<br><br><CODE SEGMENT><br>package require XOTcl<br>namespace import ::xotcl::*<br><br><br>proc barray {a {pattern "*"}} {<br> puts "barray"<br> upvar 1 $a arr<br> if {![array exists arr]} {
<br> error "\"$a\" isn't an array"<br> }<br> set maxl 0<br> foreach name [lsort [array names arr $pattern]] {<br> if {[string length $name] > $maxl} {<br> set maxl [string length $name]
<br> }<br> }<br> set maxl [expr {$maxl + [string length $a] + 2}]<br> foreach name [lsort [array names arr $pattern]] {<br> set nameString [format %s(%s) $a $name]<br> puts stdout [format "%-*s = %s" $maxl $nameString $arr($name)]
<br> }<br>}<br><br>Class X<br><br>X instproc bar {ar args} {<br> puts "bar"<br> upvar $ar arr<br> puts "upvard"<br> barray arr<br>}<br><br><br><br>X instproc init {args} {<br> array set arr {a 1 b 2}
<br> parray arr<br> my bar arr<br>}<br><br>X x1<br><br><br>Object Trace<br>Trace set traceStream stdout<br>Trace proc openTraceFile name {<br> my set traceStream [open $name w]<br>}<br>Trace proc closeTraceFile {} {<br>
close $Trace::traceStream<br> my set traceStream stdout<br>}<br>Trace proc puts line {<br> puts $Trace::traceStream $line<br>}<br>Trace proc add className {<br> $className instfilter [concat [$className info filter] traceFilter]
<br>}<br><br>Object instproc traceFilter args {<br> # don't trace the Trace object<br> if {[string equal [self] ::Trace]} {return [next]}<br> set context "[self class]->[self callingproc]"<br> set method [self calledproc]
<br> switch -- $method {<br> proc -<br> instproc {::set dargs [list [lindex $args 0] [lindex $args 1] ...] }<br> default {::set dargs $args }<br> }<br> Trace::puts "CALL $context> [self]->$method $dargs"
<br> set result [next]<br> Trace::puts "EXIT $context> [self]->$method ($result)"<br> return $result<br>}<br><br>Trace add X<br><br>X x2<br><br></CODE SEGMENT><br><br>------------<br><br><OUTPUT>
<br>arr(a) = 1<br>arr(b) = 2<br>bar<br>upvard<br>barray<br>arr(a) = 1<br>arr(b) = 2<br>CALL ::xotcl::Object->> ::x2->cleanup<br>EXIT ::xotcl::Object->> ::x2->cleanup ()<br>CALL ::xotcl::Object->> ::x2->configure
<br>EXIT ::xotcl::Object->> ::x2->configure (0)<br>CALL ::xotcl::Object->> ::x2->init<br>arr(a) = 1<br>arr(b) = 2<br>CALL ::xotcl::Object->init> ::x2->bar arr<br>bar<br>upvard<br>barray<br>"arr" isn't an array
<br></OUTPUT><br><br>----<br><br><ERRORINFO><br>% set errorInfo<br>"arr" isn't an array<br> while executing<br>"error "\"$a\" isn't an array""<br> (procedure "barray" line 5)
<br> invoked from within<br>"barray arr"<br> (procedure "bar" line 6)<br> invoked from within<br>"next"<br> (procedure "bar" line 13)<br> ::x2 ::xotcl::Object->traceFilter
<br> invoked from within<br>"my bar arr"<br> (procedure "init" line 5)<br> invoked from within<br>"next"<br> (procedure "init" line 13)<br> ::x2 ::xotcl::Object->traceFilter
<br> ::X ::xotcl::Class->recreate<br> ::X ::xotcl::Class->create<br> ::X ::xotcl::Class->unknown<br> invoked from within<br>"X x2"<br> (file "c:/temp/trace_trouble.tcl" line 81)
<br> invoked from within<br>"source c:/temp/trace_trouble.tcl"<br clear="all"></ERRORINFO><br><br><br>