In contrast, you can create and (in most cases) modify Global variables. There are many methods to create them:
Also some global variables are defined by the program:
Examples:
Global a_1 = 5 Global abc = `This is a string` Global v=row(20)
Although permitted, it is not advisable to force variable names to contain lower case characters as in the following:
// Not recommended Global "Abc" 123
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 a 1-dimensional Matrix, 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.
Curly brackets { } are very often misused, in particular they should never be used in Do loops, in the conditions of If_lines and If_blocks, in the arguments of procedure Calls, in Parse and Global statements.
The contents of { } is evaluated and substituted before the statement is interpreted, while you would probably expect evaluation to happen only when the control statements are executed. For an overview of the use of round, square and curly brackets.
Format:
any text {formula} more text
Example:
Global a=60 Say "Tangent of {a} degrees is {tan(pi*a/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.
// What one should not do Global n=5 For i From 1 To 5 Do For i From 1 To {n} Do For j From 1 To {i} Do ... Say "j={j}" Enddo Enddo Enddo
The example on the left would still work if the value of n doesn't change during execution, the example on the right would fail. A priori, I is not defined at the time the loop on J is read. If it is, then the loop on J would be executed a fixed number of times that has no relation with the value of I in the outer loop.
Garfield variables know their own type. Garfield takes care that a version of the operators and the functions appropriate for the given data type or combination of data types is called. The type of the argument propagates to the result for most operators and functions.
Global variables come in the following types:
Type | Explanation | Mode |
---|---|---|
Undefined | Declared but not initialised | 0 |
String | Character strings | 1 |
Number | A real or integer number | 2 |
Logical | Can be either True or False | 3 |
Histogram | 1-Dimensional histogram | 4 |
Matrix | n-dimensional matrices made up of numbers | 5 |
The mode is a numeric equivalent of the type, the mode is used only internally for quick reference.
Additional information on:
The value of Numbers and Logicals is stored directly in R, while for Histograms, Matrices and Strings a reference number is kept in R.
Each element of R has type information attached to it.
All R's from R(0) downwards are assumed to be constants that are not affected by the execution of the instruction list.
Although changing the values of the registers R(0) to R(-6) is not by itself prevented, the "jump always" code will for instance not work if R(-1) is set to something else than the value\ 1. Similar trouble can arise from changing the other constants in this range.
The space below R(-7) can be used for constants present in user entry points. These constants are deleted when the list is deleted with which they are associated.
The values of the constants which can be used in all lists are:
Location | Name | Value | Type |
---|---|---|---|
R(0) |
0 |
0 | Number |
R(-1) |
1 |
1 | Number |
R(-2) |
2 |
2 | Number |
R(-3) |
PI |
3.14159265 | Number |
R(-4) |
FALSE |
False | Logical |
R(-5) |
TRUE |
True | Logical |
R(-6) |
NILL |
Nill | Undefined |
Notes:
Global | Type | Explanation |
---|---|---|
BATCH |
Logical | True if running in batch, False otherwise. |
FRAME |
Number | Sequential number of the plot frame |
INPUT |
String | Name of the current input stream. |
INTERACT |
Logical | True if running interactively, False otherwise. |
MACHINE |
String | The type of computer on which you're running. |
OK |
Logical | True if last algebra instruction was successful. |
OUTPUT |
String | Name of the current output stream. |
TIME_LEFT |
Number | The amount of CPU time that remains [sec]. |
X |
Number | Used for fitting |
Additional information on:
Formatted on 21/01/18 at 16:55.