Variables and Declarations



next up previous contents index
Next: Equates Up: ScopesDeclarations, and Previous: Scope Rules

Variables and Declarations

Objects are the fundamental runtime entities in Theta. Variables are a way of denoting or naming objects.

Declarations introduce new variables. The scope of a variable is from its declaration to the end of the scoping unit containing the declaration. Hence, variables must be declared before use.

A variable has two properties: its type (which determines what can be done with it) and the object it denotes, if any. A variable is said to be uninitialized if it does not refer to any object. An attempt to use an uninitialized variable at runtime causes the exception (8.14) "failure(uninitialized variable)" to be raised.

A declaration without initialization just introduces some new, uninitialized variables:

        <decl> -> <idn_list> ":" <type_designator>
This statement introduces one or more new variables of the specified type. The following are examples of legal declarations:
x, y: int            % declare two integer variables
parts: set[part]     % declare a set[part] variable

As discussed in the next chapter, new variables can be declared and initialized at the same time, in an assignment statement (5.2.1).



theta-questions@lcs.mit.edu