[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2 Defining class

A class is a first-class object in Gauche and you can create it on the fly at run-time using procedure calls. However, for convenience, a macro is defined to create a class and bind it globally.

Macro: define-class name supers (slot-spec ...) option ...
Creates a class object according to the arguments, and globally bind it to a variable name. This macro should be used at toplevel.

Supers is a list of direct superclasses from which this class inherits. You can use multiple inheritance. See 7.2.1 Multiple inheritance below, for the rule that determines precedence of inheritance chain.

Slot-spec is a specification of a "slot", sometimes known as a "field" or an "instance variable" (but you can specify "class variable" in slot-spec as well). The simplest form of slot-spec is just a symbol, which names the slot. Or you can give a list, whose first element is a symbol and whose rest is an interleaved list of keywords and values. The list form not only defines a name of the slot but specifies behavior of the slot. See 7.2.2 Slot specification, for details.

Finally, option ... is an interleaved list of keywords and values, specifies how class object should be created. This macro recognizes one keyword, :metaclass, whose corresponding value is used for metaclass (class that instantiates another class). Other options are passed to the make method to create the class object. See section 7.6.3 Class instantiation, for the usage of metaclass.

7.2.1 Multiple inheritance  
7.2.2 Slot specification  



This document was generated by Ken Dickey on November, 28 2002 using texi2html