home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / editor / alpha513.cpt / Help / Tcl < prev    next >
Text File  |  1992-10-17  |  138KB  |  2,565 lines

  1.  
  2.     TCL - overview of Tool Command Language facilities
  3.  
  4.  
  5. INTRODUCTION
  6.      Tcl stands for ``tool command language'' and  is  pronounced
  7.      ``tickle.''  It  is  actually  two  things: a language and a
  8.      library.  First, Tcl is a simple textual language,  intended
  9.      primarily  for issuing commands to interactive programs such
  10.      as text editors, debuggers, illustrators,  and  shells.   It
  11.      has  a  simple syntax and is also programmable, so Tcl users
  12.      can write command procedures to provide more  powerful  com-
  13.      mands than those in the built-in set.
  14.  
  15.      Second, Tcl is a library package that  can  be  embedded  in
  16.      application  programs.  The Tcl library consists of a parser
  17.      for the Tcl language, routines to implement the Tcl built-in
  18.      commands,  and  procedures  that  allow  each application to
  19.      extend Tcl with additional commands specific to that  appli-
  20.      cation.   The application program generates Tcl commands and
  21.      passes them to the Tcl parser for execution.   Commands  may
  22.      be  generated by reading characters from an input source, or
  23.      by  associating  command  strings  with  elements   of   the
  24.      application's user interface, such as menu entries, buttons,
  25.      or keystrokes.  When the Tcl library  receives  commands  it
  26.      parses them into component fields and executes built-in com-
  27.      mands directly.  For commands implemented  by  the  applica-
  28.      tion,  Tcl calls back to the application to execute the com-
  29.      mands.  In many cases commands will invoke recursive invoca-
  30.      tions  of  the  Tcl  interpreter  by  passing  in additional
  31.      strings to execute (procedures, looping commands, and condi-
  32.      tional commands all work in this way).
  33.  
  34.      An application program gains three advantages by  using  Tcl
  35.      for  its  command  language.  First, Tcl provides a standard
  36.      syntax:  once users know Tcl, they will  be  able  to  issue
  37.      commands  easily  to any Tcl-based application.  Second, Tcl
  38.      provides programmability.  All a Tcl application needs to do
  39.      is  to  implement  a few application-specific low-level com-
  40.      mands.  Tcl provides many utility commands  plus  a  general
  41.      programming  interface  for building up complex command pro-
  42.      cedures.  By using Tcl, applications need  not  re-implement
  43.      these features.  Third, Tcl can be used as a common language  |
  44.      for communicating between  applications.   Inter-application  |
  45.      communication is not built into the Tcl core described here,  |
  46.      but various add-on libraries, such as the Tk toolkit,  allow  |
  47.      applications to issue commands to each other.  This makes it  |
  48.      possible for applications to  work  together  in  much  more  |
  49.      powerful ways than was previously possible.
  50.  
  51.      This manual page focuses primarily on the Tcl language.   It
  52.      describes the language syntax and the built-in commands that
  53.      will be available in any  application  based  on  Tcl.   The
  54.      individual  library  procedures are described in more detail
  55.      in separate manual pages, one per procedure.
  56.  
  57.  
  58. INTERPRETERS
  59.      The central data structure in Tcl is an interpreter (C  type
  60.      ``Tcl_Interp'').   An  interpreter consists of a set of com-
  61.      mand bindings, a set of variable values,  and  a  few  other
  62.      miscellaneous  pieces  of state.  Each Tcl command is inter-
  63.      preted in the context of  a  particular  interpreter.   Some
  64.      Tcl-based  applications  will maintain multiple interpreters
  65.      simultaneously, each associated with a different  widget  or
  66.      portion  of  the  application.   Interpreters are relatively
  67.      lightweight structures.  They can  be  created  and  deleted
  68.      quickly,  so application programmers should feel free to use
  69.      multiple interpreters if that  simplifies  the  application.
  70.      Eventually Tcl will provide a mechanism for sending Tcl com-
  71.      mands and results back and forth between interpreters,  even
  72.      if the interpreters are managed by different processes.
  73.  
  74.  
  75. DATA TYPES
  76.      Tcl supports only one type of data:  strings.  All commands,
  77.      all  arguments  to  commands,  all  command results, and all
  78.      variable values are strings.  Where commands require numeric
  79.      arguments  or  return  numeric  results,  the  arguments and
  80.      results are passed as strings.  Many commands  expect  their
  81.      string arguments to have certain formats, but this interpre-
  82.      tation is up to the individual commands.  For example, argu-
  83.      ments  often contain Tcl command strings, which may get exe-
  84.      cuted as part of the commands.  The easiest  way  to  under-
  85.      stand  the Tcl interpreter is to remember that everything is
  86.      just an operation on a string.  In many cases Tcl constructs
  87.      will  look  similar to more structured constructs from other
  88.      languages.  However, the Tcl constructs are  not  structured
  89.      at  all; they are just strings of characters, and this gives
  90.      them a different behavior than the structures they may  look
  91.      like.
  92.  
  93.      Although the exact interpretation of a Tcl string depends on
  94.      who  is  doing  the  interpretation,  there are three common
  95.      forms that strings take:  commands, expressions, and  lists.
  96.      The  major  sections below discuss these three forms in more
  97.      detail.
  98.  
  99.  
  100. BASIC COMMAND SYNTAX
  101.      The Tcl language has syntactic similarities to both the Unix
  102.      shells and Lisp.  However, the interpretation of commands is
  103.      different in Tcl than in either of those other two  systems.
  104.      A  Tcl  command  string  consists  of  one  or more commands
  105.      separated by newline characters or semi-colons.   Each  com-
  106.      mand  consists  of a collection of fields separated by white
  107.      space (spaces or tabs).  The first field must be the name of
  108.      a  command, and the additional fields, if any, are arguments
  109.      that will be passed to that command.  For example, the  com-
  110.      mand
  111.  
  112.           set a 22
  113.           
  114.      has three fields:  the first, set, is the name of a Tcl com-
  115.      mand,  and  the  last two, a and 22, will be passed as argu-
  116.      ments to the set command.  The command name may refer either
  117.      to  a  built-in Tcl command, an application-specific command
  118.      bound in with the library procedure Tcl_CreateCommand, or  a
  119.      command  procedure  defined  with the proc built-in command.
  120.      Arguments are passed literally as text strings.   Individual
  121.      commands  may  interpret  those  strings in any fashion they
  122.      wish.  The set command, for example, will  treat  its  first
  123.      argument  as  the name of a variable and its second argument
  124.      as a string value to assign to  that  variable.   For  other
  125.      commands  arguments  may  be interpreted as integers, lists,
  126.      file names, or Tcl commands.
  127.  
  128.      Command names should normally be typed completely  (e.g.  no  |
  129.      abbreviations).   However,  if  the  Tcl  interpreter cannot  |
  130.      locate a command it invokes a special command named  unknown  |
  131.      which  attempts to find or create the command.  For example,  |
  132.      at many sites unknown will  search  through  library  direc-  |
  133.      tories  for  the desired command and create it as a Tcl pro-  |
  134.      cedure if it is found.  The unknown command  often  provides  |
  135.      automatic  completion  of  abbreviated commands, but usually  |
  136.      only for commands that were typed interactively.  It's prob-  |
  137.      ably  a bad idea to use abbreviations in command scripts and  |
  138.      other forms that will be re-used over time:  changes to  the  |
  139.      command  set  may  cause  abbreviations to become ambiguous,  |
  140.      resulting in scripts that no longer work.
  141.  
  142.  
  143. COMMENTS
  144.      If the first non-blank character in a  command  is  #,  then
  145.      everything  from the # up through the next newline character
  146.      is treated as a comment  and  ignored.   When  comments  are
  147.      embedded  inside  nested  commands  (e.g. fields enclosed in
  148.      braces) they must  have  properly-matched  braces  (this  is
  149.      necessary  because  when Tcl parses the top-level command it
  150.      doesn't yet know that the nested field will  be  used  as  a
  151.      command so it cannot process the nested comment character as
  152.      a comment).
  153.  
  154.  
  155. GROUPING ARGUMENTS WITH DOUBLE-QUOTES
  156.      Normally each argument field ends at the next  white  space,
  157.      but  double-quotes  may  be  used  to  create arguments with
  158.      embedded space.  If an argument field begins with a  double-
  159.      quote,  then  the  argument  isn't terminated by white space
  160.      (including newlines) or a semi-colon (see below for informa-
  161.      tion  on  semi-colons);  instead it ends at the next double-
  162.      quote character.  The double-quotes are not included in  the
  163.      resulting argument.  For example, the command
  164.  
  165.           set a "This is a single argument"
  166.           
  167.      will pass two arguments to set:  a  and  This  is  a  single
  168.      argument.    Within  double-quotes,  command  substitutions,
  169.      variable substitutions, and  backslash  substitutions  still
  170.      occur, as described below.  If the first character of a com-
  171.      mand field is not a quote, then quotes  receive  no  special
  172.      interpretation in the parsing of that field.
  173.  
  174.  
  175. GROUPING ARGUMENTS WITH BRACES
  176.      Curly braces may also be used for grouping arguments.   They
  177.      are  similar  to  quotes except for two differences.  First,
  178.      they nest; this makes them easier  to  use  for  complicated
  179.      arguments like nested Tcl command strings.  Second, the sub-
  180.      stitutions described  below  for  commands,  variables,  and
  181.      backslashes do not occur in arguments enclosed in braces, so
  182.      braces can be used to prevent substitutions where  they  are
  183.      undesirable.  If an argument field begins with a left brace,
  184.      then the argument ends at the  matching  right  brace.   Tcl
  185.      will  strip  off  the outermost layer of braces and pass the
  186.      information between the braces to the  command  without  any
  187.      further modification.  For example, in the command
  188.  
  189.           set a {xyz a {b c d}}
  190.           
  191.      the set command will receive two arguments: a and xyz a {b c
  192.      d}.
  193.  
  194.      When braces or quotes are in effect, the matching  brace  or
  195.      quote  need not be on the same line as the starting quote or
  196.      brace; in this case the newline  will  be  included  in  the
  197.      argument  field  along  with  any other characters up to the
  198.      matching brace or quote.   For  example,  the  eval  command
  199.      takes  one argument, which is a command string; eval invokes
  200.      the Tcl interpreter to execute the command string.  The com-
  201.      mand
  202.  
  203.           eval {
  204.                set a 22
  205.                set b 33
  206.           }
  207.           
  208.      will assign the value 22 to a and 33 to b.
  209.  
  210.      If the first character of a command  field  is  not  a  left
  211.      brace,  then neither left nor right braces in the field will
  212.      be treated specially (except as part of  variable  substitu-
  213.      tion; see below).
  214.  
  215.  
  216. COMMAND SUBSTITUTION WITH BRACKETS
  217.      If an open bracket occurs in a field of a command, then com-
  218.      mand  substitution  occurs  (except  for  fields enclosed in
  219.      braces).  All of the text up to the matching  close  bracket
  220.      is  treated as a Tcl command and executed immediately.  Then
  221.      the result of that command is substituted for the  bracketed
  222.      text.  For example, consider the command
  223.  
  224.           set a [set b]
  225.           
  226.      When the set command has only a single argument, it  is  the
  227.      name  of  a  variable  and  set returns the contents of that
  228.      variable.  In this case, if variable b has  the  value  foo,
  229.      then the command above is equivalent to the command
  230.  
  231.           set a foo
  232.           
  233.      Brackets can be used in more complex ways.  For example,  if
  234.      the  variable b has the value foo and the variable c has the
  235.      value gorp, then the command
  236.  
  237.           set a xyz[set b].[set c]
  238.           
  239.      is equivalent to the command
  240.  
  241.           set a xyzfoo.gorp
  242.           
  243.      A bracketed command may contain multiple commands  separated  |
  244.      by  newlines  or  semi-colons in the usual fashion.  In this  |
  245.      case the value of the last command is used for substitution.  |
  246.      For example, the command                                      |
  247.  
  248.           set a x[set b 22                                         |
  249.           expr $b+2]x                                              |
  250.           
  251.      is equivalent to the command                                  |
  252.  
  253.           set a x24x                                               |
  254.           
  255.      If a field is enclosed in braces then the brackets  and  the
  256.      characters  between them are not interpreted specially; they
  257.      are passed through to the argument verbatim.
  258.  
  259.  
  260. VARIABLE SUBSTITUTION WITH $
  261.      The dollar sign ($) may be used as a special shorthand  form
  262.      for  substituting variable values.  If $ appears in an argu-
  263.      ment that isn't enclosed in braces then  variable  substitu-
  264.      tion  will  occur.   The  characters  after the $, up to the
  265.      first character that isn't a number, letter, or  underscore,
  266.      are  taken  as  a variable name and the string value of that
  267.      variable is substituted for the name.  For example, if vari-  |
  268.      able foo has the value test, then the command                 |
  269.  
  270.           set a $foo.c                                             |
  271.           
  272.      is equivalent to the command                                  |
  273.  
  274.           set a test.c                                             |
  275.  
  276.      There are two special forms for variable  substitution.   If  |
  277.      the next character after the name of the variable is an open  |
  278.      parenthesis, then the variable is assumed  to  be  an  array  |
  279.      name, and all of the characters between the open parenthesis  |
  280.      and the next close parenthesis are taken as  an  index  into  |
  281.      the array.  Command substitutions and variable substitutions  |
  282.      are performed on the  information  between  the  parentheses  |
  283.      before it is used as an index.  For example, if the variable  |
  284.      x is an array with one element named first and value 87  and  |
  285.      another element named 14 and value more, then the command     |
  286.  
  287.           set a xyz$x(first)zyx                                    |
  288.           
  289.      is equivalent to the command                                  |
  290.  
  291.           set a xyz87zyx                                           |
  292.           
  293.      If the variable index has the value 14, then the command      |
  294.  
  295.           set a xyz$x($index)zyx                                   |
  296.           
  297.      is equivalent to the command                                  |
  298.  
  299.           set a xyzmorezyx                                         |
  300.           
  301.      For more information on arrays,  see  VARIABLES  AND  ARRAYS  |
  302.      below.                                                        |
  303.  
  304.      The second special form for variables occurs when the dollar  |
  305.      sign  is  followed by an open curly brace.  In this case the  |
  306.      variable name consists of all the characters up to the  next  |
  307.      curly  brace.   Array  references  are  not possible in this  |
  308.      form:  the name between braces is  assumed  to  refer  to  a  |
  309.      scalar variable.  For example, if variable foo has the value  |
  310.      test, then the command                                        |
  311.  
  312.           set a abc${foo}bar                                       |
  313.           
  314.      is equivalent to the command                                  |
  315.  
  316.           set a abctestbar                                         |
  317.           
  318.      Variable substitution does not occur in arguments  that  are
  319.      enclosed  in  braces:  the dollar sign and variable name are
  320.      passed through to the argument verbatim.
  321.  
  322.      The dollar sign abbreviation is simply a shorthand form.  $a
  323.      is  completely  equivalent  to  [set a]; it is provided as a
  324.      convenience to reduce typing.
  325.  
  326.  
  327. SEPARATING COMMANDS WITH SEMI-COLONS
  328.      Normally, each command occupies one  line  (the  command  is
  329.      terminated  by  a  newline  character).  However, semi-colon
  330.      (``;'') is treated as a command separator character;  multi-
  331.      ple  commands  may  be placed on one line by separating them
  332.      with a semi-colon.  Semi-colons are not treated  as  command
  333.      separators  if  they  appear  within curly braces or double-
  334.      quotes.
  335.  
  336.  
  337. BACKSLASH SUBSTITUTION
  338.      Backslashes may be used to  insert  non-printing  characters
  339.      into  command  fields  and also to insert special characters
  340.      like braces and brackets  into  fields  without  them  being
  341.      interpreted  specially  as  described  above.  The backslash
  342.      sequences understood  by  the  Tcl  interpreter  are  listed
  343.      below.   In each case, the backslash sequence is replaced by
  344.      the given character:
  345.  
  346.      \b                  Backspace (0x8).
  347.  
  348.      \f                  Form feed (0xc).
  349.  
  350.      \n                  Newline (0xa).
  351.  
  352.      \r                  Carriage-return (0xd).
  353.  
  354.      \t                  Tab (0x9).
  355.  
  356.      \v                  Vertical tab (0xb).
  357.  
  358.      \{                  Left brace (``{'').
  359.  
  360.      \}                  Right brace (``}'').
  361.  
  362.      \[                  Open bracket (``['').
  363.  
  364.      \]                  Close bracket (``]'').
  365.  
  366.      \$                  Dollar sign (``$'').
  367.  
  368.      \<space>            Space (`` ''): doesn't  terminate  argu-
  369.                          ment.
  370.  
  371.      \;                  Semi-colon: doesn't terminate command.
  372.  
  373.      \"                  Double-quote.
  374.  
  375.      \<newline>          Nothing:  this joins two lines  together
  376.                          into  a  single  line.   This  backslash
  377.                          feature is unique in  that  it  will  be
  378.                          applied  even  when  the sequence occurs
  379.                          within braces.
  380.  
  381.      \\                  Backslash (``\'').
  382.  
  383.      \ddd                The digits ddd (one, two,  or  three  of
  384.                          them)  give the octal value of the char-
  385.                          acter.   Null  characters  may  not   be
  386.                          embedded  in  command  fields; if ddd is
  387.                          zero  then  the  backslash  sequence  is
  388.                          ignored   (i.e.  it  maps  to  an  empty
  389.                          string).
  390.  
  391.      For example, in the command
  392.  
  393.           set a \{x\[\ yz\141
  394.           
  395.      the second argument to set will be ``{x[ yza''.
  396.  
  397.      If a backslash is followed by something other  than  one  of
  398.      the options described above, then the backslash is transmit-
  399.      ted to the argument field without  any  special  processing,
  400.      and  the  Tcl  scanner  continues normal processing with the
  401.      next character.  For example, in the command
  402.  
  403.           set \*a \\\{foo
  404.           
  405.      The first argument to set will be \*a and the  second  argu-
  406.      ment will be \{foo.
  407.  
  408.      If  an  argument  is  enclosed  in  braces,  then  backslash
  409.      sequences inside the argument are parsed but no substitution
  410.      occurs  (except  for  backslash-newline):    the   backslash
  411.      sequence  is  passed  through to the argument as is, without
  412.      making any special interpretation of the characters  in  the
  413.      backslash  sequence.   In particular, backslashed braces are
  414.      not counted in locating the matching right brace  that  ter-
  415.      minates the argument.  For example, in the command
  416.  
  417.           set a {\{abc}
  418.           
  419.      the second argument to set will be \{abc.
  420.  
  421.      This backslash mechanism is not sufficient to generate abso-
  422.      lutely  any argument structure; it only covers the most com-
  423.      mon cases.  To produce particularly complicated arguments it
  424.      is  probably  easiest  to  use the format command along with
  425.      command substitution.
  426.  
  427.  
  428. COMMAND SUMMARY
  429.      [1]  A command is just a string.
  430.  
  431.      [2]  Within a string commands are separated by  newlines  or
  432.           semi-colons (unless the newline or semi-colon is within
  433.           braces or brackets or is backslashed).
  434.  
  435.      [3]  A command consists of fields.  The first field  is  the
  436.           name of the command, and may be abbreviated.  The other
  437.           fields are strings that are passed to that  command  as
  438.           arguments.
  439.  
  440.      [4]  Fields are normally separated by white space.
  441.  
  442.      [5]  Double-quotes allow  white  space  and  semi-colons  to
  443.           appear within a single argument.  Command substitution,
  444.           variable substitution, and backslash substitution still
  445.           occur inside quotes.
  446.  
  447.      [6]  Braces defer interpretation of special characters.   If
  448.           a  field  begins with a left brace, then it consists of
  449.           everything between the  left  brace  and  the  matching
  450.           right  brace. The braces themselves are not included in
  451.           the argument.  No further processing  is  done  on  the
  452.           information  between  the braces except that backslash-
  453.           newline sequences are eliminated.
  454.  
  455.      [7]  If a field doesn't begin with a brace  then  backslash,
  456.           variable,  and  command  substitution  are  done on the
  457.           field.  Only a single level of processing is done:  the
  458.           results  of  one substitution are not scanned again for
  459.           further substitutions or any other  special  treatment.
  460.           Substitution  can  occur  on  any  field  of a command,
  461.           including the command name as well as the arguments.
  462.  
  463.      [8]  If the first non-blank character of a command is  a  #,
  464.           everything  from  the  # up through the next newline is
  465.           treated as a comment and ignored.
  466.  
  467.  
  468. EXPRESSIONS
  469.      The second major interpretation applied to strings in Tcl is  |
  470.      as  expressions.   Several  commands, such as expr, for, and  |
  471.      if, treat one or more of their arguments as expressions  and  |
  472.      call    the   Tcl   expression   processors   (Tcl_ExprLong,  |
  473.      Tcl_ExprBoolean, etc.) to evaluate them.  The operators per-  |
  474.      mitted in Tcl expressions are a subset of the operators per-  |
  475.      mitted in C expressions, and they have the same meaning  and  |
  476.      precedence  as  the  corresponding C operators.  Expressions  |
  477.      almost always yield numeric results  (integer  or  floating-  |
  478.      point values).  For example, the expression                   |
  479.  
  480.           8.2 + 6                        
  481.                                     |
  482.      evaluates to 14.2.  Tcl expressions differ  from  C  expres-  |
  483.      sions  in  the  way that operands are specified, and in that  |
  484.      Tcl expressions support non-numeric operands and string com-  |
  485.      parisons.                                                     |
  486.  
  487.      A Tcl expression consists  of  a  combination  of  operands,  |
  488.      operators, and parentheses.  White space may be used between  |
  489.      the operands and operators and parentheses; it is ignored by  |
  490.      the  expression  processor.   Where  possible,  operands are  |
  491.      interpreted as integer values.  Integer values may be speci-  |
  492.      fied  in  decimal  (the normal case), in octal (if the first  |
  493.      character of the operand is 0), or in  hexadecimal  (if  the  |
  494.      first  two characters of the operand are 0x).  If an operand  |
  495.      does not have one of the integer formats given  above,  then  |
  496.      it  is  treated as a floating-point number if that is possi-  |
  497.      ble.  Floating-point numbers may be specified in any of  the  |
  498.      ways  accepted  by an ANSI-compliant C compiler (except that  |
  499.      the ``f'', ``F'', ``l'', and ``L'' suffixes will not be per-  |
  500.      mitted in most installations).  For example, all of the fol-  |
  501.      lowing are valid  floating-point  numbers:   2.1,  3.,  6e4,  |
  502.      7.91e+16.  If no numeric interpretation is possible, then an  |
  503.      operand is left as a string  (and  only  a  limited  set  of  |
  504.      operators may be applied to it).                              |
  505.  
  506.      Operators may be specified in any of the following ways:      |
  507.  
  508.      [1]                                                                ||
  509.           As an numeric value, either integer or floating-point.   |
  510.  
  511.      [2]                                                                ||
  512.           As  a  Tcl  variable,  using  standard $ notation.  The  |
  513.           variable's value will be used as the operand.            |
  514.  
  515.      [3]                                                                ||
  516.           As  a string enclosed in double-quotes.  The expression  |
  517.           parser will perform backslash,  variable,  and  command  |
  518.           substitutions  on  the  information between the quotes,  |
  519.           and use the resulting value as the operand               |
  520.  
  521.      [4]                                                                ||
  522.           As a string enclosed in braces.  The characters between  |
  523.           the open brace and matching close brace will be used as  |
  524.           the operand without any substitutions.                   |
  525.  
  526.      [5]                                                                ||
  527.           As  a  Tcl  command  enclosed in brackets.  The command  |
  528.           will be executed and its result will  be  used  as  the  |
  529.           operand.                                                 |
  530.  
  531.      [6]                                                                ||
  532.           An unquoted string consisting of any number of letters,  |
  533.           digits, and underscores (but a digit  may  not  be  the  |
  534.           first character).                                        |
  535.  
  536.      Where  substitutions  occur  above   (e.g.   inside   quoted  |
  537.      strings),  they  are  performed by the expression processor.  |
  538.      However, an additional layer  of  substitution  may  already  |
  539.      have been performed by the command parser before the expres-  |
  540.      sion processor was called.  As discussed below, it  is  usu-  |
  541.      ally  best  to  enclose expressions in braces to prevent the  |
  542.      command parser from performing  substitutions  on  the  con-  |
  543.      tents.                                                        |
  544.  
  545.      For some examples of simple expressions, suppose  the  vari-  |
  546.      able  a  has the value 3 and the variable b has the value 6.  |
  547.      Then the expression on the left side of each  of  the  lines  |
  548.      below  will  evaluate  to the value on the right side of the  |
  549.      line:                                                         |
  550.  
  551.           3.1 + $a                6.1                              |
  552.           2 + "$a.$b"             5.6                              |
  553.           4*[length "6 2"]        8                                |
  554.           {word one} < "word $a"  0                                |
  555.  
  556.      The valid operators are listed below, grouped in  decreasing  |
  557.      order of precedence:                                          |
  558.  
  559.      -  ~  !                                                            ||
  560.                          Unary  minus, bit-wise NOT, logical NOT.  |
  561.                          None of these operands may be applied to  |
  562.                          string operands, and bit-wise NOT may be  |
  563.                          applied only to integers.                 |
  564.  
  565.      *  /  %                                                            ||
  566.                          Multiply,  divide,  remainder.   None of  |
  567.                          these operands may be applied to  string  |
  568.                          operands,  and  remainder may be applied  |
  569.                          only to integers.                         |
  570.  
  571.      +  -                                                               ||
  572.                          Add and subtract.  Valid for any numeric  |
  573.                          operands.                                 |
  574.  
  575.      <<  >>                                                             ||
  576.                          Left and right shift.  Valid for integer  |
  577.                          operands only.                            |
  578.  
  579.      <  >  <=  >=                                                       ||
  580.                          Boolean  less,  greater,  less  than  or  |
  581.                          equal, and greater than or equal.   Each  |
  582.                          operator  produces 1 if the condition is  |
  583.                          true, 0 otherwise.  These operators  may  |
  584.                          be applied to strings as well as numeric  |
  585.                          operands,  in  which  case  string  com-  |
  586.                          parison is used.                          |
  587.  
  588.      ==  !=                                                             ||
  589.                          Boolean   equal  and  not  equal.   Each  |
  590.                          operator  produces  a  zero/one  result.  |
  591.                          Valid for all operand types.              |
  592.  
  593.      &                                                                  ||
  594.                          Bit-wise   AND.    Valid   for   integer  |
  595.                          operands only.                            |
  596.  
  597.      ^                                                                  ||
  598.                          Bit-wise   exclusive   OR.    Valid  for  |
  599.                          integer operands only.                    |
  600.  
  601.      |                                                                  ||
  602.                          Bit-wise OR.  Valid for integer operands  |
  603.                          only.                                     |
  604.  
  605.      &&                                                                 ||
  606.                          Logical  AND.   Produces  a  1 result if  |
  607.                          both operands are non-zero, 0 otherwise.  |
  608.                          Valid    for   numeric   operands   only  |
  609.                          (integers or floating-point).             |
  610.  
  611.      ||                                                                 ||
  612.                          Logical OR.  Produces a 0 result if both  |
  613.                          operands are zero, 1  otherwise.   Valid  |
  614.                          for  numeric  operands only (integers or  |
  615.                          floating-point).                          |
  616.  
  617.      x?y:z                                                              ||
  618.                          If-then-else,  as  in C.  If x evaluates  |
  619.                          to non-zero,  then  the  result  is  the  |
  620.                          value of y.  Otherwise the result is the  |
  621.                          value of z.  The x operand must  have  a  |
  622.                          numeric value.                            |
  623.  
  624.      See the C manual for more details on the results produced by  |
  625.      each  operator.   All of the binary operators group left-to-  |
  626.      right within the same precedence level.   For  example,  the  |
  627.      expression                                                    |
  628.  
  629.           4*2 < 7                                                  |
  630.           
  631.      evaluates to 0.                                               |
  632.  
  633.      The &&, ||, and ?: operators have ``lazy evaluation'',  just  |
  634.      as in C, which means that operands are not evaluated if they  |
  635.      are not needed to determine the outcome.  For example, in     |
  636.  
  637.           $v ? [a] : [b]                                           |
  638.  
  639.      only one of [a] or [b] will actually be evaluated, depending  |
  640.      on the value of $v.                                           |
  641.  
  642.      All internal computations involving integers are  done  with  |
  643.      the  C  type  long,  and all internal computations involving  |
  644.      floating-point are done with the C type double.   When  con-  |
  645.      verting  a  string  to  floating-point, exponent overflow is  |
  646.      detected and results in a  Tcl  error.   For  conversion  to  |
  647.      integer  from  string,  detection of overflow depends on the  |
  648.      behavior of some routines in the  local  C  library,  so  it  |
  649.      should be regarded as unreliable.  In any case, overflow and  |
  650.      underflow are generally not detected reliably for intermedi-  |
  651.      ate results.                                                  |
  652.  
  653.      Conversion  among  internal  representations  for   integer,  |
  654.      floating-point, and string operands is done automatically as  |
  655.      needed.  For  arithmetic  computations,  integers  are  used  |
  656.      until  some floating-point number is introduced, after which  |
  657.      floating-point is used.  For example,                         |
  658.  
  659.           5 / 4                                                    |
  660.           
  661.      yields the result 1, while                                    |
  662.  
  663.           5 / 4.0                                                  |
  664.           5 / ( [length "abcd" chars] + 0.0 )                      |
  665.           
  666.      both yield the result 1.25.                                   |
  667.  
  668.      String values may be used  as  operands  of  the  comparison  |
  669.      operators,  although  the  expression  evaluator tries to do  |
  670.      comparisons as integer or floating-point when  it  can.   If  |
  671.      one  of  the  operands  of  a comparison is a string and the  |
  672.      other has a numeric value, the numeric operand is  converted  |
  673.      back to a string using the C sprintf format specifier %d for  |
  674.      integers and %g for floating-point values.  For example, the  |
  675.      expressions                                                   |
  676.  
  677.           "0x03" > "2"                                             |
  678.           "0y" < "0x12"                                            |
  679.           
  680.      both evaluate to 1.  The  first  comparison  is  done  using  |
  681.      integer comparison, and the second is done using string com-  |
  682.      parison after the second operand is converted to the  string  |
  683.      ``18''.
  684.  
  685.      In general it is safest to enclose an expression  in  braces
  686.      when entering it in a command:  otherwise, if the expression
  687.      contains any white space then the Tcl interpreter will split
  688.      it among several arguments.  For example, the command
  689.  
  690.           expr $a + $b
  691.           
  692.      results in three arguments being passed to expr:  $a, +, and
  693.      $b.  In addition, if the expression isn't in braces then the
  694.      Tcl interpreter will perform variable and command  substitu-
  695.      tion  immediately  (it  will  happen  in  the command parser
  696.      rather than in the expression parser).  In  many  cases  the
  697.      expression  is  being passed to a command that will evaluate
  698.      the expression later (or even many times  if,  for  example,
  699.      the expression is to be used to decide when to exit a loop).
  700.      Usually the desired goal is to re-do the variable or command
  701.      substitutions  each time the expression is evaluated, rather
  702.      than once and for all at the beginning.   For  example,  the
  703.      command
  704.  
  705.           for {set i 1} $i<=10 {incr i} {...}       *** WRONG ***
  706.           
  707.      is probably intended to iterate over all values of i from  1
  708.      to  10.   After  each iteration of the body of the loop, for
  709.      will pass its second argument to the expression evaluator to
  710.      see  whether  or not to continue processing.  Unfortunately,
  711.      in this case the value of i in the second argument  will  be
  712.      substituted once and for all when the for command is parsed.
  713.      If i was 0 before the for command  was  invoked  then  for's
  714.      second  argument will be 0<=10 which will always evaluate to
  715.      1, even though i's value eventually becomes greater than 10.
  716.      In  the  above case the loop will never terminate.  Instead,
  717.      the expression should be placed in braces:
  718.  
  719.           for {set i 1} {$i<=10} {incr i} {...}     *** RIGHT ***
  720.           
  721.      This causes the substitution of i's value to be delayed;  it
  722.      will be re-done each time the expression is evaluated, which
  723.      is the desired result.
  724.  
  725.  
  726. LISTS
  727.      The third major way that strings are interpreted in  Tcl  is
  728.      as  lists.   A list is just a string with a list-like struc-
  729.      ture consisting of fields separated  by  white  space.   For
  730.      example, the string
  731.  
  732.           Al Sue Anne John
  733.           
  734.      is a list with four elements or fields.  Lists have the same
  735.      basic  structure  as  command strings, except that a newline
  736.      character in a list is treated as  a  field  separator  just
  737.      like  space  or  tab.  Conventions for braces and quotes and
  738.      backslashes are the same for lists  as  for  commands.   For
  739.      example, the string
  740.  
  741.           a b\ c {d e {f g h}}
  742.           
  743.      is a list with three elements:  a, b c, and d  e  {f  g  h}.
  744.      Whenever an element is extracted from a list, the same rules
  745.      about braces and quotes and backslashes are applied  as  for
  746.      commands.   Thus in the example above when the third element
  747.      is extracted from the list, the result is
  748.  
  749.           d e {f g h}
  750.           
  751.      (when the field was extracted,  all  that  happened  was  to
  752.      strip off the outermost layer of braces).  Command substitu-
  753.      tion and variable substitution are never made on a list  (at
  754.      least,  not  by  the  list-processing commands; the list can
  755.      always be passed to the Tcl interpreter for evaluation).
  756.  
  757.      The Tcl commands concat, foreach, lappend, lindex,  linsert,  |
  758.      list,  llength,  lrange,  lreplace, lsearch, and lsort allow  |
  759.      you to build lists, extract elements from them, search them,
  760.      and perform other list-related functions.
  761.  
  762.  
  763. REGULAR EXPRESSIONS
  764.      Tcl provides two commands that support string matching using  |
  765.      egrep-style regular expressions: regexp and regsub.  Regular  |
  766.      expressions are implemented using Henry  Spencer's  package,  |
  767.      and  the  description of regular expressions below is copied  |
  768.      verbatim from his manual entry.                               |
  769.  
  770.      A regular expression is zero or more branches, separated  by  |
  771.      ``|''.    It  matches  anything  that  matches  one  of  the  |
  772.      branches.                                                     |
  773.  
  774.      A branch is zero or more pieces, concatenated.  It matches a  |
  775.      match  for  the  first,  followed by a match for the second,  |
  776.      etc.                                                          |
  777.  
  778.      A piece is an atom possibly followed  by  ``*'',  ``+'',  or  |
  779.      ``?''.  An atom followed by ``*'' matches a sequence of 0 or  |
  780.      more matches of the atom.  An atom followed by ``+'' matches  |
  781.      a  sequence  of 1 or more matches of the atom.  An atom fol-  |
  782.      lowed by ``?'' matches a match of  the  atom,  or  the  null  |
  783.      string.                                                       |
  784.  
  785.      An atom is a regular expression in parentheses  (matching  a  |
  786.      match  for  the  regular  expression),  a range (see below),  |
  787.      ``.'' (matching any single character), ``^''  (matching  the  |
  788.      null  string  at  the  beginning of the input string), ``$''  |
  789.      (matching the null string at the end of the input string), a  |
  790.      ``\''  followed by a single character (matching that charac-  |
  791.      ter), or a  single  character  with  no  other  significance  |
  792.      (matching that character).                                    |
  793.  
  794.      A range is a sequence of characters enclosed in ``[]''.   It  |
  795.      normally matches any single character from the sequence.  If  |
  796.      the sequence begins with ``^'', it matches any single  char-  |
  797.      acter  not from the rest of the sequence.  If two characters  |
  798.      in the sequence are separated by ``-'',  this  is  shorthand  |
  799.      for  the  full  list  of ASCII characters between them (e.g.  |
  800.      ``[0-9]'' matches any decimal digit).  To include a  literal  |
  801.      ``]''  in the sequence, make it the first character (follow-  |
  802.      ing a possible ``^'').  To include a literal ``-'', make  it  |
  803.      the first or last character.                                  |
  804.  
  805.      If a regular expression could match two different parts of a  |
  806.      string,  it  will  match  the one which begins earliest.  If  |
  807.      both begin in the same place but match different lengths, or  |
  808.      match  the same length in different ways, life gets messier,  |
  809.      as follows.                                                   |
  810.  
  811.      In general, the possibilities in a list of branches are con-  |
  812.      sidered in left-to-right order, the possibilities for ``*'',  |
  813.      ``+'', and ``?'' are considered longest-first,  nested  con-  |
  814.      structs  are  considered  from  the  outermost  in, and con-  |
  815.      catenated constructs  are  considered  leftmost-first.   The  |
  816.      match  that will be chosen is the one that uses the earliest  |
  817.      possibility in the first choice that has  to  be  made.   If  |
  818.      there  is more than one choice, the next will be made in the  |
  819.      same manner (earliest possibility) subject to  the  decision  |
  820.      on the first choice.  And so forth.                           |
  821.  
  822.      For example, ``(ab|a)b*c'' could match ``abc'' in one of two  |
  823.      ways.   The  first choice is between ``ab'' and ``a''; since  |
  824.      ``ab'' is earlier, and does lead  to  a  successful  overall  |
  825.      match, it is chosen.  Since the ``b'' is already spoken for,  |
  826.      the  ``b*''  must  match  its  last  possibility-the   empty  |
  827.      string-since it must respect the earlier choice.              |
  828.  
  829.      In the particular case where no ``|''s are present and there  |
  830.      is  only  one ``*'', ``+'', or ``?'', the net effect is that  |
  831.      the longest possible match  will  be  chosen.   So  ``ab*'',  |
  832.      presented with ``xabbbby'', will match ``abbbb''.  Note that  |
  833.      if ``ab*'' is tried against  ``xabyabbbz'',  it  will  match  |
  834.      ``ab''  just  after  ``x'', due to the begins-earliest rule.  |
  835.      (In effect, the decision on where to start the match is  the  |
  836.      first  choice  to  be  made,  hence  subsequent choices must  |
  837.      respect it even if this leads them to less-preferred  alter-  |
  838.      natives.)
  839.  
  840.  
  841. COMMAND RESULTS
  842.      Each command produces two results:  a  code  and  a  string.
  843.      The  code  indicates  whether the command completed success-
  844.      fully or not, and the string gives  additional  information.
  845.      The valid codes are defined in tcl.h, and are:
  846.  
  847.           TCL_OK              This is the normal return code, and
  848.                               indicates  that  the  command  com-
  849.                               pleted  successfully.   The  string
  850.                               gives the command's return value.
  851.  
  852.           TCL_ERROR           Indicates that an  error  occurred;
  853.                               the string gives a message describ-
  854.                               ing the  error.   In  additon,  the  |
  855.                               global variable errorInfo will con-  |
  856.                               tain   human-readable   information  |
  857.                               describing  which commands and pro-  |
  858.                               cedures were  being  executed  when  |
  859.                               the  error occurred, and the global  |
  860.                               variable  errorCode  will   contain  |
  861.                               machine-readable  details about the  |
  862.                               error, if they are available.   See  |
  863.                               the   section   BUILT-IN  VARIABLES  |
  864.                               below for more information.
  865.  
  866.           TCL_RETURN          Indicates that the  return  command
  867.                               has  been  invoked,  and  that  the
  868.                               current  procedure  (or   top-level
  869.                               command  or  source command) should
  870.                               return  immediately.   The   string
  871.                               gives the return value for the pro-
  872.                               cedure or command.
  873.  
  874.           TCL_BREAK           Indicates that  the  break  command
  875.                               has  been invoked, so the innermost
  876.                               loop should abort immediately.  The
  877.                               string should always be empty.
  878.  
  879.           TCL_CONTINUE        Indicates that the continue command
  880.                               has  been invoked, so the innermost
  881.                               loop  should  go  on  to  the  next
  882.                               iteration.    The   string   should
  883.                               always be empty.
  884.                               
  885.      Tcl programmers do not normally need to think  about  return
  886.      codes,  since TCL_OK is almost always returned.  If anything
  887.      else is returned by a  command,  then  the  Tcl  interpreter
  888.      immediately  stops  processing  commands  and returns to its
  889.      caller.  If there are several nested invocations of the  Tcl
  890.      interpreter  in progress, then each nested command will usu-
  891.      ally return the error to its caller,  until  eventually  the
  892.      error  is  reported  to the top-level application code.  The
  893.      application will then display  the  error  message  for  the
  894.      user.
  895.  
  896.      In a few cases, some commands will handle certain  ``error''
  897.      conditions  themselves  and  not  return  them upwards.  For
  898.      example, the for command checks for the TCL_BREAK  code;  if
  899.      it occurs, then for stops executing the body of the loop and
  900.      returns TCL_OK to its caller.  The for command also  handles
  901.      TCL_CONTINUE  codes  and  the  procedure interpreter handles
  902.      TCL_RETURN codes.  The catch command allows Tcl programs  to
  903.      catch  errors  and  handle  them  without  aborting  command
  904.      interpretation any further.
  905.  
  906.  
  907. PROCEDURES
  908.      Tcl allows you to extend the command interface  by  defining
  909.      procedures.   A  Tcl  procedure can be invoked just like any
  910.      other Tcl command (it has a name and it receives one or more
  911.      arguments).   The  only  difference is that its body isn't a
  912.      piece of C code linked into the program; it is a string con-
  913.      taining  one  or more other Tcl commands.  See the proc com-
  914.      mand for information on how to define  procedures  and  what
  915.      happens when they are invoked.
  916.  
  917.  
  918. VARIABLES - SCALARS AND ARRAYS
  919.      Tcl allows the definition of variables and the use of  their  |
  920.      values either through $-style variable substitution, the set  |
  921.      command, or a few other mechanisms.  Variables need  not  be  |
  922.      declared:  a new variable will automatically be created each  |
  923.      time a new variable name is used.                             |
  924.  
  925.      Tcl supports two types of variables:  scalars and arrays.  A  |
  926.      scalar  variable  has a single value, whereas an array vari-  |
  927.      able can have any number  of  elements,  each  with  a  name  |
  928.      (called  its  ``index'')  and a value.  Array indexes may be  |
  929.      arbitrary strings; they need not  be  numeric.   Parentheses  |
  930.      are used refer to array elements in Tcl commands.  For exam-  |
  931.      ple, the command                                              |
  932.  
  933.           set x(first) 44                                          |
  934.           
  935.      will modify the element of x whose index is  first  so  that  |
  936.      its  new  value  is 44.  Two-dimensional arrays can be simu-  |
  937.      lated in Tcl by using indexes  that  contain  multiple  con-  |
  938.      catenated values.  For example, the commands                  |
  939.  
  940.           set a(2,3) 1                                             |
  941.           set a(3,6) 2                                             |
  942.           
  943.      set the elements of a whose indexes are 2,3 and 3,6.          |
  944.  
  945.      In general, array elements may be used anywhere in Tcl  that  |
  946.      scalar variables may be used.  If an array is defined with a  |
  947.      particular name, then there may not  be  a  scalar  variable  |
  948.      with  the  same name.  Similarly, if there is a scalar vari-  |
  949.      able with a particular name then it is not possible to  make  |
  950.      array references to the variable.  To convert a scalar vari-  |
  951.      able to an array or vice versa, remove the existing variable  |
  952.      with the unset command.                                       |
  953.  
  954.      The array command provides several features for dealing with  |
  955.      arrays,  such  as  querying the names of all the elements of  |
  956.      the array and searching through the array one element  at  a  |
  957.      time.
  958.  
  959.      Variables may be either global or local.  If a variable name
  960.      is  used  when  a  procedure  isn't  being executed, then it
  961.      automatically refers to a global variable.   Variable  names
  962.      used  within  a  procedure normally refer to local variables
  963.      associated with that invocation  of  the  procedure.   Local
  964.      variables  are deleted whenever a procedure exits.  The glo-
  965.      bal command may be used to request that a name  refer  to  a
  966.      global  variable  for  the duration of the current procedure
  967.      (this is somewhat analogous to extern in C).
  968.  
  969.  
  970. BUILT-IN COMMANDS
  971.      The Tcl library provides the  following  built-in  commands,
  972.      which  will  be  available in any application using Tcl.  In
  973.      addition to these built-in commands, there may be additional
  974.      commands  defined by each application, plus commands defined
  975.      as Tcl  procedures.   In  the  command  syntax  descriptions
  976.      below, words in boldface are literals that you type verbatim
  977.      to Tcl.  Words in italics are meta-symbols;  they  serve  as
  978.      names  for  any  of  a  range  of  values that you can type.
  979.      Optional arguments or groups of arguments are  indicated  by
  980.      enclosing  them in question-marks.  Ellipses (``...'') indi-
  981.      cate that any number of additional arguments  or  groups  of
  982.      arguments  may  appear,  in the same format as the preceding
  983.      argument(s).
  984.  
  985.      append varName value ?value value ...?
  986.           Append all of the value arguments to the current  value  |
  987.           of  variable  varName.  If varName doesn't exist, it is  |
  988.           given a value equal to the  concatenation  of  all  the  |
  989.           value  arguments.   This  command provides an efficient  |
  990.           way to build  up  long  variables  incrementally.   For  |
  991.           example,  ``append  a  $b'' is much more efficient than  |
  992.           ``set a $a$b'' if $a is long.
  993.  
  994.      array option arrayName ?arg arg ...?
  995.           This command performs one of several operations on  the  |
  996.           variable  given  by  arrayName.   ArrayName must be the  |
  997.           name of an existing array variable.  The  option  argu-  |
  998.           ment  determines what action is carried out by the com-  |
  999.           mand.  The legal options  (which  may  be  abbreviated)  |
  1000.           are:                                                     |
  1001.  
  1002.           array anymore arrayName searchId                              ||
  1003.                Returns  1  if there are any more elements left to  |
  1004.                be processed in an array search, 0 if all elements  |
  1005.                have  already  been  returned.  SearchId indicates  |
  1006.                which search on arrayName to check, and must  have  |
  1007.                been  the  return value from a previous invocation  |
  1008.                of array startsearch.  This option is particularly  |
  1009.                useful  if  an  array has an element with an empty  |
  1010.                name,  since   the   return   value   from   array  |
  1011.                nextelement  won't indicate whether the search has  |
  1012.                been completed.                                     |
  1013.  
  1014.           array donesearch arrayName searchId                           ||
  1015.                This  command  terminates an array search and des-  |
  1016.                troys all the state associated with  that  search.  |
  1017.                SearchId  indicates  which  search on arrayName to  |
  1018.                destroy, and must have been the return value  from  |
  1019.                a   previous   invocation  of  array  startsearch.  |
  1020.                Returns an empty string.                            |
  1021.  
  1022.           array names arrayName                                         ||
  1023.                Returns  a list containing the names of all of the  |
  1024.                elements in the array.  If there are  no  elements  |
  1025.                in the array then an empty string is returned.      |
  1026.  
  1027.           array nextelement arrayName searchId                          ||
  1028.                Returns the name of the next element in arrayName,  |
  1029.                or an empty string if all  elements  of  arrayName  |
  1030.                have  already  been  returned in this search.  The  |
  1031.                searchId argument identifies the search, and  must  |
  1032.                have been the return value of an array startsearch  |
  1033.                command.  Warning:  if elements are  added  to  or  |
  1034.                deleted  from  the  array,  then  all searches are  |
  1035.                automatically  terminated   just   as   if   array  |
  1036.                donesearch had been invoked; this will cause array  |
  1037.                nextelement operations to fail for those searches.  |
  1038.  
  1039.           array size arrayName                                          ||
  1040.                Returns a decimal string giving the number of ele-  |
  1041.                ments in the array.                                 |
  1042.  
  1043.           array startsearch arrayName                                   ||
  1044.                This  command  initializes  an  element-by-element  |
  1045.                search through the array given by arrayName,  such  |
  1046.                that  invocations of the array nextelement command  |
  1047.                will return the names of the  individual  elements  |
  1048.                in the array.  When the search has been completed,  |
  1049.                the array donesearch command  should  be  invoked.  |
  1050.                The  return value is a search identifier that must  |
  1051.                be used in array nextelement and array  donesearch  |
  1052.                commands; it allows multiple searches to be under-  |
  1053.                way simultaneously for the same array.
  1054.  
  1055.      break
  1056.           This command may be invoked only inside the body  of  a
  1057.           loop  command  such  as  for  or  foreach or while.  It
  1058.           returns a TCL_BREAK code to signal the  innermost  con-
  1059.           taining loop command to return immediately.
  1060.  
  1061.      case string ?in? patList body ?patList body ...?
  1062.      case string ?in? {patList body ?patList body ...?}
  1063.           Match string against each of the patList  arguments  in
  1064.           order.   If  one  matches,  then evaluate the following
  1065.           body argument by passing  it  recursively  to  the  Tcl
  1066.           interpreter,  and return the result of that evaluation.
  1067.           Each patList argument consists of a single  pattern  or
  1068.           list  of patterns.  Each pattern may contain any of the
  1069.           wild-cards described under string match.  If a  patList
  1070.           argument  is  default,  the  corresponding body will be
  1071.           evaluated if no patList matches string.  If no  patList
  1072.           argument  matches  string and no default is given, then
  1073.           the case command returns an empty string.
  1074.  
  1075.           Two syntaxes are provided.  The first uses  a  separate
  1076.           argument  for  each  of the patterns and commands; this
  1077.           form is convenient if substitutions are desired on some
  1078.           of  the  patterns  or commands.  The second form places  |
  1079.           all of the patterns and commands together into a single  |
  1080.           argument; the argument must have proper list structure,  |
  1081.           with the elements of the list being  the  patterns  and  |
  1082.           commands.   The  second form makes it easy to construct  |
  1083.           multi-line case commands, since the braces  around  the  |
  1084.           whole  list  make it unnecessary to include a backslash  |
  1085.           at the end of each line.  Since the  patList  arguments  |
  1086.           are  in  braces in the second form, no command or vari-  |
  1087.           able substitutions are performed on them;   this  makes  |
  1088.           the  behavior  of  the  second  form different than the  |
  1089.           first form in some cases.                                |
  1090.  
  1091.           Below are some examples of case commands:                |
  1092.  
  1093.                case abc in {a b} {format 1} default {format 2} a* {format 3}
  1094.  
  1095.           will return 3,                                           |
  1096.  
  1097.                case a in {                                         |
  1098.                  {a b} {format 1}                                  |
  1099.                  default {format 2}                                |
  1100.                  a* {format 3}                                     |
  1101.                }                                                   |
  1102.                
  1103.           will return 1, and                                       |
  1104.  
  1105.                case xyz {                                          |
  1106.                  {a b}                                             |
  1107.                    {format 1}                                      |
  1108.                  default                                           |
  1109.                    {format 2}                                      |
  1110.                  a*                                                |
  1111.                    {format 3}                                      |
  1112.                }                                                   |
  1113.                
  1114.           will return 2.
  1115.  
  1116.      catch command ?varName?
  1117.           The catch command may be used to  prevent  errors  from
  1118.           aborting  command  interpretation.  Catch calls the Tcl
  1119.           interpreter recursively to execute command, and  always
  1120.           returns  a  TCL_OK  code, regardless of any errors that
  1121.           might occur while executing command.  The return  value
  1122.           from catch is a decimal string giving the code returned
  1123.           by the Tcl interpreter after executing  command.   This
  1124.           will  be 0 (TCL_OK) if there were no errors in command;
  1125.           otherwise it will have a non-zero  value  corresponding
  1126.           to  one  of the exceptional return codes (see tcl.h for
  1127.           the definitions of code values).  If the varName  argu-
  1128.           ment  is  given,  then it gives the name of a variable;
  1129.           catch will set the value of the variable to the  string
  1130.           returned from command (either a result or an error mes-
  1131.           sage).
  1132.  
  1133.      cd ?dirName?
  1134.           Change the current working directory to dirName, or  to  |
  1135.           the  home  directory (as specified in the HOME environ-  |
  1136.           ment variable) if dirName is  not  given.   If  dirName  |
  1137.           starts  with  a  tilde, then tilde-expansion is done as  |
  1138.           described for Tcl_TildeSubst.  Returns an empty string.  |
  1139.           This command can potentially be disruptive to an appli-  |
  1140.           cation, so it may be removed in some applications.       |
  1141.  
  1142.      close fileId                                                       ||
  1143.           Closes  the  file  given by fileId.  FileId must be the  |
  1144.           return value from a previous  invocation  of  the  open  |
  1145.           command;  after  this  command,  it  should not be used  |
  1146.           anymore.   If  fileId  refers  to  a  command  pipeline  |
  1147.           instead of a file, then close waits for the children to  |
  1148.           complete.  The normal result  of  this  command  is  an  |
  1149.           empty  string,  but  errors  are  returned if there are  |
  1150.           problems in closing the file or waiting for children to  |
  1151.           complete.
  1152.  
  1153.      concat arg ?arg ...?
  1154.           This command treats each argument as a  list  and  con-
  1155.           catenates  them  into  a  single  list.  It permits any
  1156.           number of arguments.  For example, the command
  1157.  
  1158.                concat a b {c d e} {f {g h}}
  1159.                
  1160.           will return
  1161.  
  1162.                a b c d e f {g h}
  1163.                
  1164.           as its result.
  1165.  
  1166.      continue
  1167.           This command may be invoked only inside the body  of  a
  1168.           loop  command  such  as  for  or  foreach or while.  It
  1169.           returns a  TCL_CONTINUE code to  signal  the  innermost
  1170.           containing  loop  command  to skip the remainder of the
  1171.           loop's body but continue with the next iteration of the
  1172.           loop.
  1173.  
  1174.      eof fileId
  1175.           Returns 1 if an end-of-file condition has  occurred  on  |
  1176.           fileId,  0 otherwise.  FileId must have been the return  |
  1177.           value from a previous call to open, or it may be stdin,  |
  1178.           stdout,  or  stderr to refer to one of the standard I/O  |
  1179.           channels.
  1180.  
  1181.      error message ?info? ?code?
  1182.           Returns  a  TCL_ERROR  code,   which   causes   command
  1183.           interpretation to be unwound.  Message is a string that
  1184.           is returned to the application to  indicate  what  went
  1185.           wrong.
  1186.  
  1187.           If the info argument is provided and is  non-empty,  it
  1188.           is  used  to  initialize the global variable errorInfo.
  1189.           errorInfo is used to accumulate a stack trace  of  what
  1190.           was  in progress when an error occurred; as nested com-
  1191.           mands unwind, the Tcl interpreter adds  information  to
  1192.           errorInfo.  If the info argument is present, it is used
  1193.           to initialize errorInfo  and  the  first  increment  of
  1194.           unwind  information will not be added by the Tcl inter-
  1195.           preter.  In other words,  the  command  containing  the
  1196.           error  command  will  not  appear  in errorInfo; in its
  1197.           place will be info.  This feature  is  most  useful  in
  1198.           conjunction  with  the catch command: if a caught error
  1199.           cannot be handled successfully, info  can  be  used  to
  1200.           return  a  stack trace reflecting the original point of
  1201.           occurrence of the error:
  1202.  
  1203.                catch {...} errMsg
  1204.                set savedInfo $errorInfo
  1205.                ...
  1206.                error $errMsg $savedInfo
  1207.  
  1208.           If the code argument is  present,  then  its  value  is  |
  1209.           stored in the errorCode global variable.  This variable  |
  1210.           is intended to hold a machine-readable  description  of  |
  1211.           the error in cases where such information is available;  |
  1212.           see the section BUILT-IN VARIABLES below  for  informa-  |
  1213.           tion  on  the  proper  format for the variable.  If the  |
  1214.           code  argument  is  not  present,  then  errorCode   is  |
  1215.           automatically  reset to ``NONE'' by the Tcl interpreter  |
  1216.           as part of processing the error generated by  the  com-  |
  1217.           mand.
  1218.  
  1219.      eval arg ?arg ...?
  1220.           Eval  takes  one  or  more  arguments,  which  together
  1221.           comprise  a  Tcl command (or collection of Tcl commands
  1222.           separated by newlines in the  usual  way).   Eval  con-
  1223.           catenates  all its arguments in the same fashion as the
  1224.           concat command, passes the concatenated string  to  the
  1225.           Tcl  interpreter recursively, and returns the result of
  1226.           that evaluation (or any error generated by it).
  1227.  
  1228.      exit ?returnCode?                                                  ||
  1229.           Terminate  the  process,  returning  returnCode  to the  |
  1230.           parent as the exit status.  If returnCode isn't  speci-  |
  1231.           fied then it defaults to 0.
  1232.  
  1233.      expr arg
  1234.           Calls the expression processor  to  evaluate  arg,  and
  1235.           returns  the  result  as  a  string.   See  the section
  1236.           EXPRESSIONS above.
  1237.  
  1238.      file option name ?arg arg ...?
  1239.           Operate on a file or a file name.  Name is the name  of  |
  1240.           a file; if it starts with a tilde, then tilde substitu-  |
  1241.           tion is done before  executing  the  command  (see  the  |
  1242.           manual  entry  for Tcl_TildeSubst for details).  Option  |
  1243.           indicates what to do with the file  name.   Any  unique  |
  1244.           abbreviation  for  option  is  acceptable.   The  valid  |
  1245.           options are:                                             |
  1246.  
  1247.           file atime name                                               ||
  1248.                Return  a  decimal string giving the time at which  |
  1249.                file name was last accessed.  The time is measured  |
  1250.                in  the  standard  UNIX  fashion as seconds from a  |
  1251.                fixed starting time (often January 1,  1970).   If  |
  1252.                the  file  doesn't exist or its access time cannot  |
  1253.                be queried then an error is generated.              |
  1254.  
  1255.           file dirname name                                             ||
  1256.                Return all of the characters in name up to but not  |
  1257.                including the last slash character.  If there  are  |
  1258.                no slashes in name then return ``.''.  If the last  |
  1259.                slash in name is its first character, then  return  |
  1260.                ``/''.                                              |
  1261.  
  1262.           file executable name                                          ||
  1263.                Return 1 if file name is executable by the current  |
  1264.                user, 0 otherwise.                                  |
  1265.  
  1266.           file exists name                                              ||
  1267.                Return  1 if file name exists and the current user  |
  1268.                has search privileges for the directories  leading  |
  1269.                to it, 0 otherwise.                                 |
  1270.  
  1271.           file extension name                                           ||
  1272.                Return  all  of  the  characters in name after and  |
  1273.                including the last dot in name.  If  there  is  no  |
  1274.                dot in name then return the empty string.           |
  1275.  
  1276.           file isdirectory name                                         ||
  1277.                Return 1 if file name is a directory, 0 otherwise.  |
  1278.  
  1279.           file isfile name                                              ||
  1280.                Return  1 if file name is a regular file, 0 other-  |
  1281.                wise.                                               |
  1282.  
  1283.           file mtime name                                               ||
  1284.                Return  a  decimal string giving the time at which  |
  1285.                file name was last modified.  The time is measured  |
  1286.                in  the  standard  UNIX  fashion as seconds from a  |
  1287.                fixed starting time (often January 1,  1970).   If  |
  1288.                the file doesn't exist or its modified time cannot  |
  1289.                be queried then an error is generated.              |
  1290.  
  1291.           file owned name                                               ||
  1292.                Return  1  if  file  name  is owned by the current  |
  1293.                user, 0 otherwise.                                  |
  1294.  
  1295.           file readable name                                            ||
  1296.                Return  1  if file name is readable by the current  |
  1297.                user, 0 otherwise.                                  |
  1298.  
  1299.           file rootname name                                            ||
  1300.                Return all of the characters in name up to but not  |
  1301.                including the last ``.'' character  in  the  name.  |
  1302.                If name doesn't contain a dot, then return name.    |
  1303.  
  1304.           file size name                                                ||
  1305.                Return  a  decimal  string giving the size of file  |
  1306.                name in bytes.  If the file doesn't exist  or  its  |
  1307.                size cannot be queried then an error is generated.  |
  1308.  
  1309.           file stat  namevarName                                        ||
  1310.                Invoke  the  stat kernel call on name, and use the  |
  1311.                variable given  by  varName  to  hold  information  |
  1312.                returned from the kernel call.  VarName is treated  |
  1313.                as an array variable, and the  following  elements  |
  1314.                of  that variable are set: atime, ctime, dev, gid,  |
  1315.                ino, mode, mtime, nlink, size, uid.  Each  element  |
  1316.                is   a  decimal  string  with  the  value  of  the  |
  1317.                corresponding field from the  stat  return  struc-  |
  1318.                ture; see the manual entry for stat for details on  |
  1319.                the meanings of the values.  This command  returns  |
  1320.                an empty string.                                    |
  1321.  
  1322.           file tail name                                                ||
  1323.                Return  all  of  the  characters in name after the  |
  1324.                last slash.  If  name  contains  no  slashes  then  |
  1325.                return name.                                        |
  1326.  
  1327.           file writable name                                            ||
  1328.                Return  1  if file name is writable by the current  |
  1329.                user, 0 otherwise.                                  |
  1330.  
  1331.                                                                         ||
  1332.           The  file  commands  that  return 0/1 results are often  |
  1333.           used in conditional or looping commands, for example:    |
  1334.  
  1335.                if {![file exists foo]} then {error {bad file name}} else {...}|
  1336.  
  1337.      flush fileId
  1338.           Flushes any output that has been buffered  for  fileId.  |
  1339.           FileId  must have been the return value from a previous  |
  1340.           call to open, or it may be stdout or stderr  to  access  |
  1341.           one  of  the  standard  I/O streams; it must refer to a  |
  1342.           file that was opened for writing.  This command returns  |
  1343.           an empty string.
  1344.  
  1345.      for start test next body
  1346.           For is a looping command, similar in structure to the C
  1347.           for  statement.   The  start,  next, and body arguments
  1348.           must be Tcl command strings, and test is an  expression
  1349.           string.   The  for command first invokes the Tcl inter-
  1350.           preter to execute start.  Then it repeatedly  evaluates
  1351.           test  as  an  expression;  if the result is non-zero it
  1352.           invokes the Tcl interpreter on body, then  invokes  the
  1353.           Tcl  interpreter  on  next, then repeats the loop.  The
  1354.           command terminates when test evaluates to 0.  If a con-
  1355.           tinue command is invoked within body then any remaining
  1356.           commands in the current execution of body are  skipped;
  1357.           processing continues by invoking the Tcl interpreter on
  1358.           next, then evaluating test, and so on.  If a break com-
  1359.           mand  is invoked within body or next, then the for com-
  1360.           mand will return immediately.  The operation  of  break
  1361.           and  continue  are  similar to the corresponding state-
  1362.           ments in C.  For returns an empty string.
  1363.  
  1364.      foreach varname list body
  1365.           In this command, varname is the  name  of  a  variable,
  1366.           list is a list of values to assign to varname, and body
  1367.           is a collection of Tcl commands.   For  each  field  in
  1368.           list (in order from left to right), foreach assigns the
  1369.           contents of the field to varname (as if the lindex com-
  1370.           mand  had  been  used to extract the field), then calls
  1371.           the Tcl interpreter to execute  body.   The  break  and
  1372.           continue  statements  may  be invoked inside body, with
  1373.           the same effect as in  the  for  command.   Foreach  an
  1374.           empty string.
  1375.  
  1376.      format formatString ?arg arg ...?
  1377.           This command generates a formatted string in  the  same
  1378.           way  as the C sprintf procedure (it uses sprintf in its
  1379.           implementation).  FormatString indicates how to  format
  1380.           the result, using % fields as in sprintf, and the addi-
  1381.           tional arguments, if any, provide values to be  substi-
  1382.           tuted  into the result.  All of the sprintf options are
  1383.           valid; see the sprintf man page for details.  Each  arg
  1384.           must  match  the expected type from the % field in for-
  1385.           matString; the format command converts each argument to
  1386.           the correct type (floating, integer, etc.) before pass-
  1387.           ing it to sprintf for  formatting.   The  only  unusual
  1388.           conversion is for %c; in this case the argument must be
  1389.           a decimal string, which will then be converted  to  the
  1390.           corresponding   ASCII  character  value.   Format  does
  1391.           backslash substitution on its formatString argument, so
  1392.           backslash  sequences  in  formatString  will be handled
  1393.           correctly even if  the  argument  is  in  braces.   The
  1394.           return value from format is the formatted string.
  1395.  
  1396.      gets fileId ?varName?
  1397.           Reads the next line from the file given by  fileId  and  |
  1398.           discards the terminating newline character.  If varName  |
  1399.           is specified, then the line is placed in  the  variable  |
  1400.           by  that  name  and  the return value is a count of the  |
  1401.           number of characters read (not including the  newline).  |
  1402.           If  the  end  of the file is reached before reading any  |
  1403.           characters then -1 is returned and varName is set to an  |
  1404.           empty  string.   If  varName  is not specified then the  |
  1405.           return value will be the line (minus the newline  char-  |
  1406.           acter)  or  an  empty  string if the end of the file is  |
  1407.           reached before reading any characters.  An empty string  |
  1408.           will  also be returned if a line contains no characters  |
  1409.           except the newline, so eof  may  have  to  be  used  to  |
  1410.           determine  what really happened.  If the last character  |
  1411.           in the file is  not  a  newline  character,  then  gets  |
  1412.           behaves  as if there were an additional newline charac-  |
  1413.           ter at the end of the file.  FileId must  be  stdin  or  |
  1414.           the  return value from a previous call to open; it must  |
  1415.           refer to a file that was opened for reading.
  1416.  
  1417.      glob ?-nocomplain? filename ?filename ...?
  1418.           This command  performs  filename  globbing,  using  csh
  1419.           rules.   The  returned  value  from glob is the list of
  1420.           expanded filenames.  If -nocomplain is specified as the  |
  1421.           first  argument  then  an  empty  list may be returned;  |
  1422.           otherwise an error is returned if the expanded list  is  |
  1423.           empty.   The  -nocomplain  argument  must  be  provided  |
  1424.           exactly: an abbreviation will not be accepted.
  1425.  
  1426.      global varname ?varname ...?
  1427.           This command is ignored unless a Tcl procedure is being
  1428.           interpreted.    If  so,  then  it  declares  the  given
  1429.           varname's to be  global  variables  rather  than  local
  1430.           ones.   For  the duration of the current procedure (and
  1431.           only while executing in  the  current  procedure),  any
  1432.           reference  to  any  of  the varnames will be bound to a
  1433.           global variable instead of a local one.
  1434.  
  1435.      history ?option? ?arg arg ...?
  1436.           Note:  this command may not be available  in  all  Tcl-
  1437.           based applications.  Typically, only those that receive
  1438.           command input in a typescript form  will  support  his-
  1439.           tory.   The  history  command  performs  one of several
  1440.           operations  related   to   recently-executed   commands
  1441.           recorded  in  a  history  list.  Each of these recorded
  1442.           commands is referred to as an ``event''.  When specify-
  1443.           ing  an  event  to  the  history command, the following
  1444.           forms may be used:
  1445.  
  1446.           [1]  A number:  if positive, it  refers  to  the  event
  1447.                with that number (all events are numbered starting
  1448.                at 1).  If the number is negative, it  selects  an
  1449.                event  relative to the current event (-1 refers to
  1450.                the previous event, -2 to the one before that, and
  1451.                so on).
  1452.  
  1453.           [2]  A string:  selects  the  most  recent  event  that
  1454.                matches  the  string.   An  event is considered to
  1455.                match the string either if the string is the  same
  1456.                as  the  first  characters of the event, or if the
  1457.                string matches the  event  in  the  sense  of  the
  1458.                string match command.
  1459.  
  1460.           The history command  can  take  any  of  the  following
  1461.           forms:
  1462.  
  1463.           history
  1464.                Same as history info, described below.              |
  1465.  
  1466.           history add command ?exec?
  1467.                Add the command argument to the history list as  a
  1468.                new  event.  If exec is specified (or abbreviated)
  1469.                then the command is also executed and  its  result
  1470.                is  returned.   If  exec  isn't  specified then an
  1471.                empty string is returned as result.
  1472.  
  1473.           history change newValue ?event?
  1474.                Replace the  value  recorded  for  an  event  with
  1475.                newValue.   Event  specifies the event to replace,
  1476.                and defaults to the current event (not event  -1).
  1477.                This  command is intended for use in commands that
  1478.                implement new forms of  history  substitution  and
  1479.                wish  to  replace the current event (which invokes
  1480.                the substitution) with the command created through
  1481.                substitution.    The  return  value  is  an  empty
  1482.                string.
  1483.  
  1484.           history event ?event?
  1485.                Returns the value of the  event  given  by  event.
  1486.                Event defaults to -1.  This command causes history
  1487.                revision to occur: see below for details.
  1488.  
  1489.           history info ?count?
  1490.                Returns a formatted string (intended for humans to
  1491.                read)  giving  the  event  number and contents for
  1492.                each of the events in the history list except  the
  1493.                current  event.   If  count is specified then only
  1494.                the most recent count events are returned.
  1495.  
  1496.           history keep count
  1497.                This command may be used to change the size of the
  1498.                history  list  to  count  events.   Initially,  20
  1499.                events are retained in  the  history  list.   This
  1500.                command returns an empty string.
  1501.  
  1502.           history nextid
  1503.                Returns  the  number  of  the  next  event  to  be
  1504.                recorded  in  the  history list.  It is useful for
  1505.                things like printing the event number in  command-
  1506.                line prompts.
  1507.  
  1508.           history redo ?event?
  1509.                Re-execute the  command  indicated  by  event  and
  1510.                return  its  result.   Event defaults to -1.  This
  1511.                command results in history  revision:   see  below
  1512.                for details.
  1513.  
  1514.           history substitute old new ?event?
  1515.                Retrieve  the  command  given  by  event  (-1   by
  1516.                default), replace any occurrences of old by new in
  1517.                the command (only  simple  character  equality  is
  1518.                supported;  no  wild cards), execute the resulting
  1519.                command, and return the result of that  execution.
  1520.                This  command  results  in  history revision:  see
  1521.                below for details.
  1522.  
  1523.           history words selector ?event?
  1524.                Retrieve from the command given by  event  (-1  by
  1525.                default)  the  words given by selector, and return
  1526.                those words in a string separated by spaces.   The
  1527.                selector  argument  has  three  forms.  If it is a
  1528.                single number then it selects the  word  given  by
  1529.                that  number  (0  for  the command name, 1 for its
  1530.                first argument, and so on).  If it consists of two
  1531.                numbers  separated  by a dash, then it selects all
  1532.                the arguments between those two.  Otherwise selec-
  1533.                tor  is  treated  as a pattern; all words matching
  1534.                that pattern (in the sense of  string  match)  are
  1535.                returned.   In  the numeric forms $ may be used to
  1536.                select the last word of a command.   For  example,
  1537.                suppose  the  most  recent  command in the history
  1538.                list is
  1539.  
  1540.                     format  {%s is %d years old} Alice [expr $ageInMonths/12]
  1541.                     
  1542.                Below are some history commands  and  the  results
  1543.                they would produce:
  1544.  
  1545.                     Command                Result
  1546.  
  1547.                     history words $        [expr $ageInMonths/12]
  1548.                     history words 1-2      {%s is %d years  old} Alice
  1549.                     history words *a*o*    {%s is %d years old} [expr $ageInMonths/12]
  1550.                     
  1551.                History words results in  history  revision:   see
  1552.                below for details.
  1553.                
  1554.           The history options event, redo, substitute, and  words
  1555.           result  in  ``history  revision''.   When  one of these
  1556.           options is invoked then the current event  is  modified
  1557.           to  eliminate  the  history command and replace it with
  1558.           the result of the history command.  For  example,  sup-
  1559.           pose  that  the most recent command in the history list
  1560.           is
  1561.  
  1562.                set a [expr $b+2]
  1563.                
  1564.           and suppose that the next command invoked is one of the
  1565.           ones  on the left side of the table below.  The command
  1566.           actually recorded in the  history  event  will  be  the
  1567.           corresponding one on the right side of the table.
  1568.  
  1569.                Command Typed           Command Recorded
  1570.  
  1571.                history                 set a [expr $b+2]
  1572.                history s a b           set b [expr $b+2]
  1573.                set c [history w 2]     set c [expr $b+2]
  1574.                
  1575.           History revision is  needed  because  event  specifiers  |
  1576.           like -1 are only valid at a particular time:  once more  |
  1577.           events have been added to the history list a  different  |
  1578.           event  specifier  would  be  needed.   History revision  |
  1579.           occurs even when history is invoked indirectly from the  |
  1580.           current event (e.g. a user types a command that invokes  |
  1581.           a Tcl procedure that invokes history):   the  top-level  |
  1582.           command  whose  execution eventually resulted in a his-  |
  1583.           tory command is replaced.  If you wish to  invoke  com-  |
  1584.           mands  like history words without history revision, you  |
  1585.           can use history event to save the current history event  |
  1586.           and then use history change to restore it later.
  1587.  
  1588.      if test ?then? trueBody ?else? ?falseBody?
  1589.           The if command evaluates test as an expression (in  the
  1590.           same  way that expr evaluates its argument).  The value
  1591.           of the expression must be numeric; if  it  is  non-zero
  1592.           then trueBody is called by passing it to the Tcl inter-
  1593.           preter.  Otherwise falseBody is executed by passing  it
  1594.           to  the  Tcl  interpreter.  The then and else arguments
  1595.           are optional ``noise words'' to make the command easier
  1596.           to  read.   FalseBody  is  also  optional;  if it isn't
  1597.           specified then the command does nothing if test  evalu-
  1598.           ates to zero.  The return value from if is the value of
  1599.           the last command executed in trueBody or falseBody,  or
  1600.           the  empty  string if test evaluates to zero and false-
  1601.           Body isn't specified.
  1602.  
  1603.      incr varName ?increment?
  1604.           Increment the value stored in the variable  whose  name  |
  1605.           is   varName.   The  value  of  the  variable  must  be  |
  1606.           integral.  If increment  is  supplied  then  its  value  |
  1607.           (which  must  be  an  integer) is added to the value of  |
  1608.           variable varName;  otherwise 1  is  added  to  varName.  |
  1609.           The new value is stored as a decimal string in variable  |
  1610.           varName and also returned as result.
  1611.  
  1612.      info option ?arg arg ...?
  1613.           Provide information about various internals to the  Tcl
  1614.           interpreter.  The legal option's (which may be abbrevi-
  1615.           ated) are:
  1616.  
  1617.           info args procname
  1618.                Returns a list containing the names of  the  argu-
  1619.                ments  to  procedure procname, in order.  Procname
  1620.                must be the name of a Tcl command procedure.
  1621.  
  1622.           info body procname
  1623.                Returns the body of procedure procname.   Procname
  1624.                must be the name of a Tcl command procedure.
  1625.  
  1626.           info cmdcount
  1627.                Returns a count of the total  number  of  commands
  1628.                that have been invoked in this interpreter.
  1629.  
  1630.           info commands ?pattern?
  1631.                If pattern isn't  specified,  returns  a  list  of
  1632.                names  of all the Tcl commands, including both the
  1633.                built-in commands written in  C  and  the  command
  1634.                procedures  defined  using  the  proc command.  If
  1635.                pattern is specified, only  those  names  matching
  1636.                pattern  are  returned.   Matching  is  determined
  1637.                using the same rules as for string match.
  1638.  
  1639.           info default procname arg varname
  1640.                Procname must be the name of a  Tcl  command  pro-
  1641.                cedure  and arg must be the name of an argument to
  1642.                that procedure.  If arg  doesn't  have  a  default
  1643.                value  then  the  command returns 0.  Otherwise it
  1644.                returns 1 and places the default value of arg into
  1645.                variable varname.
  1646.  
  1647.           info exists varName
  1648.                Returns 1 if the variable named varName exists  in
  1649.                the  current  context (either as a global or local
  1650.                variable), returns 0 otherwise.
  1651.  
  1652.           info globals ?pattern?
  1653.                If pattern isn't specified, returns a list of  all
  1654.                the  names  of currently-defined global variables.
  1655.                If pattern is specified, only those names matching
  1656.                pattern  are  returned.   Matching  is  determined
  1657.                using the same rules as for string match.
  1658.  
  1659.           info level ?number?
  1660.                If number is not specified, this command returns a
  1661.                number giving the stack level of the invoking pro-
  1662.                cedure, or 0 if the command  is  invoked  at  top-
  1663.                level.  If number is specified, then the result is
  1664.                a list consisting of the name  and  arguments  for
  1665.                the  procedure  call at level number on the stack.
  1666.                If number is positive then it selects a particular
  1667.                stack  level (1 refers to the top-most active pro-
  1668.                cedure, 2 to the procedure it called, and so  on);
  1669.                otherwise it gives a level relative to the current
  1670.                level (0 refers to the current  procedure,  -1  to
  1671.                its  caller,  and so on).  See the uplevel command
  1672.                for more information on what stack levels mean.
  1673.  
  1674.           info library
  1675.                Returns the name of the library directory in which  |
  1676.                standard  Tcl  scripts are stored.  If there is no  |
  1677.                such directory defined for the  current  installa-  |
  1678.                tion  then an error is generated.  See the library  |
  1679.                manual entry for details of  the  facilities  pro-  |
  1680.                vided  by  the  Tcl script library.  Normally each  |
  1681.                application will have its own application-specific  |
  1682.                script  library  in  addition  to  the  Tcl script  |
  1683.                library;  I suggest that each  application  set  a  |
  1684.                global  variable  with  a  name  like  $appLibrary  |
  1685.                (where app is the application's name) to hold  the  |
  1686.                location of that application's library directory.
  1687.  
  1688.           info locals ?pattern?
  1689.                If pattern isn't specified, returns a list of  all
  1690.                the  names  of  currently-defined local variables,
  1691.                including arguments to the current  procedure,  if
  1692.                any.   Variables defined with the global and upvar  |
  1693.                commands will not  be  returned.   If  pattern  is
  1694.                specified,  only  those names matching pattern are
  1695.                returned.  Matching is determined using  the  same
  1696.                rules as for string match.
  1697.  
  1698.           info procs ?pattern?
  1699.                If pattern isn't specified, returns a list of  all
  1700.                the  names  of Tcl command procedures.  If pattern
  1701.                is specified, only those  names  matching  pattern
  1702.                are  returned.   Matching  is determined using the
  1703.                same rules as for string match.
  1704.  
  1705.           info script
  1706.                If a Tcl script file is currently being  evaluated  |
  1707.                (i.e.  there  is  a call to Tcl_EvalFile active or  |
  1708.                there is an active invocation of the  source  com-  |
  1709.                mand),  then  this command returns the name of the  |
  1710.                innermost file  being  processed.   Otherwise  the  |
  1711.                command returns an empty string.
  1712.  
  1713.           info tclversion
  1714.                Returns the version number for this version of Tcl
  1715.                in  the  form  x.y,  where  changes to x represent
  1716.                major changes with probable incompatibilities  and
  1717.                changes  to y represent small enhancements and bug
  1718.                fixes that retain backward compatibility.
  1719.  
  1720.           info vars ?pattern?
  1721.                If pattern isn't specified, returns a list of  all
  1722.                the  names of currently-visible variables, includ-
  1723.                ing both locals and currently-visible globals.  If
  1724.                pattern  is  specified,  only those names matching
  1725.                pattern  are  returned.   Matching  is  determined
  1726.                using the same rules as for string match.
  1727.  
  1728.      join list ?joinString?
  1729.           The list argument must be a valid Tcl list.  This  com-  |
  1730.           mand  returns  the  string formed by joining all of the  |
  1731.           elements of list together  with  joinString  separating  |
  1732.           each  adjacent  pair of elements.  The joinString argu-  |
  1733.           ment defaults to a space character.
  1734.  
  1735.      lappend varName value ?value value ...?
  1736.           Treat the variable given  by  varName  as  a  list  and  |
  1737.           append  each  of  the value arguments to that list as a  |
  1738.           separate element, with  spaces  between  elements.   If  |
  1739.           varName  doesn't  exist,  it  is created as a list with  |
  1740.           elements given by  the  value  arguments.   Lappend  is  |
  1741.           similar  to  append except that the values are appended  |
  1742.           as list elements rather than raw  text.   This  command  |
  1743.           provides  a  relatively efficient way to build up large  |
  1744.           lists.  For example, ``lappend  a  $b''  is  much  more  |
  1745.           efficient  than ``set a [concat $a [list $b]]'' when $a  |
  1746.           is long.                                                 |
  1747.  
  1748.      lindex list index                                                  ||
  1749.           Treats list as a Tcl list and returns the index'th ele-  |
  1750.           ment from it (0 refers to  the  first  element  of  the  |
  1751.           list).   In extracting the element, lindex observes the  |
  1752.           same rules concerning braces and quotes and backslashes  |
  1753.           as  the Tcl command interpreter; however, variable sub-  |
  1754.           stitution and command substitution do  not  occur.   If  |
  1755.           index  is  negative  or  greater  than  or equal to the  |
  1756.           number of elements in value, then an  empty  string  is  |
  1757.           returned.                                                |
  1758.  
  1759.      linsert list index element ?element element ...?                   ||
  1760.           This command produces a new list from list by inserting  |
  1761.           all of the element arguments just  before  the  indexth  |
  1762.           element  of  list.  Each element argument will become a  |
  1763.           separate element of the new list.   If  index  is  less  |
  1764.           than  or  equal  to  zero,  then  the  new elements are  |
  1765.           inserted at the beginning of the  list.   If  index  is  |
  1766.           greater  than or equal to the number of elements in the  |
  1767.           list, then the new elements are appended to the list.
  1768.  
  1769.      list arg ?arg ...?
  1770.           This command returns a list comprised of all the  args.
  1771.           Braces  and backslashes get added as necessary, so that
  1772.           the index command may be used  on  the  result  to  re-
  1773.           extract  the  original arguments, and also so that eval
  1774.           may be used to execute the resulting  list,  with  arg1
  1775.           comprising  the  command's  name  and  the  other  args
  1776.           comprising its arguments.  List produces slightly  dif-
  1777.           ferent  results  than concat:  concat removes one level
  1778.           of grouping before forming the list, while  list  works
  1779.           directly from the original arguments.  For example, the
  1780.           command
  1781.  
  1782.                list a b {c d e} {f {g h}}
  1783.                
  1784.           will return
  1785.  
  1786.                a b {c d e} {f {g h}}
  1787.  
  1788.           while concat with the same arguments will return
  1789.  
  1790.                a b c d e f {g h}
  1791.  
  1792.      llength list                                                       ||
  1793.           Treats list as a list and returns a decimal string giv-  |
  1794.           ing the number of elements in it.                        |
  1795.  
  1796.      lrange list first last                                             ||
  1797.           List  must  be  a  valid  Tcl  list.  This command will  |
  1798.           return a new list consisting of elements first  through  |
  1799.           last,  inclusive.  Last may be end (or any abbreviation  |
  1800.           of it) to refer to the last element of  the  list.   If  |
  1801.           first  is  less  than zero, it is treated as if it were  |
  1802.           zero.  If last is greater than or equal to  the  number  |
  1803.           of  elements  in  the list, then it is treated as if it  |
  1804.           were end.  If first is greater than last then an  empty  |
  1805.           string  is returned.  Note: ``lrange list first first''  |
  1806.           does not always produce the  same  result  as  ``lindex  |
  1807.           list  first'' (although it often does for simple fields  |
  1808.           that aren't enclosed in braces); it does, however, pro-  |
  1809.           duce  exactly  the  same results as ``list [lindex list  |
  1810.           first]''                                                 |
  1811.  
  1812.      lreplace list first last ?element element ...?                     ||
  1813.           Returns a new list formed by replacing one or more ele-  |
  1814.           ments of list with the element arguments.  First  gives  |
  1815.           the  index in list of the first element to be replaced.  |
  1816.           If first is less than zero then it refers to the  first  |
  1817.           element  of  list;  the element indicated by first must  |
  1818.           exist in the list.  Last gives the index in list of the  |
  1819.           last  element  to be replaced;  it must be greater than  |
  1820.           or equal to first.  Last may be end (or  any  abbrevia-  |
  1821.           tion of it) to indicate that all elements between first  |
  1822.           and the end of the list should be replaced.   The  ele-  |
  1823.           ment arguments specify zero or more new arguments to be  |
  1824.           added to the list in place of those that were  deleted.  |
  1825.           Each element argument will become a separate element of  |
  1826.           the list.  If no element arguments are specified,  then  |
  1827.           the elements between first and last are simply deleted.  |
  1828.  
  1829.      lsearch list pattern                                               ||
  1830.           Search  the  elements  of  list  to  see if one of them  |
  1831.           matches pattern.  If so, the command returns the  index  |
  1832.           of  the  first  matching  element.  If not, the command  |
  1833.           returns -1.  Pattern matching is done in the  same  way  |
  1834.           as for the string match command.                         |
  1835.  
  1836.      lsort list                                                         ||
  1837.           Sort  the  elements  of  list,  returning a new list in  |
  1838.           sorted order.  ASCII sorting is used, with  the  result  |
  1839.           in increasing order.
  1840.  
  1841.      open fileName ?access?
  1842.           Opens a file and returns an identifier that may be used  |
  1843.           in future invocations of commands like read, write, and  |
  1844.           close.  FileName gives the name of the file to open; if  |
  1845.           it  starts with a tilde then tilde substitution is per-  |
  1846.           formed as described for Tcl_TildeSubst.  If  the  first  |
  1847.           character of fileName is ``|'' then the remaining char-  |
  1848.           acters of fileName are treated as a command pipeline to  |
  1849.           invoke,  in  the same style as for exec.  In this case,  |
  1850.           the identifier returned by open may be used to write to  |
  1851.           the  command's input pipe or read from its output pipe.  |
  1852.           The access argument indicates the way in which the file  |
  1853.           (or  command  pipeline) is to be accessed.  It may have  |
  1854.           any of the following values:                             |
  1855.  
  1856.           r                                                             ||
  1857.                Open  the  file  for  reading  only; the file must  |
  1858.                already exist.                                      |
  1859.  
  1860.           r+                                                            ||
  1861.                Open  the  file  for both reading and writing; the  |
  1862.                file must already exist.                            |
  1863.  
  1864.           w                                                             ||
  1865.                Open the file for writing only.  Truncate it if it  |
  1866.                exists.  If it doesn't exist, create a new file.    |
  1867.  
  1868.           w+                                                            ||
  1869.                Open  the  file for reading and writing.  Truncate  |
  1870.                it if it exists.  If it doesn't  exist,  create  a  |
  1871.                new file.                                           |
  1872.  
  1873.           a                                                             ||
  1874.                Open  the  file  for  writing only.  The file must  |
  1875.                already exist, and the file is positioned so  that  |
  1876.                new data is appended to the file.                   |
  1877.  
  1878.           a+                                                            ||
  1879.                Open  the  file for reading and writing.  The file  |
  1880.                must already exist, and the initial  access  posi-  |
  1881.                tion is set to the end of the file.                 |
  1882.  
  1883.           Access defaults to r.  If a file  is  opened  for  both  |
  1884.           reading  and writing, then seek must be invoked between  |
  1885.           a read and a write, or  vice  versa  (this  restriction  |
  1886.           does  not apply to command pipelines opened with open).  |
  1887.           When  fileName  specifies  a  command  pipeline  and  a  |
  1888.           write-only  access  is  used, then standard output from  |
  1889.           the pipeline is directed to the current standard output  |
  1890.           unless overridden by the command.  When fileName speci-  |
  1891.           fies a command pipeline and a read-only access is used,  |
  1892.           then standard input from the pipeline is taken from the  |
  1893.           current standard input unless overridden  by  the  com-  |
  1894.           mand.                                                    |
  1895.  
  1896.      proc name args body
  1897.           The proc command creates a new Tcl  command  procedure,
  1898.           name,  replacing  any  existing  command there may have
  1899.           been  by  that  name.   Whenever  the  new  command  is
  1900.           invoked,  the  contents of body will be executed by the
  1901.           Tcl interpreter.  Args specifies the  formal  arguments
  1902.           to  the  procedure.   It  consists  of a list, possibly
  1903.           empty, each of whose elements specifies  one  argument.
  1904.           Each  argument specifier is also a list with either one
  1905.           or two fields.  If there is only a single field in  the
  1906.           specifier,  then  it  is  the  name of the argument; if
  1907.           there are two fields, then the first  is  the  argument
  1908.           name  and  the second is its default value.  braces and
  1909.           backslashes may be used in the  usual  way  to  specify
  1910.           complex default values.
  1911.  
  1912.           When name is invoked, a local variable will be  created
  1913.           for  each of the formal arguments to the procedure; its
  1914.           value will be the value of  corresponding  argument  in
  1915.           the  invoking  command or the argument's default value.
  1916.           Arguments with default values need not be specified  in
  1917.           a  procedure invocation.  However, there must be enough
  1918.           actual arguments for  all  the  formal  arguments  that
  1919.           don't  have  defaults,  and there must not be any extra
  1920.           actual arguments.  There is one special case to  permit
  1921.           procedures  with variable numbers of arguments.  If the
  1922.           last formal argument has the name args, then a call  to
  1923.           the  procedure  may  contain more actual arguments than
  1924.           the procedure has formals.  In this case,  all  of  the
  1925.           actual  arguments  starting  at  the  one that would be
  1926.           assigned to args are combined into a list  (as  if  the
  1927.           list  command  had  been  used); this combined value is
  1928.           assigned to the local variable args.
  1929.  
  1930.           When body is being executed,  variable  names  normally
  1931.           refer  to  local variables, which are created automati-
  1932.           cally when referenced and deleted  when  the  procedure
  1933.           returns.   One  local variable is automatically created
  1934.           for each of the procedure's  arguments.   Global  vari-
  1935.           ables  can only be accessed by invoking the global com-
  1936.           mand.
  1937.  
  1938.           The proc command returns the null string.  When a  pro-
  1939.           cedure  is invoked, the procedure's return value is the
  1940.           value specified in a return command.  If the  procedure
  1941.           doesn't  execute  an  explicit  return, then its return
  1942.           value is the value of the last command executed in  the
  1943.           procedure's  body.   If an error occurs while executing
  1944.           the procedure body, then the procedure-as-a-whole  will
  1945.           return that same error.
  1946.  
  1947.      puts fileId string ?nonewline?
  1948.           Writes the characters given by string to the file given  |
  1949.           by  fileId.   Puts normally outputs a newline character  |
  1950.           after string, but this feature  may  be  suppressed  by  |
  1951.           specifying  the nonewline argument.  Output to files is  |
  1952.           buffered internally by Tcl; the flush  command  may  be  |
  1953.           used to force buffered characters to be output.  FileId  |
  1954.           must have been the return value from a previous call to  |
  1955.           open,  or it may be stdout or stderr to refer to one of  |
  1956.           the standard I/O channels; it must refer to a file that  |
  1957.           was opened for writing.                                  |
  1958.  
  1959.      pwd                                                                ||
  1960.           Returns the path name of the current working directory.  |
  1961.  
  1962.      read fileId                                                        ||
  1963.  
  1964.      read fileId nonewline                                              ||
  1965.  
  1966.      read fileId numBytes                                               ||
  1967.           In  the first form, all of the remaining bytes are read  |
  1968.           from the file given by fileId; they are returned as the  |
  1969.           result of the command.  If nonewline is specified as an  |
  1970.           additional argument, then the  last  character  of  the  |
  1971.           file  is  discarded  if  it is a newline.  In the third  |
  1972.           form, the extra argument specifies how  many  bytes  to  |
  1973.           read;   exactly  this  many  bytes  will  be  read  and  |
  1974.           returned, unless there are fewer  than  numBytes  bytes  |
  1975.           left in the file; in this case, all the remaining bytes  |
  1976.           are returned.  FileId must be stdin or the return value  |
  1977.           from  a  previous call to open; it must refer to a file  |
  1978.           that was opened for reading.                             |
  1979.  
  1980.       
  1981.      regexp ?-indices? ?-nocase? exp string ?matchVar? ?subMatchVar subMatchVar ...?  ||
  1982.           Determines  whether  the regular expression exp matches  |
  1983.           part or all of string and returns 1 if it does, 0 if it  |
  1984.           doesn't.   See  REGULAR  EXPRESSIONS above for complete  |
  1985.           information on the syntax of exp and how it is  matched  |
  1986.           against string.                                          |
  1987.  
  1988.           If the -nocase  switch  is  specified  then  upper-case  |
  1989.           characters  in  string are treated as lower case during  |
  1990.           the matching  process.   The  -nocase  switch  must  be  |
  1991.           specified before exp and may not be abbreviated.         |
  1992.  
  1993.           If additional arguments are specified after string then  |
  1994.           they  are  treated  as the names of variables to use to  |
  1995.           return  information  about  which  part(s)  of   string  |
  1996.           matched  exp.   MatchVar  will  be  set to the range of  |
  1997.           string that matched all of exp.  The first  subMatchVar  |
  1998.           will  contain the characters in string that matched the  |
  1999.           leftmost parenthesized subexpression  within  exp,  the  |
  2000.           next  subMatchVar  will  contain  the  characters  that  |
  2001.           matched the next  parenthesized  subexpression  to  the  |
  2002.           right in exp, and so on.                                 |
  2003.  
  2004.           Normally, matchVar and the subMatchVars are set to hold  |
  2005.           the  matching  characters from string.  However, if the  |
  2006.           -indices switch is specified then  each  variable  will  |
  2007.           contain  a  list  of  two  decimal  strings  giving the  |
  2008.           indices in string of the first and last  characters  in  |
  2009.           the  matching range of characters.  The -indices switch  |
  2010.           must be specified before the exp argument and  may  not  |
  2011.           be abbreviated.                                          |
  2012.  
  2013.           If there are more more subMatchVar's than parenthesized  |
  2014.           subexpressions  within  exp,  or if a particular subex-  |
  2015.           pression in exp doesn't match the string (e.g.  because  |
  2016.           it  was  in  a  portion  of  the expression that wasn't  |
  2017.           matched), then the corresponding  subMatchVar  will  be  |
  2018.           set  to  ``-1 -1'' if -indices has been specified or to  |
  2019.           an empty string otherwise.                               |
  2020.  
  2021.      regsub ?-all? ?-nocase? exp string subSpec varName                 ||
  2022.           This command matches the regular expression exp against  |
  2023.           string using the rules described in REGULAR EXPRESSIONS  |
  2024.           above.   If there is no match, then the command returns  |
  2025.           0 and does nothing else.  If there is a match, then the  |
  2026.           command  returns  1 and also copies string to the vari-  |
  2027.           able whose name is  given  by  varName.   When  copying  |
  2028.           string,  the  portion  of  string  that  matched exp is  |
  2029.           replaced with subSpec.  If subSpec contains a ``&''  or  |
  2030.           ``\0'',  then  it  is replaced in the substitution with  |
  2031.           the portion of string that  matched  exp.   If  subSpec  |
  2032.           contains  a ``\n'', where n is a digit between 1 and 9,  |
  2033.           then it is replaced in the substitution with  the  por-  |
  2034.           tion  of  string  that  matched  the n-th parenthesized  |
  2035.           subexpression of exp.  Additional  backslashes  may  be  |
  2036.           used  in  subSpec  to prevent special interpretation of  |
  2037.           ``&'' or ``\0'' or ``\n'' or  backslash.   The  use  of  |
  2038.           backslashes in subSpec tends to interact badly with the  |
  2039.           Tcl parser's use  of  backslashes,  so  it's  generally  |
  2040.           safest  to  enclose  subSpec  in  braces if it includes  |
  2041.           backslashes.  If the -all argument is  specified,  then  |
  2042.           all  ranges in string that match exp are found and sub-  |
  2043.           stitution is performed for each of these ranges;   oth-  |
  2044.           erwise  only the first matching range is found and sub-  |
  2045.           stituted.  If -all is specified, then ``&'' and  ``\n''  |
  2046.           sequences  are  handled for each substitution using the  |
  2047.           information  from  the  corresponding  match.   If  the  |
  2048.           -nocase  argument is specified, then upper-case charac-  |
  2049.           ters in  string  are  converted  to  lower-case  before  |
  2050.           matching against exp;  however, substitutions specified  |
  2051.           by subSpec use the original unconverted form of string.  |
  2052.           The  -all  and  -nocase  arguments  must  be  specified  |
  2053.           exactly:  no abbreviations are permitted.
  2054.  
  2055.      rename oldName newName
  2056.           Rename the command that used to be  called  oldName  so
  2057.           that  it is now called newName.  If newName is an empty
  2058.           string (e.g. {}) then oldName is deleted.   The  rename
  2059.           command returns an empty string as result.
  2060.  
  2061.      return ?value?
  2062.           Return immediately from the current procedure (or  top-
  2063.           level  command  or  source  command), with value as the
  2064.           return value.  If value  is  not  specified,  an  empty
  2065.           string will be returned as result.
  2066.  
  2067.      scan string format varname1 ?varname2 ...?
  2068.           This command parses fields from an input string in  the
  2069.           same  fashion  as the C sscanf procedure.  String gives
  2070.           the input to be parsed  and  format  indicates  how  to
  2071.           parse  it,  using  %  fields  as in sscanf.  All of the
  2072.           sscanf options are valid; see the sscanf man  page  for
  2073.           details.   Each  varname  gives the name of a variable;
  2074.           when a field is scanned from string, the result is con-
  2075.           verted   back   into  a  string  and  assigned  to  the
  2076.           corresponding varname.  The only unusual conversion  is
  2077.           for %c.  For %c conversions a single character value is
  2078.           converted to a decimal string, which is  then  assigned
  2079.           to  the  corresponding  varname;  no field width may be  |
  2080.           specified for this conversion.                           |
  2081.  
  2082.      seek fileId offset ?origin?                                        ||
  2083.           Change  the  current  access  position for fileId.  The  |
  2084.           offset and origin arguments  specify  the  position  at  |
  2085.           which  the  next  read  or write will occur for fileId.  |
  2086.           Offset must be a number (which  may  be  negative)  and  |
  2087.           origin must be one of the following:                     |
  2088.  
  2089.           start                                                         ||
  2090.                The  new access position will be origin bytes from  |
  2091.                the start of the file.                              |
  2092.  
  2093.           current                                                       ||
  2094.                The  new access position will be origin bytes from  |
  2095.                the current access  position;  a  negative  origin  |
  2096.                moves the access position backwards in the file.    |
  2097.  
  2098.           end                                                           ||
  2099.                The  new access position will be origin bytes from  |
  2100.                the end of the file.  A negative origin places the  |
  2101.                access  position  before  the  end-of-file,  and a  |
  2102.                positive origin places the access  position  after  |
  2103.                the end-of-file.                                    |
  2104.  
  2105.           The origin argument defaults  to  start.   FileId  must  |
  2106.           have  been  the  return  value  from a previous call to  |
  2107.           open, or it may be stdin, stdout, or stderr to refer to  |
  2108.           one of the standard I/O channels.  This command returns  |
  2109.           an empty string.                                         |
  2110.  
  2111.      set varname ?value?
  2112.           Returns the value of variable  varname.   If  value  is
  2113.           specified,  then  set  the  value  of varname to value,
  2114.           creating a new variable if one doesn't  already  exist,
  2115.           and  return  its  value.   If  varName contains an open  |
  2116.           parenthesis and ends with a close parenthesis, then  it  |
  2117.           refers  to an array element:  the characters before the  |
  2118.           open parenthesis are the name of  the  array,  and  the  |
  2119.           characters between the parentheses are the index within  |
  2120.           the array.  Otherwise varName refers to a scalar  vari-  |
  2121.           able.   If  no procedure is active, then varname refers
  2122.           to a global variable.  If a procedure is  active,  then
  2123.           varname  refers to a parameter or local variable of the
  2124.           procedure, unless the global command has  been  invoked
  2125.           to declare varname to be global.
  2126.  
  2127.      source fileName
  2128.           Read file fileName and pass the  contents  to  the  Tcl
  2129.           interpreter as a sequence of commands to execute in the
  2130.           normal fashion.  The return  value  of  source  is  the
  2131.           return  value  of  the  last  command executed from the
  2132.           file.  If an error occurs in executing the contents  of
  2133.           the  file,  then  the  source  command will return that
  2134.           error.  If a return command is invoked from within  the
  2135.           file, the remainder of the file will be skipped and the
  2136.           source command will return  normally  with  the  result
  2137.           from  the  return  command.   If fileName starts with a
  2138.           tilde, then it is tilde-substituted as described in the
  2139.           Tcl_TildeSubst manual entry.
  2140.  
  2141.      split string ?splitChars?
  2142.           Returns a list created  by  splitting  string  at  each
  2143.           character  that  is  in  the splitChars argument.  Each
  2144.           element of the result list will consist of the  charac-
  2145.           ters from string between instances of the characters in
  2146.           splitChars.  Empty list elements will be  generated  if
  2147.           string  contains  adjacent characters in splitChars, or
  2148.           if  the  first  or  last  character  of  string  is  in
  2149.           splitChars.  If splitChars is an empty string then each
  2150.           character of string becomes a separate element  of  the
  2151.           result  list.   SplitChars  defaults  to  the  standard
  2152.           white-space characters.  For example,
  2153.  
  2154.                split "comp.unix.misc" .
  2155.                
  2156.           returns "comp unix misc" and
  2157.  
  2158.                split "Hello world" {}
  2159.                
  2160.           returns "H e l l o { } w o r l d".
  2161.  
  2162.      string option arg ?arg ...?
  2163.           Perform one of several string operations, depending  on
  2164.           option.   The  legal options (which may be abbreviated)
  2165.           are:
  2166.  
  2167.           string compare string1 string2
  2168.                Perform  a  character-by-character  comparison  of
  2169.                strings string1 and string2 in the same way as the
  2170.                C strcmp procedure.  Return -1, 0, or 1, depending
  2171.                on whether string1 is lexicographically less than,
  2172.                equal to, or greater than string2.
  2173.  
  2174.           string first string1 string2
  2175.                Search string2 for a sequence of  characters  that
  2176.                exactly  match  the  characters  in  string1.   If
  2177.                found, return the index of the first character  in
  2178.                the  first  such  match  within  string2.   If not
  2179.                found, return -1.
  2180.  
  2181.           string index string charIndex                                 ||
  2182.                Returns  the  charIndex'th character of the string  |
  2183.                argument.  A charIndex of  0  corresponds  to  the  |
  2184.                first  character  of  the string.  If charIndex is  |
  2185.                less than 0 or greater than or equal to the length  |
  2186.                of the string then an empty string is returned.
  2187.  
  2188.           string last string1 string2
  2189.                Search string2 for a sequence of  characters  that
  2190.                exactly  match  the  characters  in  string1.   If
  2191.                found, return the index of the first character  in
  2192.                the  last  such match within string2.  If there is
  2193.                no match, then return -1.
  2194.  
  2195.           string length string                                          ||
  2196.                Returns  a  decimal  string  giving  the number of  |
  2197.                characters in string.
  2198.  
  2199.           string match pattern string
  2200.                See if pattern matches  string;  return  1  if  it
  2201.                does,  0  if  it  doesn't.   Matching is done in a
  2202.                fashion similar to that used by the C-shell.   For
  2203.                the  two  strings to match, their contents must be
  2204.                identical  except  that  the   following   special
  2205.                sequences may appear in pattern:
  2206.  
  2207.                *         Matches any sequence  of  characters  in
  2208.                          string, including a null string.
  2209.  
  2210.                ?         Matches any single character in string.
  2211.  
  2212.                [chars]   Matches any character in the  set  given
  2213.                          by chars.  If a sequence of the form x-y
  2214.                          appears in  chars,  then  any  character
  2215.                          between x and y, inclusive, will match.
  2216.  
  2217.                \x        Matches the single  character  x.   This
  2218.                          provides  a  way of avoiding the special
  2219.                          interpretation of the  characters  *?[]\
  2220.                          in pattern.
  2221.  
  2222.           string range string first last                                ||
  2223.                Returns  a  range  of  consecutive characters from  |
  2224.                string, starting with the character whose index is  |
  2225.                first and ending with the character whose index is  |
  2226.                last.  An index of 0 refers to the first character  |
  2227.                of  the string.  Last may be end (or any abbrevia-  |
  2228.                tion of it) to refer to the last character of  the  |
  2229.                string.   If  first  is  less than zero then it is  |
  2230.                treated as if it were zero, and if last is greater  |
  2231.                than  or equal to the length of the string then it  |
  2232.                is treated as if it were end.  If first is greater  |
  2233.                than last then an empty string is returned.         |
  2234.  
  2235.           string tolower string                                         ||
  2236.                Returns  a  value  equal to string except that all  |
  2237.                upper case letters have been  converted  to  lower  |
  2238.                case.                                               |
  2239.  
  2240.           string toupper string                                         ||
  2241.                Returns  a  value  equal to string except that all  |
  2242.                lower case letters have been  converted  to  upper  |
  2243.                case.                                               |
  2244.  
  2245.           string trim string ?chars?                                    ||
  2246.                Returns  a  value  equal to string except that any  |
  2247.                leading or trailing characters from the set  given  |
  2248.                by  chars  are removed.  If chars is not specified  |
  2249.                then white space is removed  (spaces,  tabs,  new-  |
  2250.                lines, and carriage returns).                       |
  2251.  
  2252.           string trimleft string ?chars?                                ||
  2253.                Returns  a  value  equal to string except that any  |
  2254.                leading characters from the set given by chars are  |
  2255.                removed.   If  chars  is  not specified then white  |
  2256.                space is  removed  (spaces,  tabs,  newlines,  and  |
  2257.                carriage returns).                                  |
  2258.  
  2259.           string trimright string ?chars?                               ||
  2260.                Returns  a  value  equal to string except that any  |
  2261.                trailing characters from the set  given  by  chars  |
  2262.                are removed.  If chars is not specified then white  |
  2263.                space is removed (spaces, tabs, newlines, and car-  |
  2264.                riage returns).                                     |
  2265.  
  2266.      tell fileId                                                        ||
  2267.           Returns  a  decimal  string  giving  the current access  |
  2268.           position in fileId.  FileId must have been  the  return  |
  2269.           value from a previous call to open, or it may be stdin,  |
  2270.           stdout, or stderr to refer to one of the  standard  I/O  |
  2271.           channels.
  2272.  
  2273.      time command ?count?
  2274.           This command will call the Tcl interpreter count  times
  2275.           to  execute command (or once if count isn't specified).
  2276.           It will then return a string of the form
  2277.  
  2278.                503 microseconds per iteration
  2279.                
  2280.           which indicates the average amount of time required per
  2281.           iteration,   in  microseconds.   Time  is  measured  in
  2282.           elapsed time, not CPU time.
  2283.  
  2284.      trace option ?arg arg ...?
  2285.           Cause Tcl commands  to  be  executed  whenever  certain  |
  2286.           operations  are  invoked.   At  present,  only variable  |
  2287.           tracing is implemented. The legal option's  (which  may  |
  2288.           be abbreviated) are:                                     |
  2289.  
  2290.           trace variable name ops command                               ||
  2291.                Arrange  for command to be executed whenever vari-  |
  2292.                able name is accessed in one of the ways given  by  |
  2293.                ops.  Name may refer to a normal variable, an ele-  |
  2294.                ment of an array, or to an array as a whole  (i.e.  |
  2295.                name  may  be  just  the name of an array, with no  |
  2296.                parenthesized index).  If name refers to  a  whole  |
  2297.                array,  then  command is invoked whenever any ele-  |
  2298.                ment of the array is manipulated.                   |
  2299.  
  2300.                Ops indicates which operations  are  of  interest,  |
  2301.                and  consists  of  one  or  more  of the following  |
  2302.                letters:                                            |
  2303.  
  2304.                     r                                                   ||
  2305.                          Invoke  command whenever the variable is  |
  2306.                          read.                                     |
  2307.  
  2308.                     w                                                   ||
  2309.                          Invoke  command whenever the variable is  |
  2310.                          written.                                  |
  2311.  
  2312.                     u                                                   ||
  2313.                          Invoke  command whenever the variable is  |
  2314.                          unset.  Variables can  be  unset  expli-  |
  2315.                          citly  with the unset command, or impli-  |
  2316.                          citly when  procedures  return  (all  of  |
  2317.                          their local variables are unset).  Vari-  |
  2318.                          ables are also unset  when  interpreters  |
  2319.                          are  deleted,  but  traces  will  not be  |
  2320.                          invoked because there is no  interpreter  |
  2321.                          in which to execute them.                 |
  2322.  
  2323.                When  the  trace  triggers,  three  arguments  are  |
  2324.                appended  to command so that the actual command is  |
  2325.                as follows:                                         |
  2326.  
  2327.                     command name1 name2 op                         |
  2328.                     
  2329.                Name1 and name2 give the name(s) for the  variable  |
  2330.                being  accessed:  if the variable is a scalar then  |
  2331.                name1 gives the variable's name and  name2  is  an  |
  2332.                empty  string; if the variable is an array element  |
  2333.                then name1 gives the name of the array  and  name2  |
  2334.                gives the index into the array; if an entire array  |
  2335.                is being deleted and the trace was  registered  on  |
  2336.                the  overall  array, rather than a single element,  |
  2337.                then name1 gives the array name and  name2  is  an  |
  2338.                empty  string.   Op  indicates  what  operation is  |
  2339.                being performed on the variable, and is one of  r,  |
  2340.                w, or u as defined above.                           |
  2341.  
  2342.                Command executes in the same context as  the  code  |
  2343.                that  invoked  the traced operation:  if the vari-  |
  2344.                able was accessed as part of a Tcl procedure, then  |
  2345.                command  will  have access to the same local vari-  |
  2346.                ables as code in the procedure.  This context  may  |
  2347.                be  different  than the context in which the trace  |
  2348.                was created.  Note that name1 may not  necessarily  |
  2349.                be  the  same as the name used to set the trace on  |
  2350.                the variable;  differences can occur if the access  |
  2351.                is  made through a variable defined with the upvar  |
  2352.                command.                                            |
  2353.  
  2354.                For read and write traces, command can modify  the  |
  2355.                variable to affect the result of the traced opera-  |
  2356.                tion.  If command modifies the value of a variable  |
  2357.                during  a  read  trace, then the value returned by  |
  2358.                the traced read operation will be the value of the  |
  2359.                variable   after  command  completes.   For  write  |
  2360.                traces, command is invoked  after  the  variable's  |
  2361.                value  has  been changed; it can write a new value  |
  2362.                into the variable to override the  original  value  |
  2363.                specified  in  the  write  operation.   The  value  |
  2364.                returned by the traced write operation will be the  |
  2365.                value  of the variable when command completes.  If  |
  2366.                command returns an error during a  read  or  write  |
  2367.                trace,  then  the traced operation is aborted with  |
  2368.                an error.  This mechanism can be used to implement  |
  2369.                read-only   variables,   for  example.   Command's  |
  2370.                result is always ignored.                           |
  2371.  
  2372.                While command is executing during a read or  write  |
  2373.                trace, traces on the variable are temporarily dis-  |
  2374.                abled.  This means that reads and  writes  invoked  |
  2375.                by  command  will occur directly, without invoking  |
  2376.                command (or any other traces) again.  It is  ille-  |
  2377.                gal  to  unset  a variable while a trace is active  |
  2378.                for it.  It is also illegal to unset an  array  if  |
  2379.                there  are  traces  active  for any of the array's  |
  2380.                elements.                                           |
  2381.  
  2382.                When an unset trace is invoked, the  variable  has  |
  2383.                already  been deleted:  it will appear to be unde-  |
  2384.                fined with no traces.  If an unset occurs  because  |
  2385.                of  a  procedure  return,  then  the trace will be  |
  2386.                invoked in the variable context of  the  procedure  |
  2387.                being returned to:  the stack frame of the return-  |
  2388.                ing procedure will no longer  exist.   Traces  are  |
  2389.                not  disabled  during unset traces, so if an unset  |
  2390.                trace command creates a new trace and accesses the  |
  2391.                variable, the trace will be invoked.                |
  2392.  
  2393.                If there are multiple traces on  a  variable  they  |
  2394.                are  invoked  in  order  of  creation, most-recent  |
  2395.                first.  If one trace returns  an  error,  then  no  |
  2396.                further  traces  are invoked for the variable.  If  |
  2397.                an array element has a trace  set,  and  there  is  |
  2398.                also  a  trace  set  on  the array as a whole, the  |
  2399.                trace on the overall array is invoked  before  the  |
  2400.                one on the element.                                 |
  2401.  
  2402.                Once created, the trace remains in  effect  either  |
  2403.                until  the trace is removed with the trace vdelete  |
  2404.                command described below,  until  the  variable  is  |
  2405.                unset,   or  until  the  interpreter  is  deleted.  |
  2406.                Unsetting an element  of  array  will  remove  any  |
  2407.                traces on that element, but will not remove traces  |
  2408.                on the overall array.                               |
  2409.  
  2410.                This command returns an empty string.               |
  2411.  
  2412.           trace vdelete name ops command                                ||
  2413.                If  there is a trace set on variable name with the  |
  2414.                operations and command given by ops  and  command,  |
  2415.                then  the  trace  is removed, so that command will  |
  2416.                never again be invoked.  Returns an empty string.   |
  2417.  
  2418.           trace vinfo name                                              ||
  2419.                Returns  a  list  containing  one element for each  |
  2420.                trace currently set on variable name.   Each  ele-  |
  2421.                ment  of  the list is itself a list containing two  |
  2422.                elements, which are the ops and command associated  |
  2423.                with  the trace.  If name doesn't exist or doesn't  |
  2424.                have any traces set, then the result of  the  com-  |
  2425.                mand will be an empty string.                       |
  2426.  
  2427.      unknown cmdName ?arg arg ...?                                      ||
  2428.           This command doesn't actually exist as part of Tcl, but  |
  2429.           Tcl will invoke it if it does exist.  If the Tcl inter-  |
  2430.           preter encounters a command name for which there is not  |
  2431.           a defined command, then Tcl checks for the existence of  |
  2432.           a  command named unknown.  If there is no such command,  |
  2433.           then the interpeter returns an error.  If  the  unknown  |
  2434.           command  exists, then it is invoked with arguments con-  |
  2435.           sisting of the fully-substituted name and arguments for  |
  2436.           the original non-existent command.  The unknown command  |
  2437.           typically does things like  searching  through  library  |
  2438.           directories  for  a  command  procedure  with  the name  |
  2439.           cmdName, or  expanding  abbreviated  command  names  to  |
  2440.           full-length,  or  automatically  executing unknown com-  |
  2441.           mands as UNIX sub-processes.  In some  cases  (such  as  |
  2442.           expanding abbreviations) unknown will change the origi-  |
  2443.           nal command slightly and  then  (re-)execute  it.   The  |
  2444.           result of the unknown command is used as the result for  |
  2445.           the original non-existent command.                       |
  2446.  
  2447.      unset name ?name name ...?                                         ||
  2448.           Remove  one or more variables.  Each name is a variable  |
  2449.           name, specified in any of the ways  acceptable  to  the  |
  2450.           set  command.   If  a  name  refers to an element of an  |
  2451.           array, then that element is removed  without  affecting  |
  2452.           the  rest of the array.  If a name consists of an array  |
  2453.           name with no parenthesized index, then the entire array  |
  2454.           is  deleted.  The unset command returns an empty string  |
  2455.           as result.  An error occurs if  any  of  the  variables  |
  2456.           doesn't exist, or if any of the variables has an active  |
  2457.           trace.
  2458.  
  2459.      uplevel ?level? command ?command ...?
  2460.           All of the command arguments  are  concatenated  as  if
  2461.           they  had  been  passed  to  concat; the result is then
  2462.           evaluated in the variable context indicated  by  level.
  2463.           Uplevel  returns  the  result  of  that evaluation.  If
  2464.           level is an integer, then it gives a distance  (up  the
  2465.           procedure  calling  stack) to move before executing the
  2466.           command.  If level consists of # followed by  a  number
  2467.           then  the  number  gives  an absolute level number.  If
  2468.           level is omitted then it defaults to 1.   Level  cannot
  2469.           be  defaulted if the first command argument starts with
  2470.           a digit or #.  For example, suppose  that  procedure  a
  2471.           was  invoked  from top-level, and that it called b, and
  2472.           that b called c.  Suppose that c  invokes  the  uplevel
  2473.           command.   If  level  is  1 or #2  or omitted, then the
  2474.           command will be executed in the variable context of  b.
  2475.           If  level  is 2 or #1 then the command will be executed
  2476.           in the variable context of a.  If level is 3 or #0 then
  2477.           the  command will be executed at top-level (only global
  2478.           variables will be visible).  The uplevel command causes
  2479.           the  invoking procedure to disappear from the procedure
  2480.           calling stack while the command is being executed.   In
  2481.           the above example, suppose c invokes the command
  2482.  
  2483.                uplevel 1 {set x 43; d}
  2484.                
  2485.           where d is another Tcl procedure.  The set command will
  2486.           modify  the  variable x in b's context, and d will exe-
  2487.           cute at level 3, as if called from b.  If  it  in  turn
  2488.           executes the command
  2489.  
  2490.                uplevel {set x 42}
  2491.                
  2492.           then the set command will modify the same variable x in
  2493.           b's  context:  the procedure c does not appear to be on
  2494.           the call stack when d is executing.  The command ``info
  2495.           level''  may be used to obtain the level of the current
  2496.           procedure.  Uplevel makes it possible to implement  new
  2497.           control  constructs  as  Tcl  procedures  (for example,
  2498.           uplevel could be used to implement the while  construct
  2499.           as a Tcl procedure).
  2500.  
  2501.      upvar ?level? otherVar myVar ?otherVar myVar ...?
  2502.           This command arranges for one or more  local  variables  |
  2503.           in  the  current  procedure to refer to variables in an  |
  2504.           enclosing procedure call or to global variables.  Level  |
  2505.           may  have  any  of  the forms permitted for the uplevel  |
  2506.           command, and may be omitted if the first letter of  the  |
  2507.           first  otherVar  isn't # or a digit (it defaults to 1).  |
  2508.           For each otherVar argument, upvar makes the variable by  |
  2509.           that  name in the procedure frame given by level (or at  |
  2510.           global level, if level is #0) accessible in the current  |
  2511.           procedure  by the name given in the corresponding myVar  |
  2512.           argument.  The variable  named  by  otherVar  need  not  |
  2513.           exist  at the time of the call;  it will be created the  |
  2514.           first time myVar is referenced, just like  an  ordinary  |
  2515.           variable.   Upvar  may only be invoked from within pro-  |
  2516.           cedures.  Neither otherVar or myVar  may  refer  to  an  |
  2517.           element of an array.  Upvar returns an empty string.     |
  2518.  
  2519.           The upvar  command  simplifies  the  implementation  of  |
  2520.           call-by-name procedure calling and also makes it easier  |
  2521.           to build new control constructs as Tcl procedures.  For  |
  2522.           example, consider the following procedure:               |
  2523.  
  2524.                proc add2 name {                                    |
  2525.                    upvar $name x                                   |
  2526.                    set x [expr $x+2]                               |
  2527.                }                                                   |
  2528.                
  2529.           Add2 is invoked with an argument giving the name  of  a  |
  2530.           variable,  and  it  adds two to the value of that vari-  |
  2531.           able.  Although add2 could have been implemented  using  |
  2532.           uplevel  instead  of  upvar, upvar makes it simpler for  |
  2533.           add2 to access the variable in the  caller's  procedure  |
  2534.           frame.
  2535.  
  2536.      while test body
  2537.           The while command evaluates test as an  expression  (in  |
  2538.           the  same  way  that expr evaluates its argument).  The  |
  2539.           value of the expression must be numeric; if it is  non-  |
  2540.           zero  then  body  is  executed by passing it to the Tcl  |
  2541.           interpreter.  Once body has been executed then test  is  |
  2542.           evaluated  again, and the process repeats until eventu-  |
  2543.           ally test evaluates to a zero numeric value.   Continue  |
  2544.           commands  may  be executed inside body to terminate the  |
  2545.           current iteration of the loop, and break  commands  may  |
  2546.           be  executed inside body to cause immediate termination  |
  2547.           of the while command.  The while command always returns  |
  2548.           an empty string.
  2549.  
  2550.  
  2551.  
  2552. AUTHOR
  2553.      John  Ousterhout,  University  of  California  at   Berkeley
  2554.      (ouster@sprite.berkeley.edu)
  2555.  
  2556.      Many people have contributed to Tcl in various ways, but the
  2557.      following people have made unusually large contributions:
  2558.  
  2559.      Bill Carpenter
  2560.      Peter Da Silva
  2561.      Mark Diekhans
  2562.      Karl Lehenbauer
  2563.      Mary Ann May-Pumphrey
  2564.  
  2565.