home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / Tcl.n < prev    next >
Text File  |  1993-07-28  |  8KB  |  206 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/Tcl.n,v 1.118 93/07/28 14:13:25 ouster Exp $ SPRITE (Berkeley)
  22. '
  23. .so man.macros
  24. .de UL
  25. \\$1\l'|0\(ul'\\$2
  26. ..
  27. .HS Tcl tcl
  28. .BS
  29. .SH NAME
  30. Tcl \- Summary of Tcl language syntax.
  31. .BE
  32.  
  33. .SH DESCRIPTION
  34. .LP
  35. The following rules define the syntax and semantics of the Tcl language:
  36. .IP [1]
  37. A Tcl script is a string containing one or more commands.
  38. Semi-colons and newlines are command separators unless quoted as
  39. described below.
  40. Close brackets are command terminators during command substitution
  41. (see below) unless quoted.
  42. .IP [2]
  43. A command is evaluated in two steps.
  44. First, the Tcl interpreter breaks the command into \fIwords\fR
  45. and performs substitutions as described below.
  46. These substitutions are performed in the same way for all
  47. commands.
  48. The first word is used to locate a command procedure to
  49. carry out the command, then all of the words of the command are
  50. passed to the command procedure.
  51. The command procedure is free to interpret each of its words
  52. in any way it likes, such as an integer, variable name, list,
  53. or Tcl script.
  54. Different commands interpret their words differently.
  55. .IP [3]
  56. Words of a command are separated by white space (except for
  57. newlines, which are command separators).
  58. .IP [4]
  59. If the first character of a word is double-quote (``"'') then
  60. the word is terminated by the next double-quote character.
  61. If semi-colons, close brackets, or white space characters
  62. (including newlines) appear between the quotes then they are treated
  63. as ordinary characters and included in the word.
  64. Command substitution, variable substitution, and backslash substitution
  65. are performed on the characters between the quotes as described below.
  66. The double-quotes are not retained as part of the word.
  67. .IP [5]
  68. If the first character of a word is an open brace (``{'') then
  69. the word is terminated by the matching close brace (``}'').
  70. Braces nest within the word: for each additional open
  71. brace there must be an additional close brace (however,
  72. if an open brace or close brace within the word is
  73. quoted with a backslash then it is not counted in locating the
  74. matching close brace).
  75. No substitutions are performed on the characters between the
  76. braces except for backslash-newline substitutions described
  77. below, nor do semi-colons, newlines, close brackets,
  78. or white space receive any special interpretation.
  79. The word will consist of exactly the characters between the
  80. outer braces, not including the braces themselves.
  81. .IP [6]
  82. If a word contains an open bracket (``['') then Tcl performs
  83. \fIcommand substitution\fR.
  84. To do this it invokes the Tcl interpreter recursively to process
  85. the characters following the open bracket as a Tcl script.
  86. The script may contain any number of commands and must be terminated
  87. by a close bracket (``]'').
  88. The result of the script (i.e. the result of its last command) is
  89. substituted into the word in place of the brackets and all of the
  90. characters between them.
  91. There may be any number of command substitutions in a single word.
  92. Command substitution is not performed on words enclosed in braces.
  93. .IP [7]
  94. If a word contains a dollar-sign (``$'') then Tcl performs \fIvariable
  95. substitution\fR:  the dollar-sign and the following characters are
  96. replaced in the word by the value of a variable.
  97. Variable substition may take any of the following forms:
  98. .RS
  99. .TP 15
  100. \fB$\fIname\fR
  101. \fIName\fR is the name of a scalar variable;  the name is terminated
  102. by any character that isn't a letter, digit, or underscore.
  103. .TP 15
  104. \fB$\fIname\fB(\fIindex\fB)\fR
  105. \fIName\fR gives the name of an array variable and \fIindex\fR gives
  106. the name of an element within that array.
  107. \fIName\fR must contain only letters, digits, and underscores.
  108. Command substitutions, variable substitutions, and backslash
  109. substitutions are performed on the characters of \fIindex\fR.
  110. .TP 15
  111. \fB${\fIname\fB}\fR
  112. \fIName\fR is the name of a scalar variable.  It may contain any
  113. characters whatsoever except for close braces.
  114. .RE
  115. .LP
  116. There may be any number of variable substitutions in a single word.
  117. Variable substitution is not performed on words enclosed in braces.
  118. .IP [8]
  119. If a backslash (``\e'') appears within a word then
  120. \fIbackslash substitution\fR occurs.
  121. .VS
  122. In all cases but those described below the backslash is dropped and
  123. the following character is treated as an ordinary
  124. character and included in the word.
  125. .VE
  126. This allows characters such as double quotes, close brackets,
  127. and dollar signs to be included in words without triggering
  128. special processing.
  129. The following table lists the backslash sequences that are
  130. handled specially, along with the value that replaces each sequence.
  131. .RS
  132. .VS
  133. .TP 6
  134. \e\fBa\fR
  135. Audible alert (bell) (0x7).
  136. .VE
  137. .TP 6
  138. \e\fBb\fR
  139. Backspace (0x8).
  140. .TP 6
  141. \e\fBf\fR
  142. Form feed (0xc).
  143. .TP 6
  144. \e\fBn\fR
  145. Newline (0xa).
  146. .TP 6
  147. \e\fBr\fR
  148. Carriage-return (0xd).
  149. .TP 6
  150. \e\fBt\fR
  151. Tab (0x9).
  152. .TP 6
  153. \e\fBv\fR
  154. Vertical tab (0xb).
  155. .TP 6
  156. \e\fB<newline>\fIwhiteSpace\fR\fR
  157. .VS
  158. A single space character replaces the backslash, newline, and all
  159. white space after the newline.
  160. This backslash sequence is unique in that it is replaced in a separate
  161. pre-pass before the command is actually parsed.
  162. This means that it will be replaced even when it occurs between
  163. braces, and the resulting space will be treated as a word separator
  164. if it isn't in braces or quotes.
  165. .VE
  166. .TP 6
  167. \e\e
  168. Backslash (``\e'').
  169. .TP 6
  170. \e\fIooo\fR
  171. The digits \fIooo\fR (one, two, or three of them) give the octal value of
  172. the character.
  173. .TP 6
  174. \e\fBx\fIhh\fR
  175. .VS
  176. The hexadecimal digits \fIhh\fR give the hexadecimal value of
  177. the character.  Any number of digits may be present.
  178. .VE
  179. .RE
  180. .LP
  181. Backslash substitution is not performed on words enclosed in braces,
  182. except for backslash-newline as described above.
  183. .IP [9]
  184. If a hash character (``#'') appears at a point where Tcl is
  185. expecting the first character of the first word of a command,
  186. then the hash character and the characters that follow it, up
  187. through the next newline, are treated as a comment and ignored.
  188. The comment character only has significance when it appears
  189. at the beginning of a command.
  190. .IP [10]
  191. Each character is processed exactly once by the Tcl interpreter
  192. as part of creating the words of a command.
  193. For example, if variable substition occurs then no further
  194. substitions are performed on the value of the variable;  the
  195. value is inserted into the word verbatim.
  196. If command substitution occurs then the nested command is
  197. processed entirely by the recursive call to the Tcl interpreter;
  198. no substitutions are perfomed before making the recursive
  199. call and no additional substitutions are performed on the result
  200. of the nested script.
  201. .IP [11]
  202. Substitutions do not affect the word boundaries of a command.
  203. For example, during variable substitution the entire value of
  204. the variable becomes part of a single word, even if the variable's
  205. value contains spaces.
  206.