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

Referring to Other Item Knowledge

These expressions refer to other knowledge contained in or associated with an item, but not found in the item's attributes.

Referring to the Name and Class

To refer to the name of an item:

With the the quantifier, this generic reference expression produces the first symbol in the Names attribute of the specified item. With the any quantifier, this expression produces the set of symbols that name the specified item. For example:

To refer to the class of an item:

This expression produces a symbol that names the class of the specified item. For example:

To refer to an item that is an instance of a particular class:

This expression produces a truth-value that indicates whether the specified item is an instance of the class (or any of its subclasses) named in the specified symbolic expression. For example:

Referring to the Superior Item

To refer to the item superior to a workspace:

This expression produces the superior item of the specified class of a workspace that is also a subworkspace. For example:

If you specify a top-level workspace as kb-workspace, G2 signals an error. To prevent this, use this expression with the exists expression, as follows:

This generic if rule identifies each workspace that has a superior item and, for each that does and whose name also is help, sets the Purpose attribute of its superior item to the symbol help-schematic.

To refer to the object superior to an object contained in an attribute:

For an object that is the attribute value of an object of a user-defined class, this expression produces the object that is its superior item. For example:

If you specify an object that has no superior item, G2 signals an error. To prevent this, use this expression with the exists expression, as follows:

This generic if rule identifies each custom-object that has superior item and, for each that does and whose name also is help, sets its Status attribute to the symbol ok.

Referring to The Workspaces Associated With an Item

Expressions that return the workspace of an item are described in Expressions that Refer to KB Workspaces.

Referring to The Relationships of an Item

Each item contains information about the relationships in which it is participating. Such knowledge is not visible in an attribute table, but can be obtained programmatically.

To refer to the relationships of an item:

As an example, in a KB that has two relation definitions, married-to and a-son-of, you could create relations between objects with the following conclude actions:

Such actions result in the object edna having two relationships with two separate objects, bill and george. A reference to:

returns a sequence of structures as follows:


If an item is not participating in any relationships, G2 returns the symbol none.

Referring to The Size of an Item

To refer to the height of an item:

This expression produces the height in workspace units of the specified item's representation. You can apply this expression to items with an iconic representation as well as to items with other representations. For a description of the representations of items, see Item Representation.

An item's visible icon might not be as high as the rectangular space provided for it; therefore, the height in workspace units produced by this expression might be greater than the visible icon's height. For example:

To refer to the width of an item:

This expression produces the width in workspace units of the specified item's representation. You can apply this expression to items with an iconic representation as well as to items with other representations. For a description of the representations of items, see Item Representation.

An item's visible icon might not be as wide as the rectangular space provided for it; therefore, the width in workspace units produced by this expression might be greater than the visible icon's width. For example:

Referring to Degrees of Rotation

To refer to the degrees of rotation of an item's representation:

This expression produces the number of degrees of rotation (0, 90, 180, or 270) for the specified item. For example:

Not all items are rotatable. See the description of the rotate action in rotate.

Referring to the Position of an Item

To refer to the item-x-position of an item:

This expression produces the horizontal offset in workspace units between the center of the specified item's representation and its parent workspace's origin. A positive integer indicates a position to the right of the origin, and a negative integer indicates a position to the left of the origin. For example:

To refer to the item-y-position of an item:

This expression produces the vertical offset in workspace units between the center of the specified item's representation and its parent workspace's origin. A positive integer indicates a position above the origin, and a negative integer indicates a position below the origin. For example:

To refer to the item nearest to another item:

With the the quantifier or the any quantifier, this generic reference expression produces the one item of the specified class (or any of its subclasses) that is on the same workspace as, and the fewest workspace units from, the specified item. The two specified items need not be connected.

G2 calculates the proximity of a pair of items as the distance in workspace units between the centers of their respective representations. In the following example, the readout table indicates that item B is nearest to item C, even though the top edge of the rule appears nearer to the item B than the left edge of item C.


To refer to the distance between items:

This expression produces the number of workspace units of distance between the centers of the representations of the two specified items. The two items must be upon the same KB workspace, else G2 signals an error. The two items need not be connected.

The next figure shows two readout tables that use this expression to display the distance between items X and Y and between items X and Z.


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

Copyright © 1997 Gensym Corporation, Inc.