From 2ed67750d19f6a428a12f468269f8c549c458da7 Mon Sep 17 00:00:00 2001 From: dkf Date: Mon, 17 May 2004 22:31:30 +0000 Subject: Added example --- ChangeLog | 2 +- doc/uplevel.n | 22 +++++++++++++++++++++- 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 - * 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) -- cgit v0.12