1 |
578 |
markom |
'\"
|
2 |
|
|
'\" Copyright (c) 1993 The Regents of the University of California.
|
3 |
|
|
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
|
4 |
|
|
'\"
|
5 |
|
|
'\" See the file "license.terms" for information on usage and redistribution
|
6 |
|
|
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
7 |
|
|
'\"
|
8 |
|
|
'\" RCS: @(#) $Id: proc.n,v 1.1.1.1 2002-01-16 10:25:25 markom Exp $
|
9 |
|
|
'\"
|
10 |
|
|
.so man.macros
|
11 |
|
|
.TH proc n "" Tcl "Tcl Built-In Commands"
|
12 |
|
|
.BS
|
13 |
|
|
'\" Note: do not modify the .SH NAME line immediately below!
|
14 |
|
|
.SH NAME
|
15 |
|
|
proc \- Create a Tcl procedure
|
16 |
|
|
.SH SYNOPSIS
|
17 |
|
|
\fBproc \fIname args body\fR
|
18 |
|
|
.BE
|
19 |
|
|
|
20 |
|
|
.SH DESCRIPTION
|
21 |
|
|
.PP
|
22 |
|
|
The \fBproc\fR command creates a new Tcl procedure named
|
23 |
|
|
\fIname\fR, replacing
|
24 |
|
|
any existing command or procedure there may have been by that name.
|
25 |
|
|
Whenever the new command is invoked, the contents of \fIbody\fR will
|
26 |
|
|
be executed by the Tcl interpreter.
|
27 |
|
|
Normally, \fIname\fR is unqualified
|
28 |
|
|
(does not include the names of any containing namespaces),
|
29 |
|
|
and the new procedure is created in the current namespace.
|
30 |
|
|
If \fIname\fR includes any namespace qualifiers,
|
31 |
|
|
the procedure is created in the specified namespace.
|
32 |
|
|
\fIArgs\fR specifies the formal arguments to the
|
33 |
|
|
procedure. It consists of a list, possibly empty, each of whose
|
34 |
|
|
elements specifies
|
35 |
|
|
one argument. Each argument specifier is also a list with either
|
36 |
|
|
one or two fields. If there is only a single field in the specifier
|
37 |
|
|
then it is the name of the argument; if there are two fields, then
|
38 |
|
|
the first is the argument name and the second is its default value.
|
39 |
|
|
.PP
|
40 |
|
|
When \fIname\fR is invoked a local variable
|
41 |
|
|
will be created for each of the formal arguments to the procedure; its
|
42 |
|
|
value will be the value of corresponding argument in the invoking command
|
43 |
|
|
or the argument's default value.
|
44 |
|
|
Arguments with default values need not be
|
45 |
|
|
specified in a procedure invocation. However, there must be enough
|
46 |
|
|
actual arguments for all the
|
47 |
|
|
formal arguments that don't have defaults, and there must not be any extra
|
48 |
|
|
actual arguments. There is one special case to permit procedures with
|
49 |
|
|
variable numbers of arguments. If the last formal argument has the name
|
50 |
|
|
\fBargs\fR, then a call to the procedure may contain more actual arguments
|
51 |
|
|
than the procedure has formals. In this case, all of the actual arguments
|
52 |
|
|
starting at the one that would be assigned to \fBargs\fR are combined into
|
53 |
|
|
a list (as if the \fBlist\fR command had been used); this combined value
|
54 |
|
|
is assigned to the local variable \fBargs\fR.
|
55 |
|
|
.PP
|
56 |
|
|
When \fIbody\fR is being executed, variable names normally refer to
|
57 |
|
|
local variables, which are created automatically when referenced and
|
58 |
|
|
deleted when the procedure returns. One local variable is automatically
|
59 |
|
|
created for each of the procedure's arguments.
|
60 |
|
|
Global variables can only be accessed by invoking
|
61 |
|
|
the \fBglobal\fR command or the \fBupvar\fR command.
|
62 |
|
|
Namespace variables can only be accessed by invoking
|
63 |
|
|
the \fBvariable\fR command or the \fBupvar\fR command.
|
64 |
|
|
.PP
|
65 |
|
|
The \fBproc\fR command returns an empty string. When a procedure is
|
66 |
|
|
invoked, the procedure's return value is the value specified in a
|
67 |
|
|
\fBreturn\fR command. If the procedure doesn't execute an explicit
|
68 |
|
|
\fBreturn\fR, then its return value is the value of the last command
|
69 |
|
|
executed in the procedure's body.
|
70 |
|
|
If an error occurs while executing the procedure
|
71 |
|
|
body, then the procedure-as-a-whole will return that same error.
|
72 |
|
|
|
73 |
|
|
.SH KEYWORDS
|
74 |
|
|
argument, procedure
|