Initial release
This commit is contained in:
66
hlp/en/tcl/proc.htm
Normal file
66
hlp/en/tcl/proc.htm
Normal file
@@ -0,0 +1,66 @@
|
||||
<HTML><HEAD><TITLE>Built-In Commands - proc manual page</TITLE></HEAD><BODY>
|
||||
<H3><A NAME="M2">NAME</A></H3>
|
||||
proc - Create a Tcl procedure
|
||||
<H3><A NAME="M3">SYNOPSIS</A></H3>
|
||||
<B>proc </B><I>name args body</I><BR>
|
||||
<H3><A NAME="M4">DESCRIPTION</A></H3>
|
||||
The <B>proc</B> command creates a new Tcl procedure named
|
||||
<I>name</I>, replacing
|
||||
any existing command or procedure there may have been by that name.
|
||||
Whenever the new command is invoked, the contents of <I>body</I> will
|
||||
be executed by the Tcl interpreter.
|
||||
Normally, <I>name</I> is unqualified
|
||||
(does not include the names of any containing namespaces),
|
||||
and the new procedure is created in the current namespace.
|
||||
If <I>name</I> includes any namespace qualifiers,
|
||||
the procedure is created in the specified namespace.
|
||||
<I>Args</I> 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.
|
||||
<P>
|
||||
When <I>name</I> is invoked a local variable
|
||||
will be created for each of the formal arguments to the procedure; its
|
||||
value will be the value of corresponding argument in the invoking command
|
||||
or the argument's default value.
|
||||
Arguments with default values need not be
|
||||
specified in a procedure 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
|
||||
<B>args</B>, 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 <B>args</B> are combined into
|
||||
a list (as if the <B><A HREF="../TkCmd/list.htm">list</A></B> command had been used); this combined value
|
||||
is assigned to the local variable <B>args</B>.
|
||||
<P>
|
||||
When <I>body</I> 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
|
||||
created for each of the procedure's arguments.
|
||||
Global variables can only be accessed by invoking
|
||||
the <B><A HREF="../TkCmd/global.htm">global</A></B> command or the <B><A HREF="../TkCmd/upvar.htm">upvar</A></B> command.
|
||||
Namespace variables can only be accessed by invoking
|
||||
the <B><A HREF="../TkCmd/variable.htm">variable</A></B> command or the <B><A HREF="../TkCmd/upvar.htm">upvar</A></B> command.
|
||||
<P>
|
||||
The <B>proc</B> command returns an empty string. When a procedure is
|
||||
invoked, the procedure's return value is the value specified in a
|
||||
<B><A HREF="../TkCmd/return.htm">return</A></B> command. If the procedure doesn't execute an explicit
|
||||
<B><A HREF="../TkCmd/return.htm">return</A></B>, then its return value is the value of the last command
|
||||
executed in the procedure's body.
|
||||
If an error occurs while executing the procedure
|
||||
body, then the procedure-as-a-whole will return that same error.
|
||||
|
||||
<H3><A NAME="M5">SEE ALSO</A></H3>
|
||||
<B><A HREF="../TkCmd/info.htm">info</A></B>, <B><A HREF="../TkCmd/unknown.htm">unknown</A></B>
|
||||
<H3><A NAME="M6">KEYWORDS</A></H3>
|
||||
<A href="../Keywords/A.htm#argument">argument</A>, <A href="../Keywords/P.htm#procedure">procedure</A>
|
||||
<HR><PRE>
|
||||
<A HREF="../copyright.htm">Copyright</A> © 1993 The Regents of the University of California.
|
||||
<A HREF="../copyright.htm">Copyright</A> © 1994-1996 Sun Microsystems, Inc.
|
||||
<A HREF="../copyright.htm">Copyright</A> © 1995-1997 Roger E. Critchlow Jr.</PRE>
|
||||
</BODY></HTML>
|
Reference in New Issue
Block a user