home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / library / help / tcl / control / proc < prev    next >
Encoding:
Text File  |  1993-10-26  |  2.8 KB  |  54 lines  |  [TEXT/$Tcl]

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