home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / tcl_447.lzh / TCL / tcl.lzh / tcl / help / proc < prev    next >
Text File  |  1990-05-03  |  3KB  |  53 lines

  1.  proc name args body
  2.       The proc command creates a new Tcl command procedure,
  3.       name, replacing any existing command there may have
  4.       been by that name.  Whenever the new command is
  5.       invoked, the contents of body will be executed by the
  6.       Tcl interpreter.  Args specifies the formal arguments
  7.       to the procedure.  It consists of a list, possibly
  8.       empty, each of whose elements specifies one argument.
  9.  
  10.       Each argument specifier is also a list with either one
  11.       or two fields.  If there is only a single field in the
  12.       specifier, then it is the name of the argument; if
  13.       there are two fields, then the first is the argument
  14.       name and the second is its default value.  braces and
  15.       backslashes may be used in the usual way to specify
  16.       complex default values.
  17.  
  18.       When name is invoked, a local variable will be created
  19.       for each of the formal arguments to the procedure;  its
  20.       value will be the value of corresponding argument in
  21.       the invoking command or the argument's default value.
  22.       Arguments with default values need not be specified in
  23.       a procedure invocation. However, there must be enough
  24.       actual arguments for all the formal arguments that
  25.       don't have defaults, and there must not be any extra
  26.       actual arguments.  There is one special case to permit
  27.       procedures with variable numbers of arguments.  If the
  28.       last formal argument has the name args, then a call to
  29.       the procedure may contain more actual arguments than
  30.       the procedure has formals.  In this case, all of the
  31.       actual arguments starting at the one that would be
  32.       assigned to args are combined into a list (as if the
  33.       list command had been used);  this combined value is
  34.       assigned to the local variable args.
  35.  
  36.       When body is being executed, variable names normally
  37.       refer to local variables, which are created
  38.       automatically when referenced and deleted when the
  39.       procedure returns.  One local variable is automatically
  40.       created for each of the procedure's arguments.  Global
  41.       variables can only be accessed by invoking the global
  42.       command.
  43.  
  44.       The proc command returns the null string.  When a
  45.       procedure is invoked, the procedure's return value is
  46.       the value specified in a return command.  If the
  47.       procedure doesn't execute an explicit return, then its
  48.       return value is the value of the last command executed
  49.       in the procedure's body.  If an error occurs while
  50.       executing the procedure body, then the procedure-as-a-
  51.       whole will return that same error.
  52.  
  53.