Home Online Manual
Top
Back: Help string
Forward: Procedure-specific commands
FastBack: Input and output
FastForward: Libraries
Up: Procedures
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

3.7.4 Names in procedures

  • All variables defined inside a procedure are local to the procedure and their names cannot interfere with names in other procedures. Without further action, they are automatically deleted after leaving the procedure.
  • To keep local variables and their value after leaving the procedure, they have to be exported (i.e. made global) by a command like export or exportto (see export,see exportto, see importfrom; see package). To return the value of a local variable, use the return command (see return).

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.