projman/hlp/en/tcl/variable.htm

56 lines
3.0 KiB
HTML
Raw Normal View History

2015-10-19 13:27:31 +03:00
<HTML><HEAD><TITLE>Tcl Built-In Commands - variable manual page</TITLE></HEAD><BODY>
<H3><A NAME="M2">NAME</A></H3>
variable - create and initialize a namespace variable
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>variable </B>?<I>name value...</I>? <I>name </I>?<I>value</I>?<BR>
<H3><A NAME="M4">DESCRIPTION</A></H3>
This command is normally used within a
<B>namespace eval</B> command to create one or more variables
within a namespace.
Each variable <I>name</I> is initialized with <I>value</I>.
The <I>value</I> for the last variable is optional.
<P>
If a variable <I>name</I> does not exist, it is created.
In this case, if <I>value</I> is specified,
it is assigned to the newly created variable.
If no <I>value</I> is specified, the new variable is left undefined.
If the variable already exists,
it is set to <I>value</I> if <I>value</I> is specified
or left unchanged if no <I>value</I> is given.
Normally, <I>name</I> is unqualified
(does not include the names of any containing namespaces),
and the variable is created in the current namespace.
If <I>name</I> includes any namespace qualifiers,
the variable is created in the specified namespace. If the variable
is not defined, it will be visible to the <B>namespace which</B>
command, but not to the <B><A HREF="../TkCmd/info.htm">info exists</A></B> command.
<P>
If the <B>variable</B> command is executed inside a Tcl procedure,
it creates local variables
linked to the corresponding namespace variables (and therefore these
variables are listed by <B><A HREF="../TkCmd/info.htm">info locals</A></B>.)
In this way the <B>variable</B> command resembles the <B><A HREF="../TkCmd/global.htm">global</A></B> command,
although the <B><A HREF="../TkCmd/global.htm">global</A></B> command
only links to variables in the global namespace.
If any <I>value</I>s are given,
they are used to modify the values of the associated namespace variables.
If a namespace variable does not exist,
it is created and optionally initialized.
<P>
A <I>name</I> argument cannot reference an element within an array.
Instead, <I>name</I> should reference the entire array,
and the initialization <I>value</I> should be left off.
After the variable has been declared,
elements within the array can be set using ordinary
<B><A HREF="../TkCmd/set.htm">set</A></B> or <B><A HREF="../TkCmd/array.htm">array</A></B> commands.
<H3><A NAME="M5">SEE ALSO</A></H3>
<B><A HREF="../TkCmd/global.htm">global</A></B>, <B><A HREF="../TkCmd/namespace.htm">namespace</A></B>, <B><A HREF="../TkCmd/upvar.htm">upvar</A></B>
<H3><A NAME="M6">KEYWORDS</A></H3>
<A href="../Keywords/G.htm#global">global</A>, <A href="../Keywords/N.htm#namespace">namespace</A>, <A href="../Keywords/P.htm#procedure">procedure</A>, <A href="../Keywords/V.htm#variable">variable</A>
<HR><PRE>
<A HREF="../copyright.htm">Copyright</A> &#169; 1993-1997 Bell Labs Innovations for Lucent Technologies
<A HREF="../copyright.htm">Copyright</A> &#169; 1997 Sun Microsystems, Inc.
<A HREF="../copyright.htm">Copyright</A> &#169; 1995-1997 Roger E. Critchlow Jr.</PRE>
</BODY></HTML>