[Grace-core] On numbers and objects

Andrew P. Black black at cs.pdx.edu
Mon Nov 8 13:24:56 PST 2010


Folks,

I just edited the putative blog post on Numbers and Strings.  I made quite a lot of changes, so you should all look at it again.

On 8 Nov 2010, at 11:34, Kim Bruce wrote:

> In my opinion, there should be no public constructors (though obviously there are operations that construct new strings), and, because they are immutable, the egal operation doesn't allow distinctions to be made between two string objects with the same content.  I.e., the system may "accidentally" have two different versions of "equality is mysterious" floating around, but you wouldn't be able to distinguish them in any way.

I don't know what a "public constructor" is.  We have string literals, but perhaps these should be of a different class (Like StringLiteral), explicitly to allow the class String to be redefined to be something more elaborate.  (My main contribution to Fortress was to rename String to JavaString (because that's what it was; they were running on the JVM) and to implement an extensive library of implementation classes that all supported the String interface, but used efficient implementations bases on Hans Boehm's tree-structured Cord library.

Can one write aString.copy in Grace?  Why would one want to?   Perhaps to support distributed-memory processors?  If copy is allowed, it's presumably a no-op in  a single-memory implementation.   

On Nov 7, 2010, at 11:40 AM, Michael Kölling wrote:
> 
> There cannot be constructors for classes of this kind, otherwise you could have two 1-objects, which would wreak havoc with equality.

There are two implementations: (1)  intern Numbers, so there is exactly one copy, and refer to them with pointers, and (2)  copy numbers, so that both you and I have our own copy of Avogadro's Number.

Since numbers are immutable, it doesn't matter which of these we choose to do: the programmer will never be able to tell the difference from the language semantics.

I suppose that there is a philosophical difference between 56 being a reference to the one true 56 object that we all share, and 56 coming  into existence because the Grace implementation parsed my literal.  Do we ned to debate this?  Does it change anything?   56 || 56 regardless, and 56 || 57 will always be false.

|| is Baker's symbol for egal.  If we are going to use that, then I can't have || for comments.    That's OK ;-)

	Andrew



More information about the Grace-core mailing list