[Grace-core] collections interface for new classes

Andrew P Black black at cs.pdx.edu
Fri Dec 11 22:51:17 PST 2015


On 11 Dec 2015, at 20:26, James Noble <kjx at ecs.vuw.ac.nz> wrote:

I think that your last option is close:

> list
> list [“a”, “b”, “c”] 
> list (anotherCollection) 
> 
> list<String>
> list<String>  [“a”, “b”, “c”] 
> list<String> (anotherCollection) 

But since we have abolished varargs, the first variant has to be written

	list []

or 

	list<String> []

This lets us simplify the instance creation methods.   The only downside that I can see is that the empty sequence will have to be written

	sequence []

and it won’t know until creation time that it’s empty.   Still, the minor efficiency gain isn’t worth complicating the interface used by the programmer.  (In any case, the compiler could use a different interface. 

I’m also assuming, based on the previous discussion, that [] will be Iterable, not Sequence.

Notice that if I implement, say, a sorted set using, say 2-3 trees and skiplists, I can put these implementations in modules called twoThreeTree, and skipList. In both cases, I can call the class sortedSet.   That is, the module name defines the implementation, the class name the interface.

	import “twoThreeTree” as x

or 

	import “skipList” as x

	x.sortedSet<Number> [1, 2, 3]

I was a bit worried that there would be too much redundancy with this naming, but I think that it works quite well.

	Andrew





More information about the Grace-core mailing list