3 Variables can be declared as either being global, local, or static.
4 Global variables are visible to all functions and on the command
5 line, and are permanent. Local variables are visible only within
6 a single function or command sequence. When the function or command
7 sequence returns, the local variables are deleted. Static variables
8 are permanent like global variables, but are only visible within the
9 same input file or function where they are defined.
11 To declare one or more variables, the 'local', 'global', or 'static'
12 keywords are used, followed by the desired list of variable names,
13 separated by commas. The definition is terminated with a semicolon.
14 Examples of declarations are:
19 static var1, var2, var3;
21 Variables may have initializations applied to them. This is done
22 by following the variable name by an equals sign and an expression.
23 Global and local variables are initialized each time that control
24 reaches them (e.g., at the entry to a function which contains them).
25 Static variables are initialized once only, at the time that control
26 first reaches them (but in future releases the time of initialization
27 may change). Unlike in C, expressions for static variables may
28 contain function calls and refer to variables. Examples of such
32 static b = a1 + sin(a2);
34 Within function declarations, all variables must be defined.
35 But on the top level command line, assignments automatically define
36 global variables as needed. For example, on the top level command
37 line, the following defines the global variable x if it had not
42 The static keyword may be used at the top level command level to
43 define a variable which is only accessible interactively, or within
44 functions defined interactively.
46 Variables have no fixed type, thus there is no need or way to
47 specify the types of variables as they are defined. Instead, the
48 types of variables change as they are assigned to or are specified
49 in special statements such as 'mat' and 'obj'. When a variable is
50 first defined using 'local', 'global', or 'static', it has the
53 If a procedure defines a local or static variable name which matches
54 a global variable name, or has a parameter name which matches a
55 global variable name, then the local variable or parameter takes
56 precedence within that procedure, and the global variable is not
59 The MAT and OBJ keywords may be used within a declaration statement
60 in order to initially define variables as that type. Initialization
61 of these variables are also allowed. Examples of such declarations
64 static mat table[3] = {5, 6, 7};
65 local obj point p1, p2;
67 There are no pointers in the calculator language, thus all
68 arguments to user-defined functions are normally passed by value.
69 This is true even for matrices, strings, and lists. In order
70 to circumvent this, the '&' operator is allowed before a variable
71 when it is an argument to a function. When this is done, the
72 address of the variable is passed to the function instead of its
73 value. This is true no matter what the type of the variable is.
74 This allows for fast calls of functions when the passed variable
75 is huge (such as a large array). However, the passed variable can
76 then be changed by the function if the parameter is assigned into.
77 The function being called does not need to know if the variable
78 is being passed by value or by address.
80 Built-in functions and object functions always accept their
81 arguments as addresses, thus there is no need to use '&' when
82 calling built-in functions.