| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (8 out of 13)

Using Connection Expressions

G2 provides a powerful language for referring to connections and objects connected to other objects. The expressions you use with connections make it possible, for example, to write generic rules that refer to any class connected to any object.

In all connection expressions, you can refer directly to the object (if appropriate), to a port name on the object (the portname), or to a direction (an input to, an input of, an output of) of the connection.

Expressions do not exist for referencing a connection as an item upon a workspace such as:

While the Text Editor lets you enter such statements, they are ineffective and always return false, since connections cannot exist as autonomous items upon a workspace.


Note: G2 ignores junction blocks when looking for connected objects unless you refer to the, any, or every junction-block (or a subclass of JUNCTION-BLOCK) connected to an object or connection within the expression.

These generic reference expressions reference items that are connected to other items or that are attached to particular connections.

Referring to Connected Items

G2 can iterate over one or multiple items that are connected.

With the the quantifier, this generic reference expression produces the one and only item of the specified class that is connected in any way to the specified item. With the any quantifier, this expression produces the set of items of the specified class that are connected in any way to the specified item.

To refer to items connected to other items:


Referring to Input or Output Stubs

Whenever stubs are defined with a direction (input, output), you can refer to them using the flow direction (input to, input of, or output of):

With the the quantifier, this generic reference expression produces the one and only item of the specified class that is connected at any input stub or output stub of the specified item. With the any quantifier, this expression produces the set of items of the specified class that are connected at any input or output stub of the specified item. (The input to and input of phrases are equivalent; use one or the other to improve the readability of your code.)

To refer to objects connected at a particular direction:


Input and output stubs of objects are described in Specifying Connection Stubs.

Referring to Port Names

The place at which a connection attaches to an icon is called a port. You can give these locations names by defining stubs with port names in the object definition.

With the the quantifier, this generic reference expression produces the one and only item of the specified class that is connected at a named port or at any input stub or output stub of the specified object. With the any quantifier, this expression produces the set of items of the specified class that are connected at a named port or at any input or output stub of the specified object. (The input to and input of phrases are equivalent; use one or the other to improve the readability of your code.)

To refer to connected objects using a port name:


For example:

This generic if rule checks whether the Status attribute contains the symbol blocked for any valve that is connected to any tank at its water-input-for port. Input and output stubs of objects are described in Specifying Connection Stubs.


Tip: This example illustrates a naming convention for portnames in an object definition: include a preposition as a name suffix. (water-input-for is the portname.) This makes the expression easier to read by G2 developers, knowledge engineers, and application users.

Referring to the End of a Connection

G2 can iterate over any specified object connected to the (or an) input end of, output end of, or either end of a connection.

With the the quantifier, this generic reference expression produces the one and only item of the specified class that is at an input end, output end, or either end of the specified connection. With the any quantifier, this expression produces the set of items of the specified class that is at an input end, output end, or either end of the specified connection.

To refer to objects using the connected direction only, without a connected at statement:


Referring to the Connection Class

G2 can iterate over any item that uses a specific connection class.

With the the quantifier, this generic reference expression produces the one and only connection class that is connected in any way to the specified item. With the any quantifier, this expression produces the set of connections of the specified class that are connected in any way to the specified items.

To refer to a specific connection class:


| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (8 out of 13)

Copyright © 1997 Gensym Corporation, Inc.