Common Lisp Object System

Standard method combination in ANSI common lisp

The Common Lisp Object System (CLOS) is the facility for object-oriented programming in ANSI Common Lisp. CLOS is a powerful 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 such as EuLisp or Emacs Lisp.[1]

Features

The basic building blocks of CLOS are methods, classes, instances of those classes, and generic functions. CLOS provides macros to define those: defclass, defmethod, and defgeneric. Instances are created with the method make-instance.

Classes can have multiple superclasses, a list of slots (member variables in C++/Java parlance) and a special metaclass. Slots can be allocated by class (all instances of a class share the slot) or by instance. Each slot has a name and the value of a slot can be accessed by that name using the function slot-value. Additionally special generic functions can be defined to write or read values of slots. Each slot in a CLOS class must have a unique name.

CLOS is a multiple dispatch system. This means that methods can be specialized upon any or all of their required arguments. Most OO languages are single-dispatch, meaning that methods are only specialized on the first argument. Another unusual feature is that methods do not "belong" to classes; classes do not provide a namespace for generic functions or methods. Methods are defined separately from classes, and they have no special access (e.g. "this", "self", or "protected") to class slots.

Methods in CLOS are grouped into generic functions. A generic function is an object which is callable like a function and which associates a collection of methods with a shared name and argument structure, each specialized for different arguments. Since Common Lisp provides non-CLOS classes for structures and built-in data types (numbers, strings, characters, symbols, ...), CLOS dispatch works also with these non-CLOS classes. CLOS also supports dispatch over individual objects (eql specializers). CLOS does not by default support dispatch over all Common Lisp data types (for example dispatch does not work for fully specialized array types or for types introduced by deftype). However, most Common Lisp implementations provide a metaobject protocol which allows generic functions to provide application specific specialization and dispatch rules.

Dispatch in CLOS is also different from most OO languages:

  1. Given a list of arguments, a list of applicable methods is determined.
  2. This list is sorted according to the specificity of their parameter specializers.
  3. Selected methods from this list are then combined into an effective method using the method combination used by the generic function.
  4. The effective method is then called with the original arguments.

This dispatch mechanism works at runtime. Adding or removing methods thus may lead to changed effective methods (even when the generic function is called with the same arguments) at runtime. Changing the method combination also may lead to different effective methods.

For example,

; Declare the common argument structure prototype.
(defgeneric f (x y))

; Define an implementation for (f integer y), where y matches all types.
(defmethod f ((x integer) y)
  1)

(f 1 2.0) => 1

; Define an implementation for (f integer real).
(defmethod f ((x integer) (y real))
  2)

(f 1 2.0) => 2  ;Dispatch changed at runtime.

Like the OO systems in most dynamic languages, CLOS does not enforce encapsulation. Any slot can be accessed using the slot-value function or via (optionally auto-generated) accessor methods. To access it via slot-value you have to know the name of the slot. 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 "auxiliary" methods. The former two are invoked prior to, or after the primary method, in a particular order based on the class hierarchy. An :around method can control whether the primary method is executed at all. Additionally, the programmer can specify whether all possible primary methods along the class hierarchy should be called or just the one providing the closest match.

The Standard Method-Combination provides the primary, before, after and around methods explained above. There are other Method-Combinations with other method types. New (both simple and complex) Method-Combinations and method types can be defined.

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 also allows one to add, redefine and remove methods at runtime. The Circle-Ellipse Problem is readily solved in CLOS, and most OOP design patterns either disappear or are qualitatively simpler.[2]

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

Metaobject Protocol

Outside of the ANSI Common Lisp standard, there is a widely implemented extension to CLOS called the Metaobject Protocol (MOP). The MOP defines a standard interface to the underpinnings of the CLOS implementation, treating classes, slot-descriptions, generic-functions and methods themselves as instances of metaclasses, and allows the definition of new metaclasses and the modification of all CLOS 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. The MOP defines the behavior of the whole object system by a set of protocols. These are defined in terms of CLOS. Thus it is possible to create new object-systems by extending or changing the provided CLOS functionality. The book The Art of the Metaobject Protocol describes the use and implementation of the CLOS MOP.

The various Common Lisp implementations have slightly different support for the Meta-Object Protocol. The Closer[3] project aims to provide the missing features.

Influences from older Lisp-based object systems

Flavors (and its successor New Flavors) was the object system on the MIT Lisp Machine. Large parts of the Lisp Machine operating systems and many applications for it use Flavors or New Flavors. Flavors introduced multiple inheritance and mixins, among other features. Flavors is mostly obsolete, though implementations for Common Lisp do exist. Flavors was using the message passing paradigm. New Flavors introduced generic functions.

