Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added tcl to libs

File size: 8.6 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: Tcl.n,v 1.18 2007/12/13 15:22:32 dgp Exp $
9'\"
10.so man.macros
11.TH Tcl n "8.5" Tcl "Tcl Built-In Commands"
12.BS
13.SH NAME
14Tcl \- Tool Command Language
15.SH SYNOPSIS
16Summary of Tcl language syntax.
17.BE
18.SH DESCRIPTION
19.PP
20The following rules define the syntax and semantics of the Tcl language:
21.IP "[1] \fBCommands.\fR"
22A Tcl script is a string containing one or more commands.
23Semi-colons and newlines are command separators unless quoted as
24described below.
25Close brackets are command terminators during command substitution
26(see below) unless quoted.
27.IP "[2] \fBEvaluation.\fR"
28A command is evaluated in two steps.
29First, the Tcl interpreter breaks the command into \fIwords\fR
30and performs substitutions as described below.
31These substitutions are performed in the same way for all
32commands.
33The first word is used to locate a command procedure to
34carry out the command, then all of the words of the command are
35passed to the command procedure.
36The command procedure is free to interpret each of its words
37in any way it likes, such as an integer, variable name, list,
38or Tcl script.
39Different commands interpret their words differently.
40.IP "[3] \fBWords.\fR"
41Words of a command are separated by white space (except for
42newlines, which are command separators).
43.IP "[4] \fBDouble quotes.\fR"
44If the first character of a word is double-quote
45.PQ \N'34'
46then the word is terminated by the next double-quote character.
47If semi-colons, close brackets, or white space characters
48(including newlines) appear between the quotes then they are treated
49as ordinary characters and included in the word.
50Command substitution, variable substitution, and backslash substitution
51are performed on the characters between the quotes as described below.
52The double-quotes are not retained as part of the word.
53.VS 8.5 br
54.IP "[5] \fBArgument expansion.\fR"
55If a word starts with the string
56.QW {*}
57followed by a non-whitespace character, then the leading
58.QW {*}
59is removed
60and the rest of the word is parsed and substituted as any other
61word. After substitution, the word is parsed again without
62substitutions, and its words are added to the command being
63substituted. For instance,
64.QW "cmd a {*}{b c} d {*}{e f}"
65is equivalent to
66.QW "cmd a b c d e f" .
67.VE 8.5
68.IP "[6] \fBBraces.\fR"
69If the first character of a word is an open brace
70.PQ {
71and rule [5] does not apply, then
72the word is terminated by the matching close brace
73.PQ } "" .
74Braces nest within the word: for each additional open
75brace there must be an additional close brace (however,
76if an open brace or close brace within the word is
77quoted with a backslash then it is not counted in locating the
78matching close brace).
79No substitutions are performed on the characters between the
80braces except for backslash-newline substitutions described
81below, nor do semi-colons, newlines, close brackets,
82or white space receive any special interpretation.
83The word will consist of exactly the characters between the
84outer braces, not including the braces themselves.
85.IP "[7] \fBCommand substitution.\fR"
86If a word contains an open bracket
87.PQ [
88then Tcl performs \fIcommand substitution\fR.
89To do this it invokes the Tcl interpreter recursively to process
90the characters following the open bracket as a Tcl script.
91The script may contain any number of commands and must be terminated
92by a close bracket
93.PQ ] "" .
94The result of the script (i.e. the result of its last command) is
95substituted into the word in place of the brackets and all of the
96characters between them.
97There may be any number of command substitutions in a single word.
98Command substitution is not performed on words enclosed in braces.
99.IP "[8] \fBVariable substitution.\fR"
100If a word contains a dollar-sign
101.PQ $
102followed by one of the forms
103described below, then Tcl performs \fIvariable
104substitution\fR:  the dollar-sign and the following characters are
105replaced in the word by the value of a variable.
106Variable substitution may take any of the following forms:
107.RS
108.TP 15
109\fB$\fIname\fR
110\fIName\fR is the name of a scalar variable;  the name is a sequence
111of one or more characters that are a letter, digit, underscore,
112or namespace separators (two or more colons).
113.TP 15
114\fB$\fIname\fB(\fIindex\fB)\fR
115\fIName\fR gives the name of an array variable and \fIindex\fR gives
116the name of an element within that array.
117\fIName\fR must contain only letters, digits, underscores, and
118namespace separators, and may be an empty string.
119Command substitutions, variable substitutions, and backslash
120substitutions are performed on the characters of \fIindex\fR.
121.TP 15
122\fB${\fIname\fB}\fR
123\fIName\fR is the name of a scalar variable.  It may contain any
124characters whatsoever except for close braces.
125.LP
126There may be any number of variable substitutions in a single word.
127Variable substitution is not performed on words enclosed in braces.
128.RE
129.IP "[9] \fBBackslash substitution.\fR"
130If a backslash
131.PQ \e
132appears within a word then \fIbackslash substitution\fR occurs.
133In all cases but those described below the backslash is dropped and
134the following character is treated as an ordinary
135character and included in the word.
136This allows characters such as double quotes, close brackets,
137and dollar signs to be included in words without triggering
138special processing.
139The following table lists the backslash sequences that are
140handled specially, along with the value that replaces each sequence.
141.RS
142.TP 7
143\e\fBa\fR
144Audible alert (bell) (0x7).
145.TP 7
146\e\fBb\fR
147Backspace (0x8).
148.TP 7
149\e\fBf\fR
150Form feed (0xc).
151.TP 7
152\e\fBn\fR
153Newline (0xa).
154.TP 7
155\e\fBr\fR
156Carriage-return (0xd).
157.TP 7
158\e\fBt\fR
159Tab (0x9).
160.TP 7
161\e\fBv\fR
162Vertical tab (0xb).
163.TP 7
164\e\fB<newline>\fIwhiteSpace\fR
165.
166A single space character replaces the backslash, newline, and all spaces
167and tabs after the newline.  This backslash sequence is unique in that it
168is replaced in a separate pre-pass before the command is actually parsed.
169This means that it will be replaced even when it occurs between braces,
170and the resulting space will be treated as a word separator if it is not
171in braces or quotes.
172.TP 7
173\e\e
174Backslash
175.PQ \e "" .
176.TP 7
177\e\fIooo\fR
178.
179The digits \fIooo\fR (one, two, or three of them) give an eight-bit octal
180value for the Unicode character that will be inserted.  The upper bits of the
181Unicode character will be 0.
182.TP 7
183\e\fBx\fIhh\fR
184.
185The hexadecimal digits \fIhh\fR give an eight-bit hexadecimal value for the
186Unicode character that will be inserted.  Any number of hexadecimal digits
187may be present; however, all but the last two are ignored (the result is
188always a one-byte quantity).  The upper bits of the Unicode character will
189be 0.
190.TP 7
191\e\fBu\fIhhhh\fR
192.
193The hexadecimal digits \fIhhhh\fR (one, two, three, or four of them) give a
194sixteen-bit hexadecimal value for the Unicode character that will be
195inserted.
196.LP
197Backslash substitution is not performed on words enclosed in braces,
198except for backslash-newline as described above.
199.RE
200.IP "[10] \fBComments.\fR"
201If a hash character
202.PQ #
203appears at a point where Tcl is
204expecting the first character of the first word of a command,
205then the hash character and the characters that follow it, up
206through the next newline, are treated as a comment and ignored.
207The comment character only has significance when it appears
208at the beginning of a command.
209.IP "[11] \fBOrder of substitution.\fR"
210Each character is processed exactly once by the Tcl interpreter
211as part of creating the words of a command.
212For example, if variable substitution occurs then no further
213substitutions are performed on the value of the variable;  the
214value is inserted into the word verbatim.
215If command substitution occurs then the nested command is
216processed entirely by the recursive call to the Tcl interpreter;
217no substitutions are performed before making the recursive
218call and no additional substitutions are performed on the result
219of the nested script.
220.RS
221.LP
222Substitutions take place from left to right, and each substitution is
223evaluated completely before attempting to evaluate the next.  Thus, a
224sequence like
225.CS
226set y [set x 0][incr x][incr x]
227.CE
228will always set the variable \fIy\fR to the value, \fI012\fR.
229.RE
230.IP "[12] \fBSubstitution and word boundaries.\fR"
231Substitutions do not affect the word boundaries of a command,
232except for argument expansion as specified in rule [5].
233For example, during variable substitution the entire value of
234the variable becomes part of a single word, even if the variable's
235value contains spaces.
Note: See TracBrowser for help on using the repository browser.