Top
Back: Procedure definition
Forward: Parameter list
FastBack: Input and output
FastForward: Libraries
Up: Procedures
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

3.7.2 Names in procedures

All variables are local to the procedure they are defined in and to the package in which the procedure is defined. 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).

To keep local variables after leaving the procedure, they have to be exported (i.e. made known) to some higher level or to some package by a command like export or exportto (see export, see exportto, see importfrom; see also see package).

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
Note that the variable result became a global variable after the execution of xxx.


Top Back: Procedure definition Forward: Parameter list FastBack: Input and output FastForward: Libraries Up: Procedures Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 3-0-1, October 2005, generated by texi2html.