[Grace-core] Inheritance and Template Objects

Andrew P. Black black at cs.pdx.edu
Fri Apr 5 11:46:34 PDT 2013


On 5 Apr 2013, at 04:46 , James Noble wrote:

> this assumes true has a "template" method which is basically clone or something very close.

No, I obviously didn't explain this very well.  It's not "clone", it's "dement", as in "suck out my soul".   The template is NOT a boolean, it's a meta object that describes the methods — and in general also the initialization — that make the object work.  It's the "soul" of an object.

> So here are "Classiifed" versions of andrew's examples. 

> class emptyness.template {
> 				method size is abstract {}
> 				method isEmpty { self.size == 0 }
> 				method notEmpty { self.isEmpty.not }
> 				method ifEmpty(block) { self.isEmpty.ifTrue(block) } 
> 				method ifNotEmpty(block) { self.isEmpty.ifFalse{block.apply(self)}} 
> 				method ifEmpty(block)ifNotEmpty(block2){ {self.isEmpty.ifTrue(block)ifFalse{block2.apply(self)}} 
> 		}

The template is a constant.  So there is no need to generate a new one each time.  Hence, adding a class an a method is just adding unnecessary overhead.  Which was why I wrote simply:

def emptyness = template {
				method size is requirement {}
				method isEmpty { self.size = 0 }
				method notEmpty { self.isEmpty.not }
				method ifEmpty(block) { self.isEmpty.ifTrue(block) } 
				method ifNotEmpty(block) { self.isEmpty.ifFalse{block.apply(self)}} 
				method ifEmpty(tBlock)ifNotEmpty{fBlock} { self.isEmpty.ifTrue(tBlock)ifFalse{fBlock.apply(self)}} 
		}

It's an explicit goal of mine not to have unnecessary incantations.  

Let me try to explain this one more time. 

The point of my proposal was to be EXPLICIT about when we are using a template and when we are using an object.  Object construction and inheritance require no object mutation, and there is no loss of referential transparency: an expression has the same meaning regardless of context.   The initialization code — retaining which in re-executable form was the whole point of this long digression into alternative inheritance semantics — is explicitly part of the template, and it isn't executed until an object is instantiated from the template. At that time any selfs in the template are bound to the object being instantiated.   This behavior is different from anything else that we have in Grace.   It's not what ordinary objects do, which is why making aCartesianPoint.x(a)y(b) answer an object rather than a template doesn't work.

	Andrew



More information about the Grace-core mailing list