- Milestone: 5.0.0 --> None
It is sometimes convenient to treat an ordered collection as an array but at
other times as a list, queue, or even a circular queue. While all four classes
support makeArray, converting to the other classes could benefit from the
following proposal. Add a From class method to Ordered Collection so that all
four classes inherit it. The From method would take an ordered colection
instance as an argument and return an instance of the receiver containing the
same items in the same order. E.g. aList = .list~From(anArray) or
aQueue = .queue~From(aList). Since procedural Rexx programmers use compound
variables (stems) for collections, the From method should also accept as an
argument a stem if and only if it has tails that are positive whole numbers (an
ordered stem).
Similarly, it would be useful to be able to convert an ordered collection
instance to an ordered stem. So the proposal includes adding a toStem instance
method to the Ordered Collection class as well. E.g. myStem. = myList~toStem().
Proposed documentation:
from (Class Method)
-from(aCollection)----------------------------------------------><
Returns a newly created {array | list | queue | circular queue} containing the
items in aCollection in the same order. aCollection must be an instance of an
ordered collection or an ordered stem (a stem that has tails that are positive
whole numbers).
If aCollection is a sparse array, it is made non-sparse before conversion.
If aCollection is an ordered stem that has a .0 tail, the resulting {array |
list | queue | circular queue} will have the number of items specified in the .0
tail. Otherwise, the number of items in the resulting object will be the value
of the largest tail in aCollection.
toStem
-toStem-+--------+----------------------------------------------><
+-(name)-+
Returns a new stem object containing all the items in the receiver. If you
specify a string name, this value is used to create the derived name of compound
variables. The default stem name is a null string (""). The stem will have
integer tail values with the .0 tail containing the number of items in the
receiver. The items in the receiver (if any) are assigned to consecutive tail
values with the first item being assigned to .1, the second to .2, etc. If the
receiver is a sparse array, it is made non-sparse before conversion.
The attached file, CNVRTORD.REX, contains a proof-of-concept implementation of
the two methods using a MIXIN class and multiple inheritance together with
subclasses of the four Ordered Collection classes.
Anonymous