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

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/proc.n,v 1.1 93/05/10 17:10:18 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS proc tcl
  25. .BS
  26. '\" Note:  do not modify the .SH NAME line immediately below!
  27. .SH NAME
  28. proc \- Create a Tcl procedure
  29. .SH SYNOPSIS
  30. \fBproc \fIname args body\fR
  31. .BE
  32.  
  33. .SH DESCRIPTION
  34. .PP
  35. The \fBproc\fR command creates a new Tcl procedure named
  36. \fIname\fR, replacing
  37. any existing command or procedure there may have been by that name.
  38. Whenever the new command is invoked, the contents of \fIbody\fR will
  39. be executed by the Tcl interpreter.
  40. \fIArgs\fR specifies the formal arguments to the
  41. procedure.  It consists of a list, possibly empty, each of whose
  42. elements specifies
  43. one argument.  Each argument specifier is also a list with either
  44. one or two fields.  If there is only a single field in the specifier
  45. then it is the name of the argument; if there are two fields, then
  46. the first is the argument name and the second is its default value.
  47. .PP
  48. When \fIname\fR is invoked a local variable
  49. will be created for each of the formal arguments to the procedure; its
  50. value will be the value of corresponding argument in the invoking command
  51. or the argument's default value.
  52. Arguments with default values need not be
  53. specified in a procedure invocation.  However, there must be enough
  54. actual arguments for all the
  55. formal arguments that don't have defaults, and there must not be any extra
  56. actual arguments.  There is one special case to permit procedures with
  57. variable numbers of arguments.  If the last formal argument has the name
  58. \fBargs\fR, then a call to the procedure may contain more actual arguments
  59. than the procedure has formals.  In this case, all of the actual arguments
  60. starting at the one that would be assigned to \fBargs\fR are combined into
  61. a list (as if the \fBlist\fR command had been used); this combined value
  62. is assigned to the local variable \fBargs\fR.
  63. .PP
  64. When \fIbody\fR is being executed, variable names normally refer to
  65. local variables, which are created automatically when referenced and
  66. deleted when the procedure returns.  One local variable is automatically
  67. created for each of the procedure's arguments.
  68. Global variables can only be accessed by invoking
  69. the \fBglobal\fR command or the \fBupvar\fR command.
  70. .PP
  71. The \fBproc\fR command returns an empty string.  When a procedure is
  72. invoked, the procedure's return value is the value specified in a
  73. \fBreturn\fR command.  If the procedure doesn't execute an explicit
  74. \fBreturn\fR, then its return value is the value of the last command
  75. executed in the procedure's body.
  76. If an error occurs while executing the procedure
  77. body, then the procedure-as-a-whole will return that same error.
  78.  
  79. .SH KEYWORDS
  80. argument, procedure
  81.