Debian Codegraph @

doc/eval.n

raw
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 .TH eval n "" Tcl "Tcl Built-In Commands"
9 .so man.macros
10 .BS
11 '\" Note: do not modify the .SH NAME line immediately below!
12 .SH NAME
13 eval \- Evaluate a Tcl script
14 .SH SYNOPSIS
15 \fBeval \fIarg \fR?\fIarg ...\fR?
16 .BE
17 .SH DESCRIPTION
18 .PP
19 \fBEval\fR takes one or more arguments, which together comprise a Tcl
20 script containing one or more commands.
21 \fBEval\fR concatenates all its arguments in the same
22 fashion as the \fBconcat\fR command, passes the concatenated string to the
23 Tcl interpreter recursively, and returns the result of that
24 evaluation (or any error generated by it).
25 Note that the \fBlist\fR command quotes sequences of words in such a
26 way that they are not further expanded by the \fBeval\fR command.
27 .SH EXAMPLES
28 .PP
29 Often, it is useful to store a fragment of a script in a variable and
30 execute it later on with extra values appended. This technique is used
31 in a number of places throughout the Tcl core (e.g. in \fBfcopy\fR,
32 \fBlsort\fR and \fBtrace\fR command callbacks). This example shows how
33 to do this using core Tcl commands:
34 .PP
35 .CS
36 set script {
37 puts "logging now"
38 lappend $myCurrentLogVar
39 }
40 set myCurrentLogVar log1
41 # Set up a switch of logging variable part way through!
42 after 20000 set myCurrentLogVar log2
43
44 for {set i 0} {$i<10} {incr i} {
45 # Introduce a random delay
46 after [expr {int(5000 * rand())}]
47 update ;# Check for the asynch log switch
48 \fBeval\fR $script $i [clock clicks]
49 }
50 .CE
51 .PP
52 Note that in the most common case (where the script fragment is
53 actually just a list of words forming a command prefix), it is better
54 to use \fB{*}$script\fR when doing this sort of invocation
55 pattern. It is less general than the \fBeval\fR command, and hence
56 easier to make robust in practice.
57 The following procedure acts in a way that is analogous to the
58 \fBlappend\fR command, except it inserts the argument values at the
59 start of the list in the variable:
60 .PP
61 .CS
62 proc lprepend {varName args} {
63 upvar 1 $varName var
64 # Ensure that the variable exists and contains a list
65 lappend var
66 # Now we insert all the arguments in one go
67 set var [\fBeval\fR [list linsert $var 0] $args]
68 }
69 .CE
70 .PP
71 However, the last line would now normally be written without
72 \fBeval\fR, like this:
73 .PP
74 .CS
75 set var [linsert $var 0 {*}$args]
76 .CE
77 .SH "SEE ALSO"
78 catch(n), concat(n), error(n), errorCode(n), errorInfo(n), interp(n), list(n),
79 namespace(n), subst(n), uplevel(n)
80 .SH KEYWORDS
81 concatenate, evaluate, script
82 '\" Local Variables:
83 '\" mode: nroff
84 '\" End: