1mNAME0m
       proc - Create a Tcl procedure

1mSYNOPSIS0m
       1mproc 4m22mname24m 4margs24m 4mbody0m


1mDESCRIPTION0m
       The  1mproc 22mcommand creates a new Tcl procedure named 4mname24m, replacing any
       existing command or procedure there may have been by that name.   When-
       ever  the new command is invoked, the contents of 4mbody24m will be executed
       by the Tcl  interpreter.   Normally,  4mname24m  is  unqualified  (does  not
       include  the names of any containing namespaces), and the new procedure
       is created in the current namespace.  If 4mname24m  includes  any  namespace
       qualifiers,  the procedure is created in the specified namespace.  4mArgs0m
       specifies the formal arguments to the  procedure.   It  consists  of  a
       list,  possibly  empty,  each of whose elements specifies one argument.
       Each argument specifier is also a list with either one or  two  fields.
       If there is only a single field in the specifier then it is the name of
       the argument; if there are two fields, then the first is  the  argument
       name and the second is its default value.

       When  4mname24m  is invoked a local variable will be created for each of the
       formal arguments to the procedure; its value will be the value of  cor-
       responding  argument  in the invoking command or the argument's default
       value.  Arguments with default values need not be specified in a proce-
       dure  invocation.   However,  there must be enough actual arguments for
       all the formal arguments that don't have defaults, and there  must  not
       be  any  extra  actual  arguments.  There is one special case to permit
       procedures with variable numbers of  arguments.   If  the  last  formal
       argument  has  the  name 1margs22m, then a call to the procedure may contain
       more actual arguments than the procedure has formals.   In  this  case,
       all  of the actual arguments starting at the one that would be assigned
       to 1margs 22mare combined into a list (as  if  the  1mlist  22mcommand  had  been
       used); this combined value is assigned to the local variable 1margs22m.

       When  4mbody24m  is  being  executed, variable names normally refer to local
       variables, which are created automatically when referenced and  deleted
       when  the  procedure returns.  One local variable is automatically cre-
       ated for each of the procedure's arguments.  Global variables can  only
       be  accessed  by  invoking  the  1mglobal  22mcommand  or the 1mupvar 22mcommand.
       Namespace variables can only be accessed by invoking the 1mvariable  22mcom-
       mand or the 1mupvar 22mcommand.

       The 1mproc 22mcommand returns an empty string.  When a procedure is invoked,
       the procedure's return value is the value specified in  a  1mreturn  22mcom-
       mand.   If  the  procedure doesn't execute an explicit 1mreturn22m, then its
       return value is the value of the last command executed  in  the  proce-
       dure's  body.   If  an error occurs while executing the procedure body,
       then the procedure-as-a-whole will return that same error.


1mSEE ALSO0m
       info(n), unknown(n)


1mKEYWORDS0m
