diff options
Diffstat (limited to 'doc/eval.n')
-rw-r--r-- | doc/eval.n | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -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: eval.n,v 1.5 2004/05/28 10:37:04 dkf Exp $ +'\" RCS: @(#) $Id: eval.n,v 1.6 2004/10/27 09:36:58 dkf Exp $ '\" .so man.macros .TH eval n "" Tcl "Tcl Built-In Commands" @@ -27,7 +27,7 @@ Tcl interpreter recursively, and returns the result of that evaluation (or any error generated by it). Note that the \fBlist\fR command quotes sequences of words in such a way that they are not further expanded by the \fBeval\fR command. -.SH EXAMPLE +.SH EXAMPLES Often, it is useful to store a fragment of a script in a variable and execute it later on with extra values appended. This technique is used in a number of places throughout the Tcl core (e.g. in \fBfcopy\fR, @@ -46,9 +46,10 @@ for {set i 0} {$i<10} {incr i} { # Introduce a random delay after [expr {int(5000 * rand())}] update ;# Check for the asynch log switch - eval $script $i [clock clicks] + \fBeval\fR $script $i [clock clicks] } .CE +.PP .VS 8.5 Note that in the most common case (where the script fragment is actually just a list of words forming a command prefix), it is better @@ -56,6 +57,25 @@ to use \fB{expand}$script\fR when doing this sort of invokation pattern. It is less general than the \fBeval\fR command, and hence easier to make robust in practice. .VE 8.5 +The following procedure acts in a way that is analogous to the +\fBlappend\fR command, except it inserts the argument values at the +start of the list in the variable: +.CS +proc lprepend {varName args} { + upvar 1 $varName var + # Ensure that the variable exists and contains a list + lappend var + # Now we insert all the arguments in one go + set var [\fBeval\fR [list linsert $var 0] $args] +} +.CE +.VS 8.5 +However, the last line would now normally be written without +\fBeval\fR, like this: +.CS +set var [linsert $var 0 {expand}$args] +.CE +.VE 8.5 .SH KEYWORDS concatenate, evaluate, script |