#209 List collection index usage

v3.1
closed
David Ashley
5
2012-08-14
2006-11-27
Geoff Stevens
No

The current List collection documentation could be improved by explicitly stating that the indices returned by the Insert method are not array-type sequential indices, but are more like handles.

The current statement "Inserting an item in the list at position index will cause the items in the list after position index to have their indexes modified by the list object." could be interpreted to mean that inserting an item at the head (for example) causes all subsequent indices to be incremented to maintain an array-like index. This is not the case.

An illustration:

/ /
list = .list~new

index = list~insert('first', .nil)
say index
index = list~insert('second', .nil)
say index

say 'by index:'
do j = 0 to list~items-1
say list[j]
end
say ' '

say 'by ordered iteration:'
do i over list
say i
end
/ /

produces the output:

0
1
by index:
first
second

ordered iteration:
second
first

Discussion

  • David Ashley
    David Ashley
    2007-04-15

    Logged In: YES
    user_id=931756
    Originator: NO

    I added a note to the List class INSERT method docs to explain that indexes are internal handles not available to the programmer. SVN revision 297.

    This will appear in the final 3.1.2 docs.

     


Anonymous


Cancel   Add attachments