Call append with manifest arrays on some container classes
Consider this code fragment:
a_list: LINKED_LIST[STRING] ... a_list.append (<< "one", "two", "three">>)
This fails with a compilation error because {LINKED_LIST}.append only takes objects of type SEQUENCE[G], yet an array does not conform to type SEQUENCE. And in fact, I don't see any easy way of getting a manifest array into a SEQUENCE. For example, I can't say:
a_list.append ((<< "one", "two", "three">>).as_sequence)
This seems like an unnecessary restriction and there are several ways it could be resolved. Off the top of my head:
- Allow manifest arrays to conform to sequences.
- Change append() to take a COLLECTION, a common ancestor to SEQUENCE and ARRAY.
- Streamline the base library; the proliferation of container abstractions may be interesting from a theoretical perspective, but in practice I think it tends to lead to cluttered inheritance hierarchies and overly-complex code that performs type conversions that aren't really necessary. (I know this is also the least likely alternative because of its broad impact but I think it may still be a desirable long-term goal.)
Note: I copied this request from Greg's request from Eiffel support website
https://www2.eiffel.com/support/protected/report.aspx?pr=14839
(5 votes)
Comments
I prefer way 2, change the
I prefer way 2, change the `append'. But don't know how to query items in {COLLECTION}...
In the meantime, you can do
In the meantime, you can do