3.7.2 Names in procedures
-------------------------

All variables are local to the procedure they are defined in.
Locally defined variables cannot interfere with names in other
procedures and are automatically deleted after leaving
the procedure.

Internally, local variables are stored using the nesting level. A variable
is said to have nesting level 1, if it is local to a procedure that was
called interactively, nesting level 2, if it is local to a procedure that
was called by a procedure of nesting level 1 etc. listvar() also
displays the nesting level, nesting level 0 is used for global objects
(see listvar). A ring may be 'moved up' by one nesting level
with keepring (see keepring). All variables living in that
ring are moved together with that ring.

To keep local variables after leaving the procedure, they have to be
exported (i.e. made known) to some higher level by the export
command (see export).

Example:
proc xxx
{
  int k=4;        //defines a local variable k
  int result=k+2;
  export(result);  //defines the global variable "result".
}
xxx();
listvar(all);
==> // result               [0]  int 6
==> // LIB                  [0]  string standard.lib
Note that the variable result became a global variable after the
execution of xxx.

<font size="-1">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; User manual for <a href="http://www.singular.uni-kl.de/"><i>Singular</i></a> version 2-0-4, October 2002,
generated by <a href="http://www.gnu.org/software/texinfo/"><i>texi2html</i></a>.
</font>

</body>
</html>
