[Grace-core] Collections suggestion

Andrew P Black black at cs.pdx.edu
Tue Jul 29 13:48:56 PDT 2014


On 29 Jul 2014, at 02:42 , Kim Bruce <kim at cs.pomona.edu> wrote:

> I have a suggestion for a minor change in the semantics of the method at()put() (and []:=) in list.
> 
> Currently if you write myList.at(k)put(x) then it requires 1 <= k <= myList.size.  I would like it to work for 1 <= k <= myList.size+1
> 
> That is, I'd like to be able to extend the size of a list by one if the subscript is one greater than the current last index.  Doing this would make some code that involves adding new elements into a list easier in that a simple loop can shift all elements to the right over by one.  Java ArrayLists, for example, have this behavior.

This seems reasonable.  I'll put it in.

I've been testing an extended version of collections, which support Sequences (which, if you recall, are what we agreed to call immutable lists), and also more conversion operations (aList.asSet, aSequence.asList, etc).   These are passing all the tests that I've written, but there is as yet no automated way of testing coverage; that's on my list of things to do.

I've also allowed for conversion from a list and a sequence to a dictionary, in which the keys will be the indices of the list.  More controversially,  I'm also supporting conversion of sets to sequences and lists — I say controversially, since the order will be arbitrary.  But that conversion will be supported in any case through iteration: aSet.iterator.onto(list).   Sets to dictionaries seems less useful, though.

I've been thinking about sorting, and have concluded that what makes most sense would be to implement sort on PrimitiveArray (using the underlying Javascript or C sort), and then implement sort on lists &c using the sort on PrimitiveArray.

Your thoughts on any on the above are welcome.

	Andrew




More information about the Grace-core mailing list