[Grace-core] thinking about private

James Noble kjx at ecs.vuw.ac.nz
Thu Dec 6 02:52:45 PST 2012


I've been translating some "E" code into Grace.
(more on that later)

One of the cliché's I've come across is class-like functions - 
that is functions (methods) that translate object.

In Grace, we're used to things like this:

method makeFoo {
 return object {
   def a = ...
   var b = ...
   method m {a + b}
 }
}

current Grace rules treat those defs as private. 

But the E code is generally written slightly differently - as far as I can tell,
equivalent to this Grace code:

method makeFoo {
 def a = ...
 var b = ...
 return object {
   method m {a + b}
 }
}

that is, "private" defs & vars can be declared in a lexical scope "just outside" the object to which they belong - 
if we had nested methods, we could declare private methods there too.  These declarations can be seen by the 
objects they enclose, but not by objects that inherit from those objects.  And of course, this works well for 
objects created within functions, but not so well for object literals, or classes.  

So it looks as if we could consider using this kind of coding to represent "private" if we wanted to.
Except I remember I thought about this earlier, and there was a reason this wouldn't work, but I 
can't remember what that was - most likely that if we put methods there, they can't call back via 
self if they're outside the object to which they belong.  This doesn't apply to vars or defs, however...

James


More information about the Grace-core mailing list