Common Lisp Object System

From Wikipedia, the free encyclopedia

(Redirected from CLOS)
Jump to: navigation, search

The Common Lisp Object System (CLOS) is the facility for object-oriented programming which is part of ANSI Common Lisp. CLOS is a dynamic object system which differs radically from the OOP facilities found in more static languages such as C++ or Java. CLOS was inspired by earlier Lisp object systems such as MIT Flavors and CommonLOOPS, although it is more general than either. Originally proposed as an add-on, CLOS was adopted as part of the ANSI standard for Common Lisp and has been adapted into other Lisp dialects like EuLisp or Emacs Lisp.[1]

Contents

CLOS is a multiple dispatch system. This means that methods can be specialized upon the types of all of their arguments. Most OO languages are single-dispatch, meaning that methods are only specialized on the first argument. Methods in CLOS are grouped into generic functions; a generic function is a collection of methods with the same name and argument structure, but with differently-typed arguments.

Like the OO systems in most dynamic languages (such as Python), CLOS does not enforce encapsulation. Any data member (or slot) can be accessed using the slot-value function or via (optionally auto-generated) accessor methods. CL programmers use the language's package facility to declare which functions or data structures are intended for export.

Apart from normal ("primary") methods, there also are :before, :after, and :around methods. These modify the order in which methods are executed on a derived class. An :around method can specify whether the primary method is executed at all. Additionally, the programmer can adjust if all possible primary methods along the class hierarchy should be called or just the one providing the closest match.

CLOS allows multiple inheritance. When the default order in which methods are executed in multiple inheritance is not correct, the programmer may resolve the diamond inheritance problems by specifying the order of method combinations.

CLOS is dynamic, meaning that not only the contents, but also the structure of its objects can be modified at runtime. CLOS supports changing class definitions on-the-fly (even when instances of the class in question already exist) as well as changing the class membership of a given instance through the change-class operator.

CLOS is not a prototype language: Classes must be defined before objects can be instantiated as a member of that class.

Outside of the ANSI standard, there is a widely implemented extension to CLOS called the Meta-Object Protocol (MOP). The MOP defines a standard interface to the underpinnings of the CLOS implementation, treating classes themselves as instances of metaclasses, and allows the definition of new metaclasses and the modification of basic class behavior. The flexibility of the CLOS MOP prefigures aspect-oriented programming, which was later developed by some of the same engineers, such as Gregor Kiczales.

Making Lisp object oriented is easy: You can do it in two pages of code (Graham, 1994). Making object-oriented Lisp as extensible and flexible as the rest of Lisp is more difficult. Although CLOS is a complete object system, CLOS is implemented in an object-oriented fashion. The object-oriented implementation of CLOS is known as the CLOS Metaobject Protocol (or MOP) and permits the object system to be customizable and extensible.[2]

  1. ^ "CLOS is a standard. Multiple vendors supply CLOS. CLOS (or parts of it) is being used to add object orientation to other Lisp dialects such as EuLisp or Emacs Lisp." pg 110 of Veitch 1998
  2. ^ pg 108 of Veitch 1998
  • "CommonLoops: merging Lisp and object-oriented programming", by Daniel G. Bobrow, Kenneth Kahn, Gregor Kiczales, Larry Masinter, Mark Stefik, Frank Zdybel. 1986, Portland, Oregon, United States. Pages 17 - 29 of the Conference on Object Oriented Programming Systems Languages and Applications, ISSN 0362-1340.
  • "A History and Description of CLOS", by Jim Veitch. Pages 107-158 of Handbook of Programming Languages, Volume IV: Functional and Logic Programming Languages, ed. Peter H. Salus. 1998 (1st edition), Macmillian Technical Publishing; ISBN 1-57870-011-6

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.