summaryrefslogtreecommitdiffstats
path: root/doc/trace.n
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-05-28 00:05:02 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-05-28 00:05:02 (GMT)
commit59377a4a389f5f6d2eb4dd8a2968c7bbb10e04ad (patch)
tree12f9f33ebd41fe8c243941c253a43a4488d79b8e /doc/trace.n
parentf96c2ee50df9a0eb1ee70fa115d95b0bf026404f (diff)
downloadtcl-59377a4a389f5f6d2eb4dd8a2968c7bbb10e04ad.zip
tcl-59377a4a389f5f6d2eb4dd8a2968c7bbb10e04ad.tar.gz
tcl-59377a4a389f5f6d2eb4dd8a2968c7bbb10e04ad.tar.bz2
Added examples
Diffstat (limited to 'doc/trace.n')
-rw-r--r--doc/trace.n25
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)