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

Using Generic Reference Expressions

Certain expressions allow you to use generic references to a set of items or values, depending on the expression's context in an action or procedure statement. These are called generic reference expressions.

Generic reference expressions can refer to one or more items, attributes, variable or parameter values, or list or array elements in certain contexts. For instance, the generic reference expression any custom-object connected to my-valve in the antecedent of the following rule refers to a set of items:

The generic reference expression any symbol in any symbol-list in the antecedent of the following rule refers to a set of values:

To create a generic reference expression:

Including a Generic Reference Qualifier Expression

In a generic reference expression that identifies a set of items, use a generic reference qualifier expression to refer to those items with respect to their system-defined relationships with other items.

To create a generic reference qualifier expression:

For example, the antecedent of this rule specifies a generic reference expression that includes a generic reference qualifier expression connected to my-valve:

Using Quantifiers

You must prefix each generic reference expression with a G2 reserved symbol, called a quantifier. Each quantifier indicates whether the expression produces one, one and only one, at least one, or any number of items or values.

You use particular quantifiers in certain contexts, as summarized in this table:

Quantifier Meaning Context and Example
a
an

At least one
Use only in there exists expressions:
any
Zero or more
Use only in generic rules:
each
Zero or more
In expressions over a set of values, items, or attributes, use to compute a value based on the set: In expressions in procedures, use to iterate over a set of items:
every
Zero or more
In a for every expression, use to iterate over a set of items or attributes: In the consequent of a rule, causes an action to execute on every item that matches the reference: In this example, G2 iterates over all tanks in tank-list-1, and produces the truth-value true if all tanks are full.
the
One and only one
In any expression: the tank in tank-list-1 exists This expression produces the truth-value true only when there is one tank in tank-list-1.

It is possible to use the every quantifier in outer and inner statements:

When doing so, however, the second every statement cannot refer to a local variable declared in the first, and a statement such as the example here would not compile correctly.

Embedded Generic Reference Expressions

In some G2 expressions you must specify an embedded generic reference expression. In these cases, you must use a particular quantifier, not any quantifier.

For example, the there exists expression requires only the a or an quantifier for its embedded generic reference expression. This rule's antecedent tests whether any items exist that have a value other than OK in the Notes attribute:


Note: In this chapter the syntax descriptions for each expression show the required quantifier for the embedded generic reference expression, if any.

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

Copyright © 1997 Gensym Corporation, Inc.