Next section: Lexical Notation
Language OverviewDylan is built around two central concepts: objects and functions.
Objects are the data that exist in Dylan programs. Objects are mapped into a class heterarchy. The class heterarchy describes the inheritance relationships among classes. The class <object> is the root of the heterarchy. Every class inherits from its direct superclasses (except for <object> which has no superclasses). Classes may also have subclasses, which inherit from them, either directly or indirectly. The superclasses of a class are the class itself, its direct superclasses, their direct superclasses, and so on back to the class <object>.
Every object in the Dylan world is a direct instance of exactly one class. This class is referred to as "the class of" the instance. For each object O that is a direct instance of class C, the object O is also an indirect instance of all the superclasses of C (except C itself). (It follows that every object in Dylan is an indirect instance of <object>.) The term general instance means "either a direct or indirect instance."
Dylan defines four categories of classes:
- Abstract Class
- A class that is not intended to have direct instances. Its general instances obey an interface implemented by subclasses. The opposite of an abstract class is a concrete class.
- Instantiable Class
- A class that can be used as the first argument to make. The opposite of an instantiable class is an uninstantiable class. Note that an abstract class may be instantiable.
Functions are a class of objects used for performing actions in Dylan. Functions correspond to the functions, procedures, methods, and messages of other languages. Dylan supports two classes of functions: methods and generic functions.
- Sealed Class
- A class that cannot be subclassed, other than those subclasses explicitly defined in the same library. The opposite of a sealed class is an open class.
- Primary Class
- A class that may be used only as the primary superclass in multiple inheritance. It is illegal for a class to have two primary superclasses unless one is a subclass of the other. The opposite of a primary class is a free class.
A method is a basic callable unit of code. It contains a typed argument list and a code body. The types in the argument list are called the specializers of the method. A method can only be called with arguments that match the specializers of the argument list. (In the most common case, the specializer is a class, and the corresponding argument must be a general instance of the class.) When the specializers of a method match a set of arguments, the method is said to be applicable to the arguments. If a method is called with inappropriate arguments, an error is signaled.
A generic function contains zero or more methods. When a generic function is called, the arguments are compared to the specializers of all the methods in the generic function. The method with the most appropriate specializers is run. In this way, a generic function chooses a method based on the classes and identities of its arguments. This is the basic technique for object-oriented dispatch in Dylan.
In contrast to methods in other object-oriented languages, Dylan methods can also be called directly. They do not need to be added to generic functions. Used this way, methods play the role of blocks in Smalltalk, closures in Lisp, and functions in C.
Classes and functions are themselves first-class objects, which can be manipulated by programs.