[Grace-core] collections interface for new classes

James Noble kjx at ecs.vuw.ac.nz
Wed Dec 9 00:48:00 PST 2015


>> the question of whether we have varargs or some kind of 
>> built-in collection literals, probably affects the API design too.
> 
> Absolutely it does.  We agreed in Claremont, I think, that we were going to replace varargs with a notation for sequences.  This would make sewunces "special", but then they are special now, anyway, because a * argument is made on by magic.

OK yep I remember that - In fact it’s on the todo list.

> We also agreed, long ago, that collections should be "built-in", so that novices can just use list, set and sequence without having to import them.  Are you suggest ing that we revisit that?

I don’t want to “build in” the whole collections library to *everything*.
those definitions should come in a student or standard dialect.

> One advantage of sequence.empty over sequence [] is that the former can return a constant.  But maybe this is not a problem if sequence literals are built-in.

if “sequence” is the built in sequence then we’d probably just write [] anyway...

> I don't understand what your `all` wrapper would do.
>   When we had varargs, I was arguing for something like `all`, so that a client with a collection could use it to request a varargs method.  (And I thought that you argued against it ;-)  But now we have got rid of them, what do you want `all` to do?

that’s what I want it to do (and we could indeed use a prefix asterix if we wanted.
I’m willing to consider it now because
 - it would be implemented in library code (probably by testing the arguments
 - it does simplify the collections interface
 - it doesn’t overcomplicate every request everywhere
    (splat in varargs is that it can be used in non-variadic calls too)

This does simplify things though:
 list [] - empty list
 list [a,b,c] - literal list
 list(foo) - build list from a collection foo 

collection constructors now feel like wrappers over the builtin sequences

the other question is: do [] collections have a minimal or a maximal interface:
do we have to write “seq [1,2,3]” or will just "[1,2,3]" do?


> Finally, the place for this discussion is in the gracelang/languages issue tracker.

well I was hoping for a slightly wider discussion than I’d get there. 

James


More information about the Grace-core mailing list