[Grace-core] On numbers and objects
Michael Kölling
m.kolling at kent.ac.uk
Sun Nov 7 11:40:32 PST 2010
I am slowly reading through the GraceNotes - apologies for the multiple postings. I'll keep it down to a few a day... :-)
Regarding the note on Basic Types, I have a few questions and thoughts.
It seems intended (implicit in the text, I think, but not explicitly stated), that all data are objects, including the basic types - right? I think that's good. But it leaves a few questions. One is: where do these objects come from?
(Please stop me if I have the completely wrong end of the stick here. But I'll just go ahead and write my thoughts...)
I guess one view is to say that there are some pre-existing objects (such as numbers and strings), which just "are". They pre-exist in the Grace universe, and literals (1 or "Hello") are just constant references to these pre-existing objects.
That's okay.
There cannot be constructors for classes of this kind, otherwise you could have two 1-objects, which would wreak havoc with equality.
Then there are other object types (such a user defined classes), where objects don't pre-exist, but instead we are given a constructor. So we have two kinds of objects: pre-existing and constructor-created. (That's a much nicer distinction that the Java "primitive vs object".)
(Was that the idea here? Or have I got this completely wrong?)
Then there is another dimension: built-in types (the ones that the Grace system implicitly needs to know to operate, e.g. Boolean, Number) and user-defined (any class that is made by the user or explicitly imported from a library). This distinction is somewhat orthogonal to the creation question.
So, can we have all four combinations?
pre-existing / built-in: Boolean, Number, String, ...
constructed / built-in: ??? (anything that is "just there" without import from libraries?)
pre-existing / user defined: interesting case. Maybe enums?
constructed / user defined: of course. standard classes.
The "pre-existing / user defined" case looks interesting: Can I have a class where I enumerate the objects, instead of providing a constructor? After all, that's the model (as I see it) for Boolean or String.
Michael
More information about the Grace-core
mailing list