[Grace-core] Dialect encoding
Kim Bruce
kim at cs.pomona.edu
Tue Jul 31 16:50:25 PDT 2012
On Jul 31, 2012, at 4:23 PM, Timothy Jones wrote:
> 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.
That's my understanding.
>
> 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
I don't understand the allocation of an extra object. Why?
> 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.
Barring some very clever encoding (which, even if it works, is likely not to be useful in practice), that is probably correct.
> 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.
Family polymorphism can be quite complex. What are you thinking of?
>
> 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