Lists (SDL script)
This topic applies to TDK SDL script extensions. For more information, see Overview of SDL script extensions for TDK (SDL script).
SDL Script Extensions for TDK:
%list AtrList, OpList
%for %c->Attribute $ Put the current object's Attributes into a list
AtrList = AtrList + %c
%endfor

$ Exactly as above, put Operations into a list, noticeably faster:
OpList = %c->Operation

$ Again, using %add (faster than "+", slower than 'MyList = OtherList':
%list AtrList2
%for %c->Attribute
%add AtrList2, %c
%endfor

$ Lists can be ordered on a key. Key can be %string, %numeric or %object type
%list OrderedAtrList
%for %c->Attribute $ Order attributes on name
%add OrderedAtrList, %c, %c:Name
%endfor
%for OrderedAtrList $ Iterates elements in key order
%m %blue %ct
%endfor
$ Extracting objects form a list:
A = %getat (AtrList, 3) $ Returns the 4th attribute from the list
B = %getat (OrderedAtrList, 3) $ As above, returns the 4th attribute from the list
C = %getkey (OrderedAtrList, "Attribute2") $ Returns the item having key="Attribute2"
$ Returns a sublist with 4th and 5th elements, note last index is "the first excluded"
L = %getatinterval (OrderedAtrList, 3, 5)
L = %getatinterval (OrderedAtrList, 3) $ As above, since 4th to the last element included
$ Returns a sublist with attributes keyed since "Bxxx..." to "MyAtr" (latter excluded)
L = %getkeyinterval (OrderedAtrList, "B", "MyAtr")
L = %getkeyinterval (OrderedAtrList, "B") $ As above, since "Bxxx..." to the end of the list
$ Returns the elements stereotyped with "C++ Attribute"
L = %getstereotyped (AtrList, "C++ Attribute")
$ Returns the elements having property "Access" set to "Public"
L = %getwithproperty (AtrList, "Access", "Public")

$ Inserting elements into a (non ordered) list
%insertbefore AtrList, MyObject, 2 $ Inserts MyObject before the 3rd element
%insert AtrList, MyObject, 2 $ Exactly as above ('before' is optional)
%insertafter AtrList, MyObject, 2 $ Inserts MyObject after the 3rd element
$ Removing elements from a list (ordered or not)
%remove AtrList, MyObject
AtrList = AtrList – MyObject $ Equivalent to the above, slower

$ All the above can have an object's association subject, e.g.:
A = %getat (%c->Attribute, 3) $ Returns the 4th attribute of %c from the list
$ Adds an element to the Attribute association of MyClass
%add MyClass->Attribute, MyObject

MyList = %null $ Empty a list

Lists can be ordered or unordered. An empty list is the only list that is both ordered and unordered.
After %add List, Object, KeyExpr is executed, the List becomes ordered and subsequent operations take into account that it has a key, for example, %add List, O2 would fail at runtime (because it does not specify a key).
Combining two A and B lists together with '+', '*' and '-' operators returns:
An ordered list if both A and B are ordered
An unordered list otherwise
The same object instance can be added to the same list more than once. When iterated or accessed, the list will return that object several times (possibly with different keys if the list is ordered)
There are several ways for inserting and extracting elements, see the examples above.
Was this helpful?