[Grace-core] Variables as methods

Michael Homer mwh at ecs.vuw.ac.nz
Tue Aug 13 16:13:24 PDT 2013


On 14 Aug 2013 10:56, "Timothy Jones" <Timothy.Jones at ecs.vuw.ac.nz> wrote:
>
> If every variable is automatically a confidential method on the
surrounding
> object, then defining annotations to make reading and writing that
variable
> publicly available is significantly simpler.
>
> Consider this object definition:
>
> > object {
> >   // Confidential getter
> >   def a = 1
> >
> >   // Public getter
> >   def b is public = 2
> >
> >   // Confidential getter and setter
> >   var c := 3
> >
> >   // Public getter and confidential setter
> >   var d is readable := 4
> >
> >   // Confidential getter and public setter
> >   var e is writable := 5
> >
> >   // Public getter and setter
> >   var f is public := 6
> > }
>
> These variables enumerate all of the possibilities.  Annotating a var as
> readable, writable is equivalent to declaring it public.
>
> If you really need private variables, just declare them outside the
object.
>
> > method newObject {
> >   def x = 1
> >   object {
> >     method number { x }
> >   }
> > }
It's also possible to do this same system with fields public by default.
Then "confidential" restricts both, "readable" has just a public getter,
and the other way around for "writable". Lexically-bound variables still
work the same way.

Alternatively, there could be public getters by default. Then you only
really need two annotations "confidential" and "writable" (or even
"public"), because writable-only is a rare desire.
-Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20130814/11d5dd94/attachment.html>


More information about the Grace-core mailing list