CommonLoops was the successor of LOOPS (from Xerox Interlisp-D). CommonLoops was implemented for Common Lisp. A portable implementation called Portable CommonLoops (PCL) was the first implementation of CLOS. PCL is widely ported and still provides the base for the CLOS implementation of several Common Lisp implementations. PCL is implemented mostly in portable Common Lisp with only a few system dependent parts.

CLOS in other programming languages

Because of the power and expressivity of CLOS, as well as the historical availability of Tiny CLOS (a simplified portable CLOS implementation written by Gregor Kiczales for use with Scheme), CLOS-like MOP-based object systems have become the de facto norm in most Lisp dialect implementations, as well as finding their way into some other languages' OOP facilities:

Further reading

  • Bobrow, Daniel G.; Kahn, Kenneth; Kiczales, Gregor; Masinter, Larry; Stefik, Mark; Zdybel, Frank (June 1986). "CommonLoops: Merging Lisp and Object-Oriented Programming" (PDF). Conference proceedings on Object-oriented Programming Systems Languages and Applications. OOPSLA '86. pp. 17–29. doi:10.1145/28697.28700. ISBN 978-0-89791-204-4. S2CID 62631315. Archived from the original (PDF) on 2022-08-17. Retrieved 2022-03-17.
  • Veitch, Jim (1998). "A History and Description of CLOS". In Salus, Peter H. (ed.). Handbook of Programming Languages, Volume IV: Functional and Logic Programming Languages (1st ed.). Macmillan Technical Publishing. pp. 107–158. ISBN 1-57870-011-6.

References

  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." p. 110 of Veitch 1998
  2. ^ In the Design Patterns in Dynamic Languages slides, Peter Norvig presents his findings that 16 out of 23 design patterns taken from various textbooks are either "invisible or simpler" in Dylan or Common Lisp than in C++.
  3. ^ Closer Project: Closer to MOP
  4. ^ Deniau, Laurent (12 March 2010). The C Object System: Using C as a High-Level Object-Oriented Language (PDF). arXiv:1003.2547. CiteSeerX 10.1.1.763.7946. Retrieved 2022-03-17.
  5. ^ Dynace Object Oriented Extension To C
  6. ^ Newton, Jim; Rhodes, Christophe (28 November 2008). "Custom Specializers in Object-Oriented Lisp". Journal of Universal Computer Science. 14 (20): 3370–3388. CiteSeerX 10.1.1.523.2413. doi:10.3217/jucs-014-20-3370. S2CID 12032836. Retrieved 2022-03-17.
  7. ^ Tiny CLOS, developed by Gregor Kiczales

Literature

Read other articles:

Tanto Warsono Arban Wakil Bupati Pandeglang ke-4PetahanaMulai menjabat 23 Maret 2016PresidenJoko WidodoGubernurRano KarnoNata Irawan (Pj.)Wahidin Halim PendahuluHeryaniPenggantiPetahana Informasi pribadiLahir12 Januari 1983 (umur 41)Bandung, Jawa BaratKebangsaanIndonesiaPartai politikPartai Golongan KaryaAnak2Alma materUniversitas PadjadjaranSunting kotak info • L • B Tanto Warsono Arban, S.E., M.E. (lahir 12 Januari 1983) adalah pengusaha muda yang mulai menjadi pe...

 

Car, the GardenInformasi latar belakangNama lahirCha Jung-wonNama lainMayson the SoulLahir23 Oktober 1990 (umur 33)Korea SelatanGenreR&Bhip hopPekerjaanPenyanyipenulis laguInstrumenVokalTahun aktif2010–sekarangLabelDRDR ACNama KoreaHangul차정원 Alih AksaraCha Jeong-wonMcCune–ReischauerCh'a ChŏngwŏnNama panggungHangul카더가든 Alih AksaraKa Deo GadeunMcCune–ReischauerK'a Tŏ Kadŭn Cha Jung-won (Hangul: 차정원, lahir 23 Oktober 1990), secara profesional dikenal sebaga...

 

BrahmāSansekertaब्रह्मा BrahmāPāliब्रह्मा BrahmāBirmaဗြဟ္မာTionghoa梵天 (Pinyin: Fàntiān)Jepang梵天(ぼんてん) (romaji: Bonten)Korea범천 (RR: Beom Cheon)Thaiพระพรหม Phra PhromTibetཚངས་པ་Wylie: tshangs paTHL: tsangpaVietnamPhạm ThiênSinhalaබ්‍රහ්මයෝInformationDimuliakan olehTheravāda, Mahāyāna, VajrayanaPortal Agama Buddha Bagian dari seri tentangBuddhisme SejarahPenyebaran Sejarah Gari...

