[Grace-core] Dialect encoding

Timothy Jones tim at zimothy.com
Tue Jul 31 16:23:04 PDT 2012


As I understand it, an unqualified method call results in the following
lookup:

Search for the method on self (regardless of how inheritance works, this
includes looking at methods defined in super objects). If the method
isn't found, perform the same lookup on the enclosing object scope. Keep
repeating on each enclosing scope until the method is found.

I'm not sure if the spec actually defines it this way, it's just how I
believe it's supposed to work. Minigrace is currently implemented this
way (though it looks up the method statically). The important thing here
is that it's only for unqualified methods: explicit requests on self or
any other object only perform the lookup on that object.

So if you have control over an anonymous enclosing scope for an object,
you can stick whatever you want in there and it will be privately
available to the object it encloses. Grace has no way to dynamically
bring names into a local scope, but because the lookup always searches
on super objects you can dynamically bring all of the methods on an
object into scope with inheritance. Combining these two techniques allow
all of the methods in a given object to be accessible to another object
while keeping them private.

This technique allocates an extra object and may actually bring
confidential methods on the dialect object into scope as well, so we're
almost certainly better off having a dialect statement be magic rather
than sugar. Mostly I'm just testing out my understanding of the family
polymorphism in Grace, as well as what a dialect is supposed to actually
achieve.

Tim

On 07/31/2012 11:08 AM, Kim Bruce wrote:
> I've read through all 5 messages, but I'm afraid that I don't understand how this encoding works.  Can you help me?
>
> I agree it would be nice if we could encode dialect as something already in the language, but I won't feel terrible if we have to add it as a specialization of inheritance ("inherits public").
>
> Kim
>
>
>
> On Jul 29, 2012, at 6:55 PM, Timothy Jones wrote:
>
>> I wanted to be clear on what it was that declaring the use of a dialect
>> actually did, so I drew up an object encoding for it that acts the way I
>> expect dialects to work: introducing the methods on the object into the
>> local scope, but not attaching them to the self object (which is how it
>> differs from using inherits). This behaviour can be achieved by
>> attaching the methods to outer instead.
>>
>> So this code in a module:
>>
>> dialect myDialect
>> hello
>>
>> becomes:
>>
>> object {
>>    inherits myDialect
>>    method newModule {
>>        object {
>>            hello
>>        }
>>    }
>> }.newModule
>>
>> A module that doesn't declare a dialect could be encoded in the same
>> way, just with the outer object inheriting from the prelude rather than
>> an explicit object.
>>
>> The encoded program works in Minigrace. It calls the hello method
>> defined in myDialect when run, and attempting to invoke hello on the
>> module object itself fails.
>>
>> Have I interpreted what a dialect is supposed to achieve correctly?
>>
>> Tim
>>
>> _______________________________________________
>> Grace-core mailing list
>> Grace-core at cecs.pdx.edu
>> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core



More information about the Grace-core mailing list