variables
Global variables can be created in a variety of ways.
- some globals are predefined;
- some globals are created by running certain commands which
store their results in global variables;
- loop variables of DO loops and the arguments of CALL
statements are automatically declared as globals;
- global variables can also be created manually, asdescribed
below.
The easiest way to create a global of type Number, Logical or
String, is the GLOBAL statement.
Histograms and Matrices are normally created by using procedure
CALL's, such as BOOK_HISTOGRAM and BOOK_MATRIX. Since ordinary
arithmetic can be applied to both Histograms and Matrices, one
can also create them by manipulating other, already existing,
Histograms and Matrices.
The one exception to this is the creation of 1-dimensional Matrices
with the VECTOR statement. The vector can be given another shape by
a call to RESHAPE_MATRIX.
The current value of a global variable is substituted in regular
statements by enclosing a formula in terms of global variables
by curly brackets.
If the formula evaluates to a Number, Logical or String, then
the value is simply substituted. If the result is an Histogram,
then the string "Histogram" is substituted for the formula. For
1-dimensional matrices, the first portion of the matrix is
substituted but for higher dimensional matrices, the string
"n-Matrix" will appear, where n is the dimension of the matrix.
Format:
any text {formula} more text
Example:
Global a=60
Say "Tangent of {a} degrees is {tan(pi*60/180)}."
(The global variable A is assigned the value 60. In the following
SAY statement, A is converted from degrees to radians and its
tangent is displayed.
Further examples of this use of global variables can be found in
the examples given for many other commands.)
+--------------------------------------------------------------+
| Do not use curly brackets in DO, IF, CALL, PARSE and GLOBAL |
| |
| Curly brackets { } are very often mis-used. |
| |
| They should only be used in normal input statements, to |
| substitute expressions in terms of global variables in such |
| statements. |
| |
| They should not be used with the control statements IF, DO, |
| CALL, GLOBAL and PARSE. If you use { } in such statements, |
| then the contents of { } is evaluated and substituted |
| before the statement is interpreted as a control statement. |
| |
| Correct: Wrong: Would not work: |
| |
| Global sx=5 Global n=5 For i From 1 To 5 Do |
| period x {sx} For i From 1 To {n} Do For j From 1 To {i} Do |
| ... Say "j={j}" |
| Enddo Enddo |
| Enddo |
+--------------------------------------------------------------+
Global variables come in the following types:
-------------------------------------------------------------------
Type Explanation
-------------------------------------------------------------------
Undefined Declared but not used, or deleted matrix or histogram
Number A real or integer number
Logical Can be either True or False
String Character strings
Histogram 1-Dimensional histogram
Matrix n-dimensional matrices made up of numbers
-------------------------------------------------------------------
Some global variables are predefined and you may not change their
values, one global (OK) may be user redefined, but this is not
recommended:
-------------------------------------------------------------------
Global Type Explanation
-------------------------------------------------------------------
BATCH Logical TRUE if running in batch, FALSE otherwise.
INTERACT Logical TRUE if running interactively, FALSE otherwise.
MACHINE String The type of computer on which you're running.
OK Logical TRUE if last instruction was successful.
TIME_LEFT Number The amount of CPU time that remains.
-------------------------------------------------------------------
Keyword index.
Formatted on 10/11/98.