diff options
author | dkf <dkf@noemail.net> | 2004-05-28 00:05:02 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2004-05-28 00:05:02 (GMT) |
commit | 0228efff0b04713c5161125a543a4b0305b37558 (patch) | |
tree | 12f9f33ebd41fe8c243941c253a43a4488d79b8e | |
parent | 05d3fc8ef8f33c74f6cbe1214767e667c24bff16 (diff) | |
download | tcl-0228efff0b04713c5161125a543a4b0305b37558.zip tcl-0228efff0b04713c5161125a543a4b0305b37558.tar.gz tcl-0228efff0b04713c5161125a543a4b0305b37558.tar.bz2 |
Added examples
FossilOrigin-Name: afba689385c01b925933d9dac62277d60d0403ca
-rw-r--r-- | doc/trace.n | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/doc/trace.n b/doc/trace.n index 0e74108..716a918 100644 --- a/doc/trace.n +++ b/doc/trace.n @@ -6,7 +6,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: trace.n,v 1.15 2003/10/08 17:50:32 dgp Exp $ +'\" RCS: @(#) $Id: trace.n,v 1.16 2004/05/28 00:05:02 dkf Exp $ '\" .so man.macros .TH trace n "8.4" Tcl "Tcl Built-In Commands" @@ -354,6 +354,29 @@ future version of Tcl. They use an older syntax in which \fBarray\fR, \fBw\fR and \fBu\fR respectively, and the \fIops\fR argument is not a list, but simply a string concatenation of the operations, such as \fBrwua\fR. +.SH EXAMPLES +Print a message whenever either of the global variables \fBfoo\fR and +\fBbar\fR are updated, even if they have a different local name at the +time (which can be done with the \fBupvar\fR command): +.CS +proc tracer {varname args} { + upvar #0 $varname var + puts "$varname was updated to be \e"$var\e"" +} +trace add variable foo write "tracer foo" +trace add variable bar write "tracer bar" +.CE +.PP +Ensure that the global variable \fBfoobar\fR always contains the +product of the global variables \fBfoo\fR and \fBbar\fR: +.CS +proc doMult args { + global foo bar foobar + set foobar [expr {$foo * $bar}] +} +trace add variable foo write doMult +trace add variable bar write doMult +.CE .SH "SEE ALSO" set(n), unset(n) |