Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/eval.n @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

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