RATS 10.1
RATS 10.1

Instructions /

DECLARE Instruction

Home Page

← Previous Next →

DECLARE  datatype  list of names (dimension fields optional)

Declares data types of global variables; arrays can be dimensioned in the process. Use LOCAL to declare local variables within a PROCEDURE.

 

For arrays, you can either specify the array dimensions in the DECLARE statement (by enclosing the dimensions in parentheses after the array name), or using the separate DIMENSION instruction.

Parameters

datatype

The data type you want to assign to the listed variables. For instance, REAL, RECTANGULAR, or VECTOR[SERIES].

list of names

The list of variables that will have datatype. Separate the names with blanks. Symbolic names must be unique—if you attempt to assign a new type to a name already in use (by you or by RATS) you will get an error message.

 

You can also set the dimensions of an array at the time you DECLARE it, by using a dimension field instead of simply the variable name­—just provide the dimensions for the array in parentheses immediately after the variable name. Arrays can also be dimensioned later (or redimensioned) using DIMENSION.

Description

In most situations, you do not need to declare a variable name before using—RATS will determine what type of variable is needed from the context. However:

You will probably have to DECLARE any array whose values will be set in a COMPUTE instruction, to be sure that you get the array type that you want.

Any “non-standard” aggregate type, such as a VECTOR[SYMMETRIC] or FRML[COMPLEX] will need a DECLARE.

Any variable or array which you initialize with INPUT or ENTER needs DECLARE, since those instructions can handle a number of variable types.

 

You can, however, often dispense with a separate DECLARE instruction by putting the type specification directly into the instruction. For instance,

 

compute [symmetric] s=tr(a)*a

 

can be used instead of

 

declare symmetric s

compute s=tr(a)*a

 

Variables introduced with DECLARE (as well as any that are created from context by a RATS instruction) have global scope. They can be used anywhere later on in the program, and in procedures. You cannot change the type of such a variable later in the program.

Data Types Available

Basic types

INTEGER, REAL, COMPLEX, LABEL, STRING, EQUATION, MODEL, PARMSET, and REPORT.

 

Aggregate types

VECTOR, SYMMETRIC, RECTANGULAR, PACKED, SERIES, FRML, HASH, and LIST.

 

The aggregate types can be layered as deep as you need. You can have a VECTOR of FRMLs (written VECTOR[FRML]), a RECTANGULAR of SERIES of VECTORS (written as RECTANGULAR[SERIES[VECTOR]]), and so on. These are all for real numbers by default, but you create things like a VECTOR of COMPLEX numbers (VECTOR[COMPLEX]) or a FRML of STRINGs (FRML[STRING]).

Examples

declare real a b c d e

declare integer count

declare vector[integer] counters(10)

declare symm s(nvar,nvar)                                       

 

The statements above declare the following variables:

 

A through E as scalar real variables.

COUNT as a scalar integer variable.

COUNTERS as a vector of integers. COUNTERS is also dimensioned to have 10 elements (referenced as element 1 through element 10).

S as a symmetric array, with dimensions NVAR by NVAR (where NVAR has been set previously to some value)

 

 

declare label product

declare vector[label]  product_codes(25)

 

declares PRODUCT as a label variable (that is, it can contain a single LABEL of up to 16 characters), and PRODUCT_CODES as a VECTOR of LABELS with 25 elements (each element will contain a single LABEL).

Deleting Declared Variables

While there is no instruction which can “undeclare” a variable, you can manually delete variables from memory by using the View—All Symbols operation, selecting the variable(s), and doing Edit–Delete (or Right+Click then Delete). This can be handy if you are writing a program and get a type wrong.

 

Because of their special nature, you cannot delete SERIES except by doing File–Clear Memory, which clears everything.

 


Copyright © 2025 Thomas A. Doan