requestCall 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:

  1. Allow manifest arrays to conform to sequences.
  2. Change append() to take a COLLECTION, a common ancestor to SEQUENCE and ARRAY.
  3. 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

2.4
Your rating: None Average: 2.4 (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

manus_eiffel's picture

In the meantime, you can do

a_list.append (create {ARRAYED_LIST [STRING]}.make_from_array (<< "one", "two", "three">>))

Syndicate content