[Grace-core] collections interface for new classes

James Noble kjx at ecs.vuw.ac.nz
Sat Dec 12 01:20:27 PST 2015


> I think that your last option is close:

(phew!) 


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

going once, going twice… 


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

that would do for now; we should look at Java8 or Fortress to see about finitness & size. 

I’d prefer to write “seq” if I’m allowed, or look at rejigging the names to get something shorter. 


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

writing it is a downside, unless we decide to make []s basically *be* sequences with a full interface. 
In a jit, or even a self-optimising interpreter, if the argument to sequences is known statically 
you should be able to inline it, especially in this case. PyPy and Gralll at least should both do that.

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

yes you can - and I think it does too. 


This relies - for now - on < > generics and [ ] as collection literals.  
I’m happy with that, especially as we could? can? disambiguate via spaces and still be LL1.
I can make progress and if we want we can agonise about reopening that issue.

James


More information about the Grace-core mailing list