An Introduction to the Tingle Programming Language

Dirk van Deun, dirk at dinf.vub.ac.be

Section 1: Classes and Ideas

In an imaginary language, that looks a lot like Tingle, let us define a simple class Human as follows:

class Human {
   def play_tetris() { ... }
}

Now to derive a subclass Woman, providing some specifically female skills, we would, perhaps using some specialized syntax like "extends", reopen the scope of Human, and embed the class Woman inside it, so that the methods and data of the class Human would be visible for any newly added methods for Woman. Staying as close as possible to Tingle syntax, we would write something like:

class Human {
   class Woman {
      def give_birth() { ... }
      def walk_on_high_heels() { ... }
   }
}

The two new methods are able to see the Human method play_tetris(), which is in an enclosing scope.

The above code is in fact syntactically valid in Tingle; but it means that the classes Human and Woman overlap, and that the two new methods exist in their set intersection, available only to objects that are both Human and Woman.

As all women are by definition also human, the class Woman and the intersection coincide. Maybe we can make the example more interesting by making it about the intersection of Human and Female instead:

class Human {
   class Female {
      def give_birth() { ... }
      def walk_on_high_heels() { ... }
   }
}

class Woman = Human Female.

We now have two independent classes, Human and Female, neither of which is a superclass or a subclass of the other; and therefore we needed to separately declare the composite class Woman, modeling beings that are both Human and Female.

To distinguish between these two kinds of classes, we call Human and Female ideas, and only Woman will be a class: the name "idea" (imperfectly) reflects Platonic jargon, where "a woman takes part in the Ideas Human and Female", instead of being Human with subclass Woman. Also, to highlight the difference between classes and ideas, we will preferably open blocks of ideas with the specialized keyword "as".

Here we should point out, that classes in Tingle are no more than collections of ideas: they have no properties except the properties that they derive from the ideas they contain. For any collection of ideas, there will be only one way in which they "click together", so that the declaration of the class Woman did not need any further annotations or glue code, nor was even the order of Human and Female relevant.

The next two sections together will explain how this works.



Contents | Section 2: The Top Method