[Grace-core] Collections suggestion

Kim Bruce kim at cs.pomona.edu
Tue Jul 29 14:28:33 PDT 2014


The structure dialect does now compile properly on both Safari and Firefox on my Mac.  I guess I'll have to investigate the best way to get them to clear old code when the compiler has been updated.  It doesn't seem to be a problem with student written code, as far as I can tell.
On Jul 29, 2014, at 10:48 PM, Andrew P Black <black at cs.pdx.edu> wrote:

> 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.

Thanks!
> 
> 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.

Those sound good.
> 
> 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.

Converting to dictionary should be fine, though I'm not sure how helpful it would be to have indices as keys, though perhaps there would be useful dictionary operations that might make it more useful.

As you note, sets to list will be accessible via iterators anyway.  I'm not sure that I'd like to highlight those conversions (of course we would find examples like s1 == s2, but list(s1) != list(s2)) by making them so easy, but I can live with it.
> 
> 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.

Makes sense.  Which would you put into the language?  I could see a justification to do a single sort (hybrid quicksort/insertion) or have several different ones that highlight different big-O performance -- perhaps one O(n^2) and one O(n log n)?
> 
> Your thoughts on any on the above are welcome.

Thanks for all of your hard work on this.  I really appreciate it.  (Could you let me know when you change at()put()?  I have code for the text that i want to try out.)

The conference here is good.  Tim gave a talk on types for TinyGrace in FtFJP(?) and the Ph.D. Symposium.  James talks on dialects tomorrow.  The main issue is it has been very hot -- close to 90, and there is no air conditioning.  Tomorrow it will rain and it will be cooler, which will be quite nice.  See you next week!

Kim
> 
> 	Andrew
> 




More information about the Grace-core mailing list