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

The List and Array Classes

Within the system-defined class hierarchy, nine system-defined parallel subclasses for lists and arrays exist, each capable of containing these elements:

These list and array classes... Can have these elements...
G2-LIST or G2-ARRAY
Items and values
VALUE-LIST or VALUE-ARRAY
Values of any G2 type, but no items
ITEM-LIST or ITEM-ARRAY
Items
SYMBOL-LIST or SYMBOL-ARRAY
Symbolic values
TEXT-LIST or TEXT-ARRAY
Text values
TRUTH-VALUE-LIST or
TRUTH-VALUE-ARRAY

Truth values
QUANTITY-LIST or
QUANTITY-ARRAY

Float or integer values
FLOAT-LIST or FLOAT-ARRAY
Float values
INTEGER-LIST or INTEGER-ARRAY
Integer values

To see the class hierarchy of lists and arrays using Inspect, enter:

or

Creating Subclasses of Lists and Arrays

You can create subclasses directly from G2-LIST and G2-ARRAY, and from any of their subclasses as you would any other user-defined class.

When creating a new list or array class, always use the most specific type possible for your requirements.

You can also create your own set of list or array classes in which membership is permanent by default, by specifying the Array-is-permanent or List-is-permanent as yes in the Attribute-initializations attribute of the class definition.

For classes with VALUE-ARRAY as a direct superior class, you can include values of any type (float, integer, symbol, text, and truth-value, but not items), as the following example indicates:


Notice that you must precede symbolic values (me, you and us in this example) with the statement the symbol, as described in Specifying Symbolic Initial Values in Arrays.

For new classes with ITEM-LIST or ITEM-ARRAY as a direct superior class, the elements of the list or array can be generic or specific to a particular item class. To create a list or array of a specific item class, use an class definition to create a subclass of ITEM-LIST or ITEM-ARRAY.

Within the class definition, you can use the Attribute-initializations attribute to specify a particular class of items for the Element-type attribute. When you specify a class name for the Element-type attribute, all elements within the list or array must be instances of that class.

For a complete description of creating subclasses, see Creating Object Classes.

Class-Specific Attributes

These are the class-specific attributes of lists and arrays:

Attribute Description
Array-length
Arrays only. Specifies the number of elements that the array contains.
Allowable values:
Minimum:
Maximum:

0
523,264

Default value:
0




Element-type
Specifies the type or class of the list or array elements.
Allowable values:
For a list of allowable type or classes for lists and arrays, see The List and Array Classes.
Default value:
For a list of type or classes for lists and arrays, see The List and Array Classes.



Allow-duplicate-elements?
Lists only. Controls whether duplicates of the same element can exist in a list.
Allowable values:
{yes | no}

Default value:
yes




Initial-values
Arrays only. Specifies the initial-value for each array element.
Allowable values:
See Providing Initial Values for Array Elements
Default value:
See Providing Initial Values for Array Elements



Array-is-permanent
Arrays only. Specifies whether the elements of the array are maintained as permanent KB knowledge.
Allowable values:
yes or no
Default value:
no



List-is-permanent
Lists only. Specifies whether the elements of the lists are maintained as permanent KB knowledge.
Allowable values:
yes or no
Default value
no


Note: G2 permits the use of lists and arrays of the non-specific type quantity. For efficiency, we recommend that you use an item of specific type (integer or float) whenever possible.

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

Copyright © 1997 Gensym Corporation, Inc.