http://www.purl.org/tcl/home/man/tcl8.4/TclCmd/trace.htm ---- What are some of the uses for trace? Well, see [Traces] for some wiki info. * Communication between parts of a GUI and the internal state of the app. (Simplified MVC, observer). In general communication between different parts of an app without coupling them strongly. * Simple constraint computation for a number of variables ("if this flag is and that one, then no other is allwed to set", and some such). * [Canvas] text items bound to a variable, dynamically updating ---- ''A small example to illustrate the order of processing -- [JCW]'' proc tellme {id a e op} { puts " $id a=$a e=$e op=$op\ ax=[info exists ::$a] ex=[info exists ::${a}($e)]" } proc do {args} { puts "<$args>" uplevel $args } trace var a wu {tellme array} trace var a(1) wu {tellme element} puts [trace vinfo a] puts [trace vinfo a(1)] do set a(0) zero do set a(1) one do set a(2) two do unset a(0) do unset a(2) do unset a # output is: # # {wu {tellme array}} # {wu {tellme element}} # # array a=a e=0 op=w ax=1 ex=1 # # array a=a e=1 op=w ax=1 ex=1 # element a=a e=1 op=w ax=1 ex=1 # # array a=a e=2 op=w ax=1 ex=1 # # array a=a e=0 op=u ax=1 ex=0 # # array a=a e=2 op=u ax=1 ex=0 # # array a=a e= op=u ax=0 ex=0 # element a=a e=1 op=u ax=0 ex=0 ---- On news:comp.lang.tcl, [CLN] answers [Erik Leunissen]'s question: Erik Leunissen wrote: > The following passage from the man page to the trace command is > mystifying to me: > > "If an unset occurs because of a procedure return, then the trace will > be invoked in the variable context of the procedure being returned to: > the stack frame of the returning procedure will no longer exist." > > I've read it again and again; I can't imagine how a procedure return > affects/causes an unset. > ... proc foo { } { set x 1 trace variable u x {some code here} } When foo is invoked, x is created (locally), has a trace associated with it, then becomes unset as foo exits. ---- [Tcl syntax help] - [Arts and crafts of Tcl-Tk programming] - [Category Command]