The Cardiff and Merthyr GuardianThe Cardiff and Merthyr guardian, Glamorgan, Monmouth, and Brecon gazetteTypeweekly newspaperPublisherHenry Webber EditorJames Emerson Williams[*]Launched4 January 1845 CityCardiff CountryWalesOCLC number751657429 Media of WalesList of newspapers The Cardiff and Merthyr Guardian was a weekly English language newspaper, supportive of conservative politics, which circulated throughout Glamorganshire, Monmouthshire and Breconshire. The newspaper's ...

 

Josep Joffre (atau nama lengkapnya Joseph Jacques Césaire Joffre; 12 Januari 1852 – 3 Januari 1931) adalah seorang jenderal Prancis pada Perang Dunia I, yang masuk dalam barisan bataille de la Marnedi tahun 1916. Artikel bertopik biografi Prancis ini adalah sebuah rintisan. Anda dapat membantu Wikipedia dengan mengembangkannya.lbs

 

Bagian dari Alkitab KristenPerjanjian LamaYosua 1:1 pada Kodeks Aleppo Taurat Kejadian Keluaran Imamat Bilangan Ulangan Sejarah Yosua Hakim-hakim Rut 1 Samuel 2 Samuel 1 Raja-raja 2 Raja-raja 1 Tawarikh 2 Tawarikh Ezra Nehemia Ester Puisi Ayub Mazmur Amsal Pengkhotbah Kidung Agung Kenabian Besar Yesaya Yeremia Ratapan Yehezkiel Daniel Kecil Hosea Yoël Amos Obaja Yunus Mikha Nahum Habakuk Zefanya Hagai Zakharia Maleakhi Deuterokanonika Tobit Yudit Tambahan Ester 1 Makabe 2 Makabe Kebijaksanaa...

Augustus, kaisar pertama Romawi. Lukisan yang menggambarkan Senat Romawi pada zaman republik. Pada zaman kekaisaran, kekuasaan senat banyak menurun dan bergeser ke tangan kaisar. Tata negara Kekaisaran Romawi diatur oleh konstitusi tidak tertulis berupa prinsip-prinsip dan garis-garis besar yang sebagian besar diwariskan turun-temurun sebagai preseden.[1] Setelah kejatuhan Republik Romawi yang dimulai dengan naiknya kaisar pertama Augustus, kekuasaan bergeser dari Senat Romawi kepada ...

 

PPI beralih ke halaman ini. Untuk kegunaan lain, lihat PPI (disambiguasi). Partai Pemuda Indonesia Ketua umumHoras SihombingSekretaris JenderalSyarir TamberoKantor pusatKasablanka, Jakarta SelatanIdeologiPancasila dan UUD 45 dan Partai TerbukaSitus webhttp://www.partaipemudaindonesia.com/Politik IndonesiaPartai politikPemilihan umum Partai Pemuda Indonesia (PPI) adalah sebuah partai politik di Indonesia yang didirikan pada tanggal 5 Maret 2007, oleh sekelompok aktivis dari Komite Nasional Pem...

 

Pesta Olahraga Asia Tenggara Ke-23Tuan rumahManila FilipinaMotoOne Heritage, One Southeast AsiaJumlah negara11Jumlah atlet5336Jumlah disiplin--- dari 42 cabangUpacara pembukaan27 November 2005Upacara penutupan5 Desember 2005Dibuka olehGloria Macapagal-ArroyoPresiden FilipinaJanji atletMikaela Mikee Cojuangco-JaworskiPenyalaan oborMary Antoinette RiveroTempat utamaQuirino Grandstand, Rizal Park← Hanoi - Ho Chi Min City 2003 Nakhon Ratchasima 2007 → Pesta Olahraga Asia Tenggara...

Шалфей обыкновенный Научная классификация Домен:ЭукариотыЦарство:РастенияКлада:Цветковые растенияКлада:ЭвдикотыКлада:СуперастеридыКлада:АстеридыКлада:ЛамиидыПорядок:ЯсноткоцветныеСемейство:ЯснотковыеРод:ШалфейВид:Шалфей обыкновенный Международное научное наз...

 

DillenialesRentang fosil: Eosen - saat ini PreЄ Є O S D C P T J K Pg N Hibbertia stellaris Klasifikasi ilmiah Kerajaan: Plantae (tanpa takson): Angiospermae (tanpa takson): Eudikotil (tanpa takson): Core Eudikotil Ordo: Dilleniales Famili lihat teks. Dilleniales adalah salah satu ordo anggota tumbuhan berbunga yang termasuk dalam anak kelas Dilleniidae, kelas Magnoliopsida, [1]menurut Sistem klasifikasi Cronquist (1981). Ada dua famili yang termasuk di dalamnya: Dilleniaceae dan Pa...

 

