[Grace-core] Dialect encoding

Timothy Jones tim at zimothy.com
Sun Jul 29 18:55:37 PDT 2012


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



More information about the Grace-core mailing list