To create a list or array class:
Choose:
KB Workspace > New Object >g2-listorg2-array
choose a class submenu.
Array-length attribute lets you specify how many elements the array contains. The default value is 0. The array length should correspond to the number of initial values that you provide. If the number of initial values differs from the length of the array, G2 populates the array with the initial value for the array type.
Element-type attribute defines the class or type of the list or array. You cannot change the value of this attribute, unless you modify the Attribute-initializations attribute of user-defined class of ITEM-LIST or ITEM-ARRAY. The valid types or classes for lists and arrays are listed in the section The List and Array Classes.
Allowing Duplicate List Elements
The Allow-duplicate-elements? list attribute determines whether a list permits duplicate elements. yes value to no disallows duplicate list elements in the list.
Note: Inserting elements into a list that does not allow duplicate elements takes longer than into a list that allows duplicates.
For information on the backward compatibility feature for inserting duplicate elements into lists, see Ignoring Duplicate List Element Error.
Providing Initial Values for Array Elements
The Initial-values attribute specifies an initial value for each array element. The number of initial values should correspond with the array length or should contain one initial value. G2-ARRAYs and ITEM-ARRAYs, you can specify item names as the initial values.
Elements in arrays must always have a value, except for
ITEM-ARRAYs and G2-ARRAYs, which can have an initial value of none. If you do not specify initial values for the array, G2 provides initial values as follows.
| Array Type | Default |
|---|---|
G2-ARRAY
|
none
|
VALUE-ARRAY
|
0.0
|
ITEM-ARRAY
|
none
|
SYMBOL ARRAY
|
g2
|
TEXT-ARRAY
|
""
|
TRUTH-VALUE-ARRAY
|
false
|
QUANTITY-ARRAY
|
0.0
|
FLOAT-ARRAY
|
0.0
|
INTEGER-ARRAY
|
0
|
G2-ARRAY Initial Values Conflict
You can set the initial values of a G2-ARRAY subclass in the Attribute-initializations attribute of its class definition.
Initial-values attribute specifies only one value, all elements receive that value.
Notes attribute of the instance.
Initial-values attribute has a count that does not match the Array-length attribute, G2 assigns the initial value for that array class to each element.
ITEM-ARRAY conflict with the Element-type of the array, G2 assigns no-item to the element in conflict.
G2-ARRAY
VALUE-ARRAY
SYMBOL-ARRAY
Attribute-initializations attribute of a class definition, the syntax differs slightly depending on the array class. For
G2-ARRAY and VALUE-ARRAY classes, precede symbolic names with the symbol. For SYMBOL-ARRAYs, enter only the symbolic name, as follows:
| For this array class... | Enter symbolic values like this... |
|---|---|
|
the symbol cold, the symbol warm, the symbol hot
|
|
cold, warm, hot
|
Using Permanent-Membership Lists and Arrays
If the List-is-permanent attribute of a list, or the Array-is-permanent attribute of an array is no (the default), membership in the list or array is transient:
List-is-permanent or Array-is-permanent attribute to yes. A permanent-membership list or array is unaffected by resetting or restarting G2, and by saving and loading the KB, provided that all member items have the properties described in Complying to Permanent Membership.
Levels of Permanency in Lists and Arrays
The List-is-permanent and Array-is-permanent attributes do not determine whether the list or array item is itself permanent, and do not determine whether any items referenced as elements are permanent. The attributes control only whether membership is permanent.
INTEGER-ARRAY, the G2 supplies an initial value of 0; for a symbol array, G2 supplies the symbol g2. When a permanent-membership array is first activated, G2 initializes it with either its default or user-provided initial values. The array then maintains initial or changed values throughout KB Restart and Reset operations, no further initialization takes place, and the values are saved in the KB.
For an item to remain in a permanent-membership list or array when a KB is saved and reloaded, the item must be uniquely identifiable. Otherwise G2 will not be able to identify the item referenced in the list or array and restore the reference to it.
An item is uniquely identifiable if any of the following is true:
unique-identification mixin class as one of the direct superior classes. G2 then includes a UUID attribute and automatically generates a UUID value when an instance is created. For more information about UUIDs, see Universal Unique Identifiers.
Failure of an item to comply to permanent membership does not preclude its inclusion in a permanent-membership list or array. G2 does not signal an error if you populate permanent-membership list and array elements with non-compliant items, and does not post any messages if their non-compliance causes G2 to remove them from the list or array.
Maintaining Permanent-Membership Lists and Arrays
It is the KB developer's responsibility to monitor and maintain the integrity of permanent-membership lists and arrays. After adding items to them, G2 does not monitor members for conformance to permanent membership, nor does it inform you if it is unable to save any list or array item as a permanent member during a KB save or reset operation.
none.
List-is-permanent or Array-is-permanent attribute to no.
This is how G2 handles rendezvous failures: