The cl-abstract-classes Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-abstract-classes Reference Manual

This is the cl-abstract-classes Reference Manual, version 1.7, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 03:06:07 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

Abstract, Final, and Singleton Metaclasses for CLOS

A common complaint about CLOS is that it is somehow 'not properly object-oriented'. As usual with such complaints it's often hard to find out what is really meant. However it is clear that one of the things people don't like is that CLOS is too liberal. Politically-correct object-oriented languages differ in a number of ways from CLOS, among them:

Most of these aspects of 'modern' object-oriented languages are simply beneath contempt. They seem to be restrictions placed on the language out of some misplaced desire for an efficient implementation without doing very much work, restrictions because it's impossible to trust programmers, especially with classes they didn't write, restrictions because it's just nice to be restricted and not to have to think too hard, or a gratuitous overloading of several ideas into one construct.

CLOS is quite different. CLOS assumes some intelligence and maturity in its users, and provides something much more like a toolkit for constructing object-oriented programs that actually fit the domain rather than having to deform the domain into some ludicrously restrictive framework.

Of course, this doesn't help, because everyone now 'knows' that an object system has to have all these properties, so CLOS is just inherently no good. Well, all is not lost: CLOS is a toolkit for constructing object-oriented programs that fit the domain, and one of the domains it can produce programs to fit is the domain of 'modern' object-oriented languages. It's fairly obvious for instance that by a little judicous use of the package system and macros you could easily define a single-dispatch, all-methods-are-in-the-class language based on CLOS. Data hiding can also be done by devious use of gensymed slot names, and so on. Almost everything is possible

Finally, you can use the MOP to change CLOS in all-sorts of interesting ways, most of which are simply beyond what 'modern' systems can imagine. Here is a small example of this. By defining suitable metaclasses, it is almost trivial to add 'abstract' and 'final' classes to CLOS.

Abstract classes

A class which can be subclassed, but not directly implemented. Defined using either the metaclass abstract-class or the macro define-abstract-class.

(define-abstract-class container ()
  ;; May not be instantiated
  ((children :initarg :children
	     :accessor children
	     :initform '())))

(define-abstract-class contained ()
  ;; May not be instantiated
  ((parent :initarg :parent
	     :accessor parent
	     :initform nil)))

(defclass exchange-object (container contained)
  ;; may be instantiated
  ())

Final classes

A class which may not be further subclassed. Defined either using the metaclass final-class or the macro define-final-class.

(defclass exchange-object (container contained)
  ;; may be instantiated and subclassed
  ())

(define-final-class mux (exchange-object)
  ;; may be instantiated but not subclassed
  ((id :initarg :id
       :reader id)))

(defclass shelf (exchange-object)
  ;; may be instantiated but not subclassed
  ()
  (:metaclass final-class))

Both abstract and final classes are implemented very simply by subclassing standard-class and writing suitable methods on make-instance and validate-superclass. Although the MOP is not completely standardised, the implementation here works on three commercial, and one non-commercial, CLs with only minor conditionalisation.

Singleton classes

Along the lines of abstract classes above, it's quite easy using the MOP to create classes which only have a single instance. For these classes, make-instance always returns the same object. It's somewhat questionable whether this is a good thing to do, since it violates a lot of expectations - expecting (eq (make-instance 'foo) (make-instance 'foo)) to be true is almost as strange as expecting (eq (cons 1 1) (cons 1 1)) to be true. However, it's easy enough to do, and it gives another example of using the MOP to alter CLOS.

Example:

(in-package :cl-user)

(use-package :org.tfeb.hax.singleton-classes)

(defclass foo ()
  ((x :initform (progn
                  (format *debug-io* "~&Initialising x~%")
                  1)))
  (:metaclass singleton-class))

Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 abstract-classes

Author

Tim Bradshaw (tfb at lostwithiel)

Description

Extends the MOP to allow ‘abstract‘ and ‘final‘ classes.

Version

1.7

Dependency

closer-mop

Source

abstract-classes.asd (file)

Component

abstract-classes.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 abstract-classes.asd

Location

abstract-classes.asd

Systems

abstract-classes (system)

Packages

abstract-classes-system


Previous: , Up: Lisp files   [Contents][Index]

3.1.2 abstract-classes/abstract-classes.lisp

Parent

abstract-classes (system)

Location

abstract-classes.lisp

Packages

org.tfeb.hax.abstract-classes

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 abstract-classes-system

Source

abstract-classes.asd

Use List

Previous: , Up: Packages   [Contents][Index]

4.2 org.tfeb.hax.abstract-classes

Source

abstract-classes.lisp (file)

Nicknames
Use List
Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Macros

Macro: define-abstract-class CLASS SUPERS SLOTS &rest OPTIONS
Package

org.tfeb.hax.abstract-classes

Source

abstract-classes.lisp (file)

Macro: define-final-class CLASS SUPERS SLOTS &rest OPTIONS
Package

org.tfeb.hax.abstract-classes

Source

abstract-classes.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Classes

Class: abstract-class ()

The class of abstract classes

Package

org.tfeb.hax.abstract-classes

Source

abstract-classes.lisp (file)

Direct superclasses

standard-class (class)

Direct methods
  • validate-superclass (method)
  • validate-superclass (method)
  • make-instance (method)
Class: final-class ()

The class of classes which may not be subclassed

Package

org.tfeb.hax.abstract-classes

Source

abstract-classes.lisp (file)

Direct superclasses

standard-class (class)

Direct methods
  • validate-superclass (method)
  • validate-superclass (method)

Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   A   F   L  
Index Entry  Section

A
abstract-classes.asd: The abstract-classes<dot>asd file
abstract-classes/abstract-classes.lisp: The abstract-classes/abstract-classes<dot>lisp file

F
File, Lisp, abstract-classes.asd: The abstract-classes<dot>asd file
File, Lisp, abstract-classes/abstract-classes.lisp: The abstract-classes/abstract-classes<dot>lisp file

L
Lisp File, abstract-classes.asd: The abstract-classes<dot>asd file
Lisp File, abstract-classes/abstract-classes.lisp: The abstract-classes/abstract-classes<dot>lisp file

Jump to:   A   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   D   M  
Index Entry  Section

D
define-abstract-class: Exported macros
define-final-class: Exported macros

M
Macro, define-abstract-class: Exported macros
Macro, define-final-class: Exported macros

Jump to:   D   M  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables


Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   A   C   F   O   P   S  
Index Entry  Section

A
abstract-class: Exported classes
abstract-classes: The abstract-classes system
abstract-classes-system: The abstract-classes-system package

C
Class, abstract-class: Exported classes
Class, final-class: Exported classes

F
final-class: Exported classes

O
org.tfeb.hax.abstract-classes: The org<dot>tfeb<dot>hax<dot>abstract-classes package

P
Package, abstract-classes-system: The abstract-classes-system package
Package, org.tfeb.hax.abstract-classes: The org<dot>tfeb<dot>hax<dot>abstract-classes package

S
System, abstract-classes: The abstract-classes system

Jump to:   A   C   F   O   P   S