| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (9 out of 16)

Using Local Names in Expressions

You can use a local name to simplify some expressions, including generic reference expressions. For example, using two local names, V and T, you can recode this expression:

as this expression:

You can use local names implicitly and explicitly. You can also use existing classes or attribute names as local names.

Implicit Use

You can implicitly use local names in expressions to simplify the expression. A local name provides a quick method of referring to the value produced by an expression, such as:

In this example, you use the local name T1 to refer to the temperature of tank-1.

An implicit local name must be unique to the expression in which it appears. The scope of an implicit local name is also limited to the expression in which it appears. Thus, you can use the same implicit local name in different expressions in the same rule, action, or procedure statement.

Explicit Use

In procedures and methods you can also use declared local names. In the local name declaration section of the procedure, you must declare each local name that receives an assignment (in a = statement) within that procedure.

This example demonstrates how a procedure can use both explicit and implicit local names:


Tip: Declaring a local name in a procedure allows G2 to compile each statement that uses the name more efficiently.

Class or Attribute Name Use

You can use a class name or attribute name as a local name in a rule, in which case you must use the the quantifier. When you first refer to an attribute in a rule, you must identify the item of the attribute. When you make additional references to that same attribute, however, you need not identify the item, because the item is clear from the first reference.

For example, this rule uses the name of the Temperature attribute of the Tank class as a local name:

The second reference to the Temperature attribute omits the reference to tank-1. G2 assumes that the reference the temperature still refers to the temperature of tank-1.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (9 out of 16)

Copyright © 1997 Gensym Corporation, Inc.