SuippescomuneSuippes – Veduta LocalizzazioneStato Francia RegioneGrand Est Dipartimento Marna ArrondissementChâlons-en-Champagne CantoneArgonne Suippe et Vesle TerritorioCoordinate49°08′N 4°32′E / 49.133333°N 4.533333°E49.133333; 4.533333 (Suippes)Coordinate: 49°08′N 4°32′E / 49.133333°N 4.533333°E49.133333; 4.533333 (Suippes) Superficie41,97 km² Abitanti3 991[1] (2009) Densità95,09 ab./km² Altre informazion...

American spree killer (1969–1997) Andrew CunananCunanan in April 1997FBI Ten Most Wanted FugitiveChargesFirst-degree murderSecond-degree murderArmed robberyDescriptionBornAndrew Phillip Cunanan(1969-08-31)August 31, 1969National City, California, U.S.DiedJuly 23, 1997(1997-07-23) (aged 27)Miami Beach, Florida, U.S.Cause of deathSuicide by gunshotStatusAddedJune 12, 1997Number449Deceased prior to capture Andrew Phillip Cunanan (August 31, 1969 – July 23, 1997) was an American spree ki...

 

Australian financial services company 33°51′59″S 151°12′15″E / 33.866318°S 151.204190°E / -33.866318; 151.204190 BT Financial GroupCompany typeSubsidiary of WestpacIndustryWealth ManagementFounded1969HeadquartersSydney, AustraliaNumber of locationsCorporate Head Office in Barangaroo, SydneyArea servedAustralia, New ZealandProductsWealth managementAUM A$46 billion (2022)[1]Website[1] BT, formerly BT Financial Group, is a financial-services company ba...

 

此条目序言章节没有充分总结全文内容要点。 (2019年3月21日)请考虑扩充序言,清晰概述条目所有重點。请在条目的讨论页讨论此问题。 哈萨克斯坦總統哈薩克總統旗現任Қасым-Жомарт Кемелұлы Тоқаев卡瑟姆若马尔特·托卡耶夫自2019年3月20日在任任期7年首任努尔苏丹·纳扎尔巴耶夫设立1990年4月24日(哈薩克蘇維埃社會主義共和國總統) 哈萨克斯坦 哈萨克斯坦政府...

Artikel ini tidak memiliki referensi atau sumber tepercaya sehingga isinya tidak bisa dipastikan. Tolong bantu perbaiki artikel ini dengan menambahkan referensi yang layak. Tulisan tanpa sumber dapat dipertanyakan dan dihapus sewaktu-waktu.Cari sumber: Sekolah Tinggi Ilmu Ekonomi AUB – berita · surat kabar · buku · cendekiawan · JSTOR Sekolah Tinggi Ilmu Ekonomi AUBNama lainSTIE AUBMotoMuluk Kondang Kusumaning BawonoJenisPerguruan Tinggi SwastaDidirika...

 

2016 mass shooting in Orlando, Florida, US Pulse nightclub shootingPart of mass shootings in the United States, violence against LGBT people in the United States, and Islamic terrorism in the United StatesThe scene of the shootingOrlandoOrlando (Florida) 150m160yds 1  LocationPulse Nightclub1912 S. Orange AvenueOrlando, Florida, U.S.Coordinates28°31′10.5″N 81°22′36.5″W / 28.519583°N 81.376806°W / 28.519583; -81.376806DateJune 12, 2016; 7 ye...

 

Solution of Einstein field equations General relativity G μ ν + Λ g μ ν = κ T μ ν {\displaystyle G_{\mu \nu }+\Lambda g_{\mu \nu }={\kappa }T_{\mu \nu }} Introduction HistoryTimelineTests Mathematical formulation Fundamental concepts Equivalence principle Special relativity World line Pseudo-Riemannian manifold Phenomena Kepler problem Gravitational lensing Gravitational redshift Gravitational time dilation Gravitational waves Frame-drag...

Heraldic animal This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Biscione – news · newspapers · books · scholar · JSTOR (September 2016) (Learn how and when to remove this message) The coat of arms of the Visconti of Milan showing the biscione wearing a crown The biscione[a] (English: big grass snake)...

 

The Synod of Whitby was a Christian administrative gathering held in Northumbria in 664, wherein King Oswiu ruled that his kingdom would calculate Easter and observe the monastic tonsure according to the customs of Rome rather than the customs practised by Irish monks at Iona and its satellite institutions. The synod was summoned at Hilda's double monastery of Streonshalh (Streanæshalch), later called Whitby Abbey. Sources A manuscript of Bede's Historia Ecclesiastica gentis Anglorum. There...