summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-05-17 22:31:30 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-05-17 22:31:30 (GMT)
commit2ed67750d19f6a428a12f468269f8c549c458da7 (patch)
tree39b6163ac3df3de286b2366cbd5dc1740bd231c1
parenta5814852ae67398cca46427e3bf248d577bc0c49 (diff)
downloadtcl-2ed67750d19f6a428a12f468269f8c549c458da7.zip
tcl-2ed67750d19f6a428a12f468269f8c549c458da7.tar.gz
tcl-2ed67750d19f6a428a12f468269f8c549c458da7.tar.bz2
Added example
-rw-r--r--ChangeLog2
-rw-r--r--doc/uplevel.n22
2 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 32208f8..06f85c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
2004-05-17 Donal K. Fellows <donal.k.fellows@man.ac.uk>
- * doc/global.n: Added an example.
+ * doc/global.n, doc/uplevel.n: Added an example.
* tests/info.test (info-3.1): Corrected test result back to what
it used to be in Tcl 7.* now that command counts are being
diff --git a/doc/uplevel.n b/doc/uplevel.n
index 0d3bf6e..abbc4f2 100644
--- a/doc/uplevel.n
+++ b/doc/uplevel.n
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: uplevel.n,v 1.3 2000/09/07 14:27:52 poenitz Exp $
+'\" RCS: @(#) $Id: uplevel.n,v 1.4 2004/05/17 22:31:31 dkf Exp $
'\"
.so man.macros
.TH uplevel n "" Tcl "Tcl Built-In Commands"
@@ -72,6 +72,26 @@ describing a command that is either
the outermost procedure call or the outermost \fBnamespace eval\fR command.
Also, \fBuplevel #0\fR evaluates a script
at top-level in the outermost namespace (the global namespace).
+.SH EXAMPLE
+As stated above, the \fBuplevel\fR command is useful for creating new
+control constructs. This example shows how (without error handling)
+it can be used to create a \fBdo\fR command that is the counterpart of
+\fBwhile\fR except for always performing the test after running the
+loop body:
+.CS
+proc do {body while condition} {
+ if {$while ne "while"} {
+ error "required word missing"
+ }
+ set conditionCmd [list expr $condition]
+ while {1} {
+ uplevel 1 $body
+ if {![uplevel 1 $conditionCmd]} {
+ break
+ }
+ }
+}
+.CE
.SH "SEE ALSO"
namespace(n), upvar(n)