An Introduction to the Tingle Programming Language

Dirk van Deun, dirk at

Section 8: Your Class is my Idea

In the previous section we hid ideas in a name space, and accessed only classes. Without access to the ideas, we could not use nesting, so that we could only use the classes in isolation and with mixins. Our next step is that we make the API that is offered by the classes available for scoping again, so that we can emulate subclassing from a library class, for instance.

To enumerate the drawbacks of using only name spaces: we can now use Widget@WidgetLibrary as a black box, which exports its top methods as an API, but when using this safe API in the mixin myWidget:

Therefore we introduce the possibility to regard classes as ideas when used outside of their own native name space, and so use them for nesting:

as Widget@WidgetLibrary {
   as myWidget {

class MyWidget = Widget@WidgetLibrary myWidget.

(To be excruciatingly precise, Widget would actually be allowed to be in the current name space, but not Widget's ideas.)

In this example, for the scoping rule, the class Widget@WidgetLibrary will be considered to be an idea without data members, and with as methods only the top methods of the class. This corresponds with the viewpoint from a mixin, except that:

The analogy between ideas from your own name space and classes from other name spaces is not perfect. Classes used as ideas are self-contained for scoping: if they are nested themselves, their methods do not suddenly get the enclosing nestings in scope, as they were not defined in them. (Note that classes imported from the same name space can share data; but this is done through scoping in that other name space, so this is the responsibility of the library writer, who should know that code intimately.)

Each nesting should contain at least one "real" idea of your own. This is not currently enforced, but for instance the effect of adding code directly in a class used as an idea is left unspecified:

as Widget@WidgetLibrary {
   // the semantics of adding code here has not been settled

In conclusion, Tingle does not only support a novel very open style in code that belongs and is designed together, but also provides extra hiding and encapsulation when we cross the boundaries of such modules; to fall back to what is essentially multiple inheritance with sharing of common parts.

Contents | Section 9: Access Control