Variables in Raptor

A variable can be thought of as a name associated with a value.  A variable is given a value in an Input symbol or in an Assignment symbol.  The first time a variable is given a value, certain attributes for the variable are established:

 

 

Once these attributes are established, they cannot change.  The name will always be associated with the initial type and structure.  A variable initialized as a string must always be used as a string.  A variable initialized as a one-dimensional array of numeric values cannot be changed to a scalar (single) variable later.  A program can determine the type and structure of a variable using the functions Is_String, Is_Array, Is_Number, Is_2D_Array.

 

Type of a Variable

 

The type of a variable is established when the variable is first given a value.  The type determines the operations that can be performed on the variable.  For numeric variables, those operations are fairly well-understood (see Math Operators, Math (Non-Trigonometric) Functions, and Trigonometric Functions).  The operations on strings are fewer (see String Operations).  Numeric comparisons are also familiar (see Boolean Expressions); similar comparisons are available for strings (see String Comparisons).  

 

If programs deal only with numeric data, few issues with data type arise.  When mixing the use of strings and numbers, refer to String Variables & Assignment and String vs. Numeric Input to get a full understanding of how types are initially established.

 

 

Structure of a Variable - Arrays

 

Arrays provide programs with scalability, the ability to deal simply with large amounts of data (see Array Overview).  With arrays, one name represents many variables (and their respective values, all of the same type).  Raptor supports both one-dimensional and two-dimensional arrays.  

 

If a name is to represent an array variable, it must be indexed the first time it is used.  For example, an assignment of the form values[1] <- 0 tells Raptor that values is an array.  As described in Creating Arrays, the array can later grow as new assignments are performed.  After its initialization, though, values must be treated as an array; an assignment of the form values <- 3 is not allowed.  Similarly, if a variable is initially treated as a scalar (single) value, as in grid <- 0, it cannot later be treated as an array, as in grid[3,5] <- 6.