|Top Previous Next|
Intrinsics are built-in subroutines that do a variety of operations, such as input and output, and math functions. There are 79 intrinsics in the run-time code (NATIVE).
An intrinsic, like any named thing, must be declared before it can be used. When an intrinsic is declared, a name is given to its number. The general form of an intrinsic declaration is:
code TYPE NAME(COMMENT) = INTEGER, ... NAME(COMMENT) = INTEGER;
Here are some examples:
code Ran=1, Text=12;
code real Sin=56, Cos=60;
Intrinsics can be given any name, but the established names are usually preferred.
Since some intrinsics are used as functions, and since the compiler must distinguish between integer and real functions, an intrinsic declaration includes an optional type specifier. This specifier works the same way as for function declarations except that it defines the data type of all the names following the declaration. In the example, Sin and Cos are trig functions that return real values.
An intrinsic call is identical to a procedure or function call. Arguments, if any, are placed between parentheses immediately following the intrinsic name.
Here are some examples of intrinsic calls:
Height:= Sin(Angle) * 10.0;
The first example sends the values 20 and 12 to the cursor positioning intrinsic. In the second example, a random number between 0 and 99 (inclusive) is assigned to the variable "Number". The last example computes the sine of Angle, multiplies it by 10, and stores the result in Height.
Some intrinsics return a value while others do not. Intrinsics that return a value must be used as functions (factors), not as statements, otherwise a run-time error occurs. Conversely, an intrinsic that does not return a value must not be used as a function.
The following is an example of the incorrect use of intrinsics. This statement is illegal and causes a run-time error when it executes:
for I:= 10, 100 do Ran(I); \A bad statement
The error occurs because the random-number intrinsic returns a value that is not used.