[Grace-core] Collection naming

Andrew P. Black black at cs.pdx.edu
Wed Jul 2 21:32:55 PDT 2014


On 30 Jun 2014, at 20:29, James Noble <kjx at ecs.vuw.ac.nz> wrote:

> I don't think we want different syntax for requesting a "variable arity method with no arguments"  versus a "fixed arity method with no arguments".

I agree.  But it’s easy to agree, because there is no such thing as a variable arity method with no arguments.   The way that I see it, a variable arity method, by definition, has at least one parameter (the varargs parameter).   When it is requested, that request must therefore provide an argument list, which defines what is bound to that parameter.

If the list has two arguments, the varargs parameter is bound to a list containing the values of those two arguments.  If the list is empty, the varargs  parameter is bound to an empty list.   I would argue that it should be an error to fail to provide an argument list in the request.

This is completely different from a method with no parameter list, which must be requested with no argument list.

> at least get him to agree to update his book / labs (ideally by monday next week which *isn't* going to happen).
> but we should be able to fix it with the testers, and just tell them to write class foo'new say, instead of foo.new :-)

Kim can use whatever naming convention he likes his book.  That’s entirely orthogonal to what the class keyword does.

> we could get rid of varags lists, and only pass (nominally-homogeneous) collections;

No, we can’t, because we wouldn’t have a reasonably convenient way of creating those collections without variable arity methods.
(I don’t think that Marco’s suggestion of mutating a collection by adding one element at a time, and then presumably freezing it, is reasonably convenient.)
We could do something Pythin-like and make , a tupling operator, so that (1,2) is a single object, viz, a tuple containing 1 and 2.   I actually had this in my grammar in 2011, but we decided that variable arity methods was a better choice.  I’m happy to revisit that at some point, but probably after the end of Kim’s course.

> Andrew - is there something that we can look at about your collection API? 

Yes — the code.   

It would be nice to have a simple GraceDoc program that would extract documentation from the code.  Then I would be motivated to put some in.  Maybe that’s what I should work on …

> Python has a nice take on things that I didn't realise: mutable objects, especially collections 
> aren't hashable, so can't be in sets or as keys in a dictionary.

I know.   And it would be completely unreasonable to use the value of a mutable collection as a key.  But it is entirely reasonable to use the identity of a mutable object as a key.   And that was what I was proposing.

	Andrew

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20140702/bdad173f/attachment.html>


More information about the Grace-core mailing list