[Grace-core] collections interface for new classes
Kim Bruce
kbbruce47 at gmail.com
Sat Dec 12 13:47:52 PST 2015
I haven’t jumped in here because I generally don’t feel very strongly about the differences. Obviously Andrew has the most experience with it.
> On Dec 12, 2015, at 3:41 AM, James Noble <kjx at ecs.vuw.ac.nz> wrote:
>
> 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” ]
I have a slight preference for 1 over 2 as it seems a bit painful to add [] where they aren’t really needed.
>
> 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.
I’d keep the two argument versions of this, and then add them into the collections interfaces for sequences or lists
>
> * 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
It seems reasonable to use these with the list notation.
>
> * 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
> _______________________________________________
> Grace-core mailing list
> Grace-core at cecs.pdx.edu
> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core
More information about the Grace-core
mailing list