An Introduction to the Tingle Programming Language

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

Section 6: Templates

These are two independent ideas, without any intersections:

as tapereader {
   def read() { ... }
}

as diskreader {
   def read() { ... }
}

And this is how we extend them together:

as buffered {
   as tapereader, diskreader {
      def read() { ... super.read() ... }
   }
}

class BufferedTapereader = buffered tapereader.
class BufferedDiskreader = buffered diskreader.

Which is short for:

as buffered {
   as tapereader {
      def read() { ... super.read() ... }
   }
   as diskreader {
      def read() { ... super.read() ... }
   }
}

Syntax as used in the examples until here does however not allow to express the following as a template:

as buffered {
   as diskreader {
      as floppy {
         def read() { ... super.read() ... }
      }
   }
   as tapereader {
      def read() { ... super.read() ... }
   }
}

So we add an alternative syntax for nestings that only consist of an intersection:

as buffered {
   as diskreader->floppy {
      def read() { ... super.read() ... }
   }
   as tapereader {
      def read() { ... super.read() ... }
   }
}

And then we can write the template:

as buffered {
   as tapereader, diskreader->floppy {
      def read() { ... super.read() ... }
   }
}

Note how the arrow syntax is also suitable for expressing traditional subclassing concisely:

class car->taxi {
   ...
}

class Taxi = taxi car.



Contents | Section 7: Name spaces