Chapter 3 The Application Description Language

3.26 Scope

A scope is a region of a program in which a variable or set of variables has definition. In AM2, each class (see Section 3.20, "Class Definition" page 40) and method definition (see Section 3.21, "Method Definition" page 41) as well as each initializor block forms a scope (see Section 3.25, "Object Initialization" page 49).

AM2 scopes are of two kinds, transparent and opaque. The variables defined in an enclosing scope are also visible in an enclosed transparent scope. In an enclosed opaque scope, they are not. Method definitions form transparent scopes and class definitions and initializor blocks opaque ones. Class definitions are visible in the current scope and in all enclosed transparent scopes as you would expect. Classes defined at the top level of an application are also visible everywhere.

You can access members and variables from the enclosed scope using the syntax for object member reference if an enclosed scope has been named (see Section 3.19, "Object Member Reference" page 38). Occasionally, you may need to refer to a global object, although avoid doing so wherever possible. Consider two application modules that are never simultaneously visible, but which each possess a button that puts its own module to sleep and calls up the other. These would normally be implemented as instances of module classes. The button actions for each must be able to send a wake up message to the other module, and must therefore be able to see the name of the other module in the enclosing application scope.

The ADL, therefore, allows you to specify that a symbol has one of two kinds of scoping:

The keyword global must accompany and precede a type specifier (e.g., string) or class name in a declaration. If the declaration refers to a global instance of an anonymous class, there is no class name to use as the type specifier. In this case, you can use the key word anonymous as a type specifier. You can combine global scope with the ( . ) or ( -> ) operators. The global declaration merely designates where to look for the left-most member of a (.) or (->) chain.

Note that an enclosed scope cannot refer to an enclosing scope without a global declaration. Programming languages typically make the identifiers of an enclosing scope visible to an enclosed scope. Our aim here is to increase the modularity of the ADL by minimizing name clashes. This should encourage the reuse of interface and module templates and the development of template libraries. An enclosing scope can make one of its members visible inside an enclosed opaque scope by passing a handle to the member as an argument to a custom constructor.
(see Section 3.17, "Dynamic Objects and Storage Management" page 36).
Scope Example
class Aclass

{

XFbutton aButton;

. . .

};

class Bclass

{

on Foo

{

global Aclass aInstance;

aInstance.aButton.width = 40;

}

};

Aclass aInstance;

Bclass bInstance;


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker