[Grace-core] collections interface for new classes

James Noble kjx at ecs.vuw.ac.nz
Sat Dec 12 03:41:07 PST 2015


Doing due diligence through Andrew’s & Kim’s code for varargs methods:

* collections has a bunch, mostly around add & remove (they’re in parallel)
I think the full suite is:

> add(*x) 
> addAll(elements) 
> addAllFirst(l) 
> addFirst(*l) 
> addLast(*x)

there seem to be two options here: 

1. take the varargs versions back to single elements,
leave the “All” versions taking collections

> c.add “x”
> c.addFirst “x” 
> c.addLast “x” 
> 
> c.addAll [ “x”, “y” ] 
> c.addAllFirst [ “x”, “y” ] 

2. dump the single element versions, do everything with collections,
everyone has to lift objects into collections

> c.add [ “x” ] 
> c.addFirst [ “x” ]
> c.addLast [ “x” ]

“contains” would term into “subset” I guess;

* there are also a couple of other methods in the prelude

> StandardPrelude.grace:method max(a, b, *xs) {
> StandardPrelude.grace:method min(a, b, *xs) {

I presume these just lose the varargs argument;
If it’s a big problem, we could put min & max into the collections interfaces.

* objectdraw has precisely two varargs methods for creating selection boxes

> objectdraw.grace:  factory method options (*options: String) labeled (label': String) -> Choice {
> objectdraw.grace:  factory method options(*optStrings: String) -> Choice {

* Kim’s book doesn’t declare varargs methods at all and has two mentions in the text
(one for creating selection boxes, one for lists)

ch10-gui/GUI.tex:three options, but we could just as easily had 6 or more.\footnote{We say that this method has \lstinline{varargs}.
ch13-arrays/create.tex:This is our first example of the use of ``varargs'' in Grace.  It simply means that

* amg (Andrew’s minigrace) has a few methods in the AST and parser

ast.grace:    method new(*values) scope(s) {
ast.grace:    factory method new(*values) {
ast.grace:    factory method new(*values) {
parser.grace:method findNextValidToken(*validFollowTokens) {

J

PS andrew - which is the best current version of collections to work on? 

PPS if we’re allowed “min” and “max” surely we are allowed “seq” as well?

PPPS if we add “min” and “max” into collections, there’s average, and sum, and … 
  although here I think I’d be very happy to have a trait that mixed this in to the collections library elsewhere


More information about the Grace-core mailing list