Closed phgachoud closed 4 years ago
In lists the cursor can be before
(index = 0) or after
(index = count + 1). This is true for arrayed list as well (which is a list). So in this context, a valid index does not mean that there is a item available at that cursor position. That's why feature item
does not use valid_index
in its precondition. An arrayed list is not an array, it's a list. So valid_index
is about the list cursor, not about availability of items in an array. The precondition of item
comes from DS_INDEXABLE, where there is no notion of before
or after
. Perhaps what is missing is a valid_index
routine in DS_INDEXABLE. But it is not the same valid_index
as in DS_LIST. So in DS_ARRAYED_LIST there should be two different routines: valid_item_index
(from DS_INDEXABLE.valid_index) and valid_cursor_index
(from DS_LIST.valid_index). But for backward compatibility we have to keep valid_index
in DS_ARRAYED_LIST with the implementation of DS_LIST.
Thx for your explanation of the implementation and implications, I'd have to say that I still miss some function to check if I can call item with a particular index. So my workaround is
if content.valid_index (a_col_index) and a_col_index >= 1 and a_col_index <= count then
Result := content.item (a_col_index)
end
Don't know if you want me to close the issue.
The following code should be enough, as per the precondition:
if a_col_index >= 1 and a_col_index <= a_list.count then
Result := a_list.item (a_col_index)
end
The following code should be enough, as per the precondition:
if a_col_index >= 1 and a_col_index <= a_list.count then Result := a_list.item (a_col_index) end
Closing the issue, could be an improvment
Ran into an issue with valid_index precondition using a DS_ARRAYED_LIST. It seems that the valid_index in inherited from DS_LIST and not implemented again. So my question has 2 wings:
valid_index
precondition toat alias "@", item (i: INTEGER): G
FROM DS_LIST
SUGGESTED
I use it with content:
DS_ARRAYED_LIST
.content.valid_index(0)
returnsTrue
as it shouldn't