gracelang / language

Design of the Grace language and its libraries
GNU General Public License v2.0
6 stars 1 forks source link

what is the interface of platform/memory aka PrimitiveArray #50

Open kjx opened 8 years ago

kjx commented 8 years ago

Presumably this needs to confirm to #49 How do we decide what the interface should be. In particular, should it really have sort? I note neither implementation has hash.

spec

doesn't really say

amg

    add_Method(PrimitiveArray, "at", &PrimitiveArray_index);
    add_Method(PrimitiveArray, "[]", &PrimitiveArray_index);
    add_Method(PrimitiveArray, "at()put", &PrimitiveArray_indexAssign);
    add_Method(PrimitiveArray, "[]:=", &PrimitiveArray_indexAssign);
    add_Method(PrimitiveArray, "asString", &PrimitiveArray_asString);
    add_Method(PrimitiveArray, "asDebugString", &PrimitiveArray_asDebugString);
    add_Method(PrimitiveArray, "::", &Object_bind);
    add_Method(PrimitiveArray, "size", &BuiltinList_length);
    add_Method(PrimitiveArray, "==", &Object_Equals);
    add_Method(PrimitiveArray, "!=", &Object_NotEquals);
    add_Method(PrimitiveArray, "sortInitial()by", &PrimitiveArray_sort);

Kernan

        AddMethod("[]", at);
        AddMethod("at", at);
        AddMethod("[] :=", atPut);
        AddMethod("at put", atPut);
        AddMethod("size", new DelegateMethod0(mSize));
KimBruce commented 8 years ago

I don't see any need for sort. My intro students will never see PrimitiveArray, only List. I see we need it (e.g., in data structures to show what is going on under the hood), but it should not contain anything substantive.

kjx commented 8 years ago

All methods from #49, plus:

at()
at()put()
size()
sortInitial()by()
apblack commented 8 years ago

Sort is there for pragmatic reasons. We do need sort on lists, sequences, etc. If we implement sort in Grace, it will always run 10 or 100 times more slowly than anything implemented by the underlying platform.

So, rather than writing Quicksort in Grace, I chose to expose the underlying sorts from C and JavaScript. I think that this is a reasonable approach for other implementations too. Kernan could expose C#'s sort.

apblack commented 8 years ago

We need a naming scheme for this. Something like an object primitive with attributes memory, identity, ...

I suggest that primitive be used for things that are defined as part of the language, and platform for things that are platform-dependent.

kjx commented 8 years ago

we're supposed to have such a scheme, not sure where it is documented, but we did agree on it, and that the prefix for this was "platform"

note that for object capability security reasons, this should be in many small modules "platform/memory" and "platform/timing" and "platform/rats" or whatever --- rather than just one big module object with lots of sub-objects.

kjx commented 8 years ago

PrimitiveArray is now in the standard. If anyone cares about naming schemes, I guess we can open another issue.

apblack commented 8 years ago

I think that primitiveArray needs to be in the language spec, not in the Standard library document. It's something that a language implementation needs to provide, in order that one can write the libraries.

Moreover, it should be capitalized that way.

kjx commented 8 years ago

On 11/06/2016, at 3:27AM, Andrew Black notifications@github.com wrote:

I think that primitiveArray needs to be in the language spec, not in the Standard library document.

Why? The full protocol for String & Integer is in the standard prelude doc, not the main language...

It's something that a language implementation needs to provide, in order that one can write the libraries.

that's a separate question. it's imported, right, so why put it in the core? reflection also has to be "built in" to an impl, do we put that in the language?