The Art of the Metaobject Protocol Chapters 5 and 6
The Art of the Metaobject Protocol Chapters 5 and 6
The Art of the Metaobject Protocol Chapters 5 and 6
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>The</strong> <strong>Art</strong> <strong>of</strong> <strong>the</strong> <strong>Metaobject</strong> <strong>Protocol</strong><br />
<strong>Chapters</strong> 5<strong>and</strong> 6<br />
Gregor Kiczales, Jim des Rivieres, <strong>and</strong> DanielG.Bobrow<br />
Xerox Palo Alto Research Center<br />
c 1991 MIT Press. <strong>The</strong> material i ncl uded here compri ses chapters 5 <strong>and</strong> 6 <strong>of</strong> \<strong>The</strong> <strong>Art</strong><strong>of</strong><br />
<strong>the</strong><strong>Metaobject</strong> <strong>Protocol</strong>." MITPress is expected to publishthis entire workin<strong>the</strong>summer<br />
<strong>of</strong> 1991. Pl ease see page 1 f or f ur<strong>the</strong>r i nformati on about <strong>the</strong>copyri ght <strong>of</strong>this material.
ontent s<br />
5 Concepts 3<br />
Introducti on :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 3<br />
Metaobj ects : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 3<br />
Cl asses :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4<br />
Sl ot Denitions : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4<br />
Generi c Functi ons :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 5<br />
Methods : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6<br />
Speci al i zers ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6<br />
Method Combinati ons : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6<br />
Inheri tance Structure <strong>of</strong> Metaobj ect Classes : : : : : : : : : : : : : : : : : : : : : : 6<br />
Implementation<strong>and</strong>User Specialization : : : : : : : : : : : : : : : : : : : : 8<br />
Processing<strong>of</strong><strong>the</strong>User Interface Macros : : : : : : : : : : : : : : : : : : : : : : : 11<br />
Compile-le Processing<strong>of</strong><strong>the</strong>User Interface Macros : : : : : : : : : : : : : 12<br />
<strong>The</strong> defcl ass Macro : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 12<br />
<strong>The</strong> defmethod Macro : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 16<br />
ProcessingMethod Bodies :: : : : : : : : : : : : : : : : : : : : : : : : : : : : 17<br />
<strong>The</strong> def generi c Macro : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 19<br />
Subprotocols :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 20<br />
Metaobj ect I nitialization<strong>Protocol</strong>s : : : : : : : : : : : : : : : : : : : : : : : 20<br />
Class Finalization<strong>Protocol</strong> : : : : : : : : : : : : : : : : : : : : : : : : : : : 22<br />
Instance Structure <strong>Protocol</strong> : :: : : : : : : : : : : : : : : : : : : : : : : : : : 23<br />
Funcallable Instances ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 25<br />
Generi c Functi on Invocati on <strong>Protocol</strong> ::<br />
: : : : : : : : : : : : : : : : : : : : 26<br />
Dependent Mai ntenance <strong>Protocol</strong> : : : : : : : : : : : : : : : : : : : : : : : : : 26<br />
6 Generic Functi ons <strong>and</strong> Methods 29<br />
add-dependent : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 30<br />
add-di rect-method :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 31<br />
add-di rect-subcl ass : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 32<br />
add-method : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 33<br />
i
ii<br />
CONTENTS<br />
allocate-instance : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 34<br />
class-:::: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 35<br />
compute-applicable-methods :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 35<br />
compute-applicable-methods-using- cl asses : : : : : : : : : : : : : : : : : : : : : : : 36<br />
compute-class-precedence-list : ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : 38<br />
compute-default-ini targs : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 39<br />
compute-discriminati ng- f uncti on : : : : : : : : : : : : : : : : : : : : : : : : : : : 40<br />
compute-eecti ve-method :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 41<br />
compute-eecti ve-sl ot-denition : : : : : : : : : : : : : : : : : : : : : : : : : : : : 42<br />
compute-slots :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 43<br />
direct-slot-denition-class : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 45<br />
eecti ve-sl ot-denition-class : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 45<br />
ensure-class : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 46<br />
ensure-class-using- cl ass : : :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 47<br />
ensure-generi c-functi on : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 49<br />
ensure-generi c-functi on-using- cl ass : : ::<br />
: : : : : : : : : : : : : : : : : : : : : : : 50<br />
eql -speci al i zer-object : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 52<br />
extract-lambda- l i st : :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 52<br />
extract-speci al i zer-names : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 53<br />
nalize-inheri tance : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 54<br />
nd-method-combination : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 54<br />
funcallable-st<strong>and</strong>ard-instance-access : : : : : : : : : : : : : : : : : : : : : : : : : 55<br />
generi c-functi on- :::: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 56<br />
Initialization<strong>of</strong> Class Metaobj ects : : : : : : : : : : : : : : : : : : : : : : : : : : 57<br />
Initialization<strong>of</strong> Generi c Functi on Metaobj ects : : : : : : : : : : : : : : : : : : : : 61<br />
Initialization<strong>of</strong> Method Metaobj ects : : : : : : : : : : : : : : : : : : : : : : : : : 64<br />
Initialization<strong>of</strong> Slot DenitionMetaobj ects : : : : : : : : : : : : : : : : : : : : : 67<br />
intern-eql-speci al i zer : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 70<br />
make-i nstance : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 70<br />
make-method-lambda : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 71<br />
map-dependents : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 73<br />
method- ::: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 74<br />
Readers f or Class Metaobj ects : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 75<br />
Readers f or Generi c Functi on Metaobj ects ::<br />
: : : : : : : : : : : : : : : : : : : : : 79<br />
Readers f or Method Metaobj ects :: : : : : : : : : : : : : : : : : : : : : : : : : : : 81<br />
Readers f or Slot DenitionMetaobj ects : :: : : : : : : : : : : : : : : : : : : : : : 83<br />
reader-method-class : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 86<br />
remove-dependent : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 87<br />
remove-di rect-method :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 89<br />
remove-di rect-subcl ass : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 90<br />
remove-method : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 91<br />
set-funcallable-instance-functi on : : ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : 91
CONTENTS<br />
iii<br />
(setf class-name) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 92<br />
(setf generi c-functi on-name) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 92<br />
(setf slot-val ue-using- cl ass) : : ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : 93<br />
slot-boundp-using- cl ass : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 94<br />
slot-denition- :::: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 95<br />
slot-makunbound-using- cl ass ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : : 96<br />
slot-val ue-using- cl ass : ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 97<br />
speci al i zer-di rect-generic-functi: ons : : : : : : : : : : : : : : : : : : : : : : : : : 98<br />
speci al i zer-di rect-methods : ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : 99<br />
st<strong>and</strong>ard-instance-access : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :100<br />
update- dependent : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :101<br />
validate-supercl ass : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :102<br />
writer-method-class ::<br />
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :103
iv<br />
CONTENTS
In this part <strong>of</strong> <strong>the</strong> book, weprovide<strong>the</strong>detailedspeci cati on <strong>of</strong> a metaobj ect protocol<br />
for CLOS. Our work withthis protocol has al ways been rooted i n our ownimplementation<br />
<strong>of</strong> CLOS, PCL. This has made itpossible for ustohave auser community, whichinturn<br />
has provided us wi th feedback on this protocol as it has evol ved. As a result, much <strong>of</strong> <strong>the</strong><br />
desi gn presented here i s well-tested <strong>and</strong> stable. As this is bei ng written, those parts have<br />
been i mplemented not onlyinPCL, but inatleastthree o<strong>the</strong>r CLOS implementationswe<br />
know<strong>of</strong> . O<strong>the</strong>r parts <strong>of</strong> <strong>the</strong>protocol, even though <strong>the</strong>y have been i mplementedinone f orm<br />
or ano<strong>the</strong>r i n PCL <strong>and</strong>o<strong>the</strong>r i mplementations, are less wel l worked out. Work remai ns<br />
to improve not only <strong>the</strong>ease<strong>of</strong>use <strong>of</strong> <strong>the</strong>se protocols, but also <strong>the</strong>bal ance <strong>the</strong>y provide<br />
between user extensibility<strong>and</strong>implementor freedom.<br />
Inprepari ng this speci cati on, itisourhope that i t will provideabasi s f or <strong>the</strong> users <strong>and</strong><br />
implementors whowishtowork withametaobj ect protocol for CLOS. This documentshould<br />
not be construed as any sort <strong>of</strong> nal word or st<strong>and</strong>ard, but ra<strong>the</strong>r onl y as documentation<br />
<strong>of</strong> what has been done s<strong>of</strong>ar. We l ook f orward to seei ng<strong>the</strong>improvements, both smal l <strong>and</strong><br />
large, whichwehope this publicationwill catalyze.<br />
Tothis end, f or Part I I only(chapters 5 <strong>and</strong>6), wegrantpermissionto prepare revisions<br />
or o<strong>the</strong>r deri vati ve works incl udinganyamount <strong>of</strong> <strong>the</strong> ori gi nal text. We askonly that<br />
you properl y acknowledge <strong>the</strong> source <strong>of</strong> <strong>the</strong> ori gi nal text <strong>and</strong>explicitly allowsubsequent<br />
revisions<strong>and</strong>deri vati ve works under <strong>the</strong> sameterms. T<strong>of</strong>ur<strong>the</strong>r facilitate improvements in<br />
this work, wehave made <strong>the</strong> electronic source for <strong>the</strong>se chapters publiclyavai l able; it can<br />
be accessed byanonymous FTPfrom<strong>the</strong> /pcl/mop di rectory on arisia.xerox.com.<br />
In additionto <strong>the</strong>val uable feedback f romusers <strong>of</strong> PCL, <strong>the</strong>protocol desi gn presented<br />
here has beneted fromdetailedcomments <strong>and</strong>suggesti ons by<strong>the</strong> followingpeople: Kim<br />
Barrett, Scott Cyphers, Harley Davis, Patrick Dussud, John Foderaro, Richard P. Gabriel,<br />
DavidGray,DavidA. Moon, Andreas Paepcke, Chris Richardson,Wal ter van Roggen, <strong>and</strong><br />
Jon L. White. Wearevery grateful to each <strong>of</strong> <strong>the</strong>m. Any remai ning errors, inconsistenci es<br />
or desi gn deci enci es are <strong>the</strong> responsibility<strong>of</strong> <strong>the</strong>authors al one.
2 CONTENTS
a<br />
ter<br />
on e ts<br />
Introduction<br />
<strong>The</strong> CLOS Speci cati on [X3J13 , CLtLII]descri bes <strong>the</strong> st<strong>and</strong>ard Programmer Interface for<br />
<strong>the</strong> Common Lisp Object System(CLOS). This document extends that speci cati on by<br />
deningametaobj ect protocol for CLOS|that i s, a descri pti on <strong>of</strong> CLOS i tsel f as an extensible<br />
CLOS program. In this descri ption, <strong>the</strong>fundamental elements <strong>of</strong> CLOS programs<br />
(classes, slot denitions, generi c functi ons, methods, speci al i zers <strong>and</strong>method combinati ons)<br />
are represented byrst-class objects. <strong>The</strong> behavior <strong>of</strong> CLOS is provided by<strong>the</strong>se objects,<br />
or, more preci sel y, bymethods speci al i zed to <strong>the</strong> classes <strong>of</strong> <strong>the</strong>se objects.<br />
Because <strong>the</strong>se objects represent pi eces <strong>of</strong> CLOS programs, <strong>and</strong>because <strong>the</strong>i r behavior<br />
provides <strong>the</strong> behavior <strong>of</strong> <strong>the</strong>CLOS language i tsel f , <strong>the</strong>y are considered meta- l evel objects<br />
or metaobj ects. <strong>The</strong> protocol followed by<strong>the</strong>metaobj ects to provide<strong>the</strong>behavior <strong>of</strong> CLOS<br />
is called<strong>the</strong>CLOS Metaobj ect <strong>Protocol</strong> (MOP).<br />
etaobjects<br />
For each kind<strong>of</strong> programel ement <strong>the</strong>re is a corresponding basic metaobject class. <strong>The</strong>se<br />
are <strong>the</strong> classes: class, slot-denition, generi c- functi on, method <strong>and</strong> method-combi -<br />
nation. A met aobj ect cl ass is a subcl ass <strong>of</strong> exactl y one <strong>of</strong><strong>the</strong>se classes. <strong>The</strong> results are<br />
undened i f an attempt ismade todene a cl ass that i s a subclass<strong>of</strong>more than one basi c<br />
metaobj ect cl ass. Amet aobj ect is aninstance <strong>of</strong> a metaobj ect cl ass.<br />
Each metaobj ect represents oneprogramel ement. Associ ated wi<strong>the</strong>achmetaobj ect i s<br />
<strong>the</strong> information required to serve its role. This incl udes i nformati on that mightbe provided<br />
directly ina user interface macro such as def cl ass or def method. It also incl udes<br />
informati on computed indirectlyfromo<strong>the</strong>r metaobj ects such as that computed fromcl ass<br />
inheri tance or <strong>the</strong> full set <strong>of</strong> methods associ ated wi th a generi c functi on.<br />
3
4 CHAPTER 5. CONCEPTS<br />
Much <strong>of</strong> <strong>the</strong> informati on associ ated with a metaobj ect i s i n <strong>the</strong> f orm<strong>of</strong> connecti ons<br />
to o<strong>the</strong>r metaobj ects. This interconnecti on means that <strong>the</strong> role<strong>of</strong>ametaobj ect i s al ways<br />
based on that <strong>of</strong> o<strong>the</strong>r metaobj ects. As an introducti on to this interconnected structure,<br />
this sectionpresents a partial enumeration<strong>of</strong> <strong>the</strong>kinds <strong>of</strong>informati on associ ated wi th each<br />
kind<strong>of</strong> metaobj ect. More detailedinformati on i s presented l ater.<br />
lasses<br />
Acl ass met aobj ect determines <strong>the</strong> structure <strong>and</strong><strong>the</strong>default behavior <strong>of</strong> its instances. <strong>The</strong><br />
followinginformati on i s associ ated withclass metaobj ects:<br />
<strong>The</strong> name, i f <strong>the</strong>re i s one, i s avai l abl e as an obj ect.<br />
<strong>The</strong> di rect subclasses, di rect supercl asses <strong>and</strong>class precedence list are avai l able as lists<br />
<strong>of</strong> cl ass metaobj ects.<br />
<strong>The</strong> slots dened directly in <strong>the</strong> cl ass are avai l able as a list <strong>of</strong> di rect sl ot denition<br />
metaobj ects. <strong>The</strong> slotswhich are accessible ininstances <strong>of</strong> <strong>the</strong> cl ass are avai l abl e as a<br />
list <strong>of</strong> eecti ve slotdenitionmetaobj ects.<br />
<strong>The</strong> documentationis avai l able as a stringornil.<br />
<strong>The</strong> methods whichuse <strong>the</strong> cl ass as a speci al i zer, <strong>and</strong><strong>the</strong>generi c functi ons associ ated<br />
with those methods are availabl e as l i sts <strong>of</strong> method <strong>and</strong> generi c functi on metaobj ects<br />
respecti vel y.<br />
Sl ot e niti ons<br />
Asl ot de ni t i on met aobj ect containsinformati onabout <strong>the</strong>denition<strong>of</strong> aslot. <strong>The</strong>re are two<br />
kinds <strong>of</strong>slotdenitionmetaobj ects. Adi rect sl ot denitionmetaobj ect i s used to represent<br />
<strong>the</strong>di rect denition<strong>of</strong> aslot inaclass. This corresponds roughlyto <strong>the</strong>slotspeci ers found<br />
indef cl ass forms. Aneecti ve slotdenitionmetaobj ect i s used to representinformati on,<br />
incl udinginheri ted i nformati on, about a sl ot whi ch i s accessi ble ininstances <strong>of</strong> a particular<br />
class.<br />
Associ ated wi<strong>the</strong>achclass metaobj ect i s a l i st <strong>of</strong> di rect sl ot denitionmetaobj ects representing<strong>the</strong>slotsdened<br />
directlyin<strong>the</strong> class. Al so associ ated wi<strong>the</strong>achclass metaobj ect<br />
is a list <strong>of</strong> eecti ve slot denition metaobj ects representing<strong>the</strong> set <strong>of</strong> sl ots accessi ble in<br />
instances <strong>of</strong> that cl ass.<br />
<strong>The</strong> followinginformati on i s associ ated with both di rect <strong>and</strong> eecti ve slotdenitions<br />
metaobj ects:<br />
<strong>The</strong> name, al l ocati on, <strong>and</strong>type areavai l able as formsthat couldappear i n a def cl ass<br />
form.
ETAO JECTS 5<br />
<strong>The</strong> initialization f orm, if <strong>the</strong>re is one, i s avai l abl e as a f ormthat could appear i n a<br />
def cl ass form. <strong>The</strong> initializationformtoge<strong>the</strong>r withits lexical environment isavai l able<br />
as a f uncti on <strong>of</strong> no arguments which, when cal l ed, returns <strong>the</strong>result <strong>of</strong> eval uati ng <strong>the</strong><br />
initializationforminits lexical environment. This is called<strong>the</strong> init unct i on <strong>of</strong> <strong>the</strong> slot.<br />
<strong>The</strong> slotllinginitializationarguments are avai l able as alist <strong>of</strong> symbol s.<br />
<strong>The</strong> documentationis avai l able as a stringornil.<br />
Certaino<strong>the</strong>r i nformati on i s onl y associ ated withdi rect sl ot denitionmetaobj ects. This<br />
informati on applies only to <strong>the</strong>di rect denition<strong>of</strong> <strong>the</strong>slotin<strong>the</strong> class (it is not i nheri ted).<br />
<strong>The</strong> functi on names <strong>of</strong> those generi c functi ons f or which<strong>the</strong>re are automati cal l y generated<br />
reader <strong>and</strong>writer methods. This informati on i s avai l abl e as l i sts <strong>of</strong> f uncti on names.<br />
Anyaccessors speci ed i n <strong>the</strong> def cl ass formare broken downinto <strong>the</strong>i r equival ent readers<br />
<strong>and</strong>writers in <strong>the</strong>di rect sl ot denition.<br />
Informati on, incl udinginheri ted i nformation,whichapplies to<strong>the</strong>denition<strong>of</strong> aslot in<br />
aparticular class in whi ch i t i s accessi bl e i s associ ated only with eecti ve slotdenition<br />
metaobj ects.<br />
For certain slots, <strong>the</strong> l ocati on <strong>of</strong> <strong>the</strong> slotininstances <strong>of</strong> <strong>the</strong> class is avai l able.<br />
eneri c<br />
uncti ons<br />
Ageneri c unct i on met aobj ect containsinformati on about a generi c functionover <strong>and</strong>above<br />
<strong>the</strong>informati on associ ated wi th each <strong>of</strong> <strong>the</strong> generi c functi on's methods.<br />
<strong>The</strong> name isavai l abl e as a f uncti on name.<br />
<strong>The</strong> methods associ ated with <strong>the</strong> generi c functi on are avai l able as a list <strong>of</strong> method<br />
metaobj ects.<br />
<strong>The</strong> defaul t cl ass f or thi s generi c functi on's method metaobj ects i s available as a class<br />
metaobj ect.<br />
<strong>The</strong> lambdalist is available as alist.<br />
<strong>The</strong> method combinati on i s avai l able as a method combinati onmetaobj ect.<br />
<strong>The</strong> documentationis avai l able as a stringornil.<br />
<strong>The</strong> argument precedence order i s avai l able as apermutation<strong>of</strong> those symbol s f rom<strong>the</strong><br />
lambdalist whichname <strong>the</strong>requi red arguments <strong>of</strong> <strong>the</strong>generi c functi on.
6 CHAPTER 5 . CONCEPTS<br />
<strong>The</strong> decl arati ons areavai l able as alist <strong>of</strong> decl arati ons.<br />
erminology ote:<br />
<strong>The</strong>re i s someambiguityinCommon Lispabout <strong>the</strong>termsusedto identify<strong>the</strong>vari ous<br />
parts <strong>of</strong> decl are speci al forms. Inthis document, <strong>the</strong>termdecl arat i on is usedtorefer<br />
to an obj ect that couldbeanargument toadecl are speci al form. For example, in<br />
<strong>the</strong>speci al form(decl are (speci al *g1*)), <strong>the</strong> list (speci al *g1*) is adecl arati on.<br />
et o s<br />
Amet hod met aobj ect containsinformati on about aspeci c method.<br />
<strong>The</strong> qualiers are avai l able as alist <strong>of</strong> <strong>of</strong> non-nul l atoms.<br />
<strong>The</strong> lambdalist is available as alist.<br />
<strong>The</strong> speci al i zers are avai l able as alist <strong>of</strong> speci al i zer metaobj ects.<br />
<strong>The</strong> functi on i s availabl e as a f uncti on. This functi on can be appliedtoarguments <strong>and</strong><br />
alist <strong>of</strong> next methods using applyor funcall.<br />
When <strong>the</strong>methodi s associ ated wi th a generi c functi on, that generi c functi onmetaobj ect<br />
is avai l able. Amethod can be associ ated withat most one generi c functi on at a ti me.<br />
<strong>The</strong> documentationis avai l able as a stringornil.<br />
S<br />
ecializers<br />
Aspeci al i zer metaobj ect represents <strong>the</strong> speci al i zers <strong>of</strong> a method. Class metaobj ects are<br />
<strong>the</strong>mselves speci al i zer metaobj ects. Aspeci al kind<strong>of</strong> speci al i zer metaobj ect i s used for eql<br />
speci al i zers.<br />
et o o inati ons<br />
Amet hod combi nat i on met aobj ect represents <strong>the</strong>informati onabout <strong>the</strong>method combination<br />
bei ngused by a generi c functi on.<br />
ote:<br />
This document does not speci fy <strong>the</strong> structure <strong>of</strong> method combinati on metaobj ects.<br />
In eritance tructure o etaobject lasses<br />
<strong>The</strong> inheri tance structure <strong>of</strong> <strong>the</strong>speci ed metaobj ect cl asses i s shown inTabl e 5. 1.<br />
Each cl ass marked witha\3" isanabst ract cl ass <strong>and</strong> is not i ntended to be instantiated.<br />
<strong>The</strong> results are undened i f an attempt ismade tomake aninstance <strong>of</strong> one <strong>of</strong><strong>the</strong>se classes<br />
withma e- i nstance.
NHER TANCE S TR CT RE O ETAO JECT C ASSES 7<br />
<strong>Metaobject</strong> Class i rect upercl asses<br />
st<strong>and</strong>ard-object<br />
(t)<br />
funcallable-st<strong>and</strong>ard-object (st<strong>and</strong>ard-object functi on)<br />
3 metaobject (st<strong>and</strong>ard-object)<br />
3 generi c- f uncti on (metaobject<br />
funcallable-st<strong>and</strong>ard-object)<br />
st<strong>and</strong>ard-generi c- f uncti on (generi c- f uncti on)<br />
3 method (metaobject)<br />
st<strong>and</strong>ard-method<br />
(method)<br />
3 st<strong>and</strong>ard-accessor-method (st<strong>and</strong>ard-method)<br />
st<strong>and</strong>ard-reader- method (st<strong>and</strong>ard-accessor-method)<br />
st<strong>and</strong>ard-wri ter-method (st<strong>and</strong>ard-accessor-method)<br />
3 method-combinati on (metaobject)<br />
3 slot-denition (metaobject)<br />
3 direct-slot-denition (slot-denition)<br />
3 e ecti ve- sl ot-denition (slot-denition)<br />
3 st<strong>and</strong>ard-slot-denition (slot-denition)<br />
st<strong>and</strong>ard-direct-slot- (st<strong>and</strong>ard-slot-denition<br />
denition<br />
di rect- sl ot-denition)<br />
st<strong>and</strong>ard-e ecti ve- sl ot- (st<strong>and</strong>ard-slot-denition<br />
denition<br />
e ecti ve- sl ot-denition)<br />
3 speci al i zer (metaobject)<br />
eql-speci alizer<br />
(speci alizer)<br />
3 cl ass (speci alizer)<br />
built-in-class<br />
(class)<br />
forward- ref erenced-class (class)<br />
st<strong>and</strong>ard-class<br />
(class)<br />
funcallable-st<strong>and</strong>ard-class (class)<br />
a e .1 r r r .<br />
r a a - a r<br />
- - a e e -<br />
a a - e e - r a a e-<br />
a a - a .
8 CHAPTER 5 . CONCEPTS<br />
<strong>The</strong> classes st<strong>and</strong>ard-class, st<strong>and</strong>ard-di rect- sl ot-denition, st<strong>and</strong>ard-e ecti veslot-denition,<br />
st<strong>and</strong>ard-method, st<strong>and</strong>ard-reader- method, st<strong>and</strong>ard-writermethod<br />
<strong>and</strong> st<strong>and</strong>ard-generic-functi on are cal l ed st<strong>and</strong>ard met aobj ect cl asses. For<br />
each kind<strong>of</strong> metaobj ect, this is <strong>the</strong> class <strong>the</strong>user interface macros presented in <strong>the</strong>CLOS<br />
Speci cati on use bydefault. <strong>The</strong>se are also <strong>the</strong> classes on whichuser specializations are<br />
normal l y based.<br />
<strong>The</strong> classes built-in-class, funcallable-st<strong>and</strong>ard-class <strong>and</strong> forward- ref erencedcl<br />
ass are speci al -purpose cl ass metaobj ect cl asses. Built-in classes are instances <strong>of</strong> <strong>the</strong><br />
cl ass built-in-class. <strong>The</strong> class funcallable-st<strong>and</strong>ard-class provides a speci al kind<strong>of</strong><br />
instances descri bed i n <strong>the</strong> section called \Funcal lable Instances. " When <strong>the</strong> denition <strong>of</strong><br />
a class references ano<strong>the</strong>r cl ass which has not yet been dened, an instance <strong>of</strong> forwardreferenced-class<br />
is used as a st<strong>and</strong>-inuntil <strong>the</strong> class is actuallydened.<br />
<strong>The</strong> classst<strong>and</strong>ard-object is <strong>the</strong> de aul t di rect su ercl ass <strong>of</strong> <strong>the</strong> classst<strong>and</strong>ard-class.<br />
When an i nstance <strong>of</strong> <strong>the</strong> class st<strong>and</strong>ard-class i s created, <strong>and</strong>nodi rect superclasses are<br />
explicitly speci ed, it defaults to <strong>the</strong>class st<strong>and</strong>ard-object. In this way, anybehavior<br />
associ ated with<strong>the</strong>classst<strong>and</strong>ard-object will beinheri ted, directly or indirectly, byall<br />
instances <strong>of</strong> <strong>the</strong> classst<strong>and</strong>ard-class. Asubcl ass <strong>of</strong> st<strong>and</strong>ard-class may have adierent<br />
cl ass as i ts default di rect supercl ass, but that cl ass must beasubcl ass <strong>of</strong> <strong>the</strong> classst<strong>and</strong>ardobject.<br />
<strong>The</strong> same is trueforfuncallable-st<strong>and</strong>ard-class <strong>and</strong> funcallable-st<strong>and</strong>ard-object.<br />
<strong>The</strong> classspeci alizercaptures only<strong>the</strong>most basi c behavior <strong>of</strong> method speci al i zers, <strong>and</strong><br />
is not itself intended to be instantiated. <strong>The</strong> classcl ass is adi rect subcl ass <strong>of</strong> speci alizer<br />
re ecti ng <strong>the</strong>property that cl asses by <strong>the</strong>mselves can be used as method speci al i zers. <strong>The</strong><br />
cl ass eql-speci alizer is used for eql speci al i zers.<br />
le entati on an ser S ecializati on<br />
<strong>The</strong> purpose <strong>of</strong> <strong>the</strong> Metaobj ect <strong>Protocol</strong> is to provideusers withapowerful mechanismfor<br />
extending<strong>and</strong>customizing<strong>the</strong>basi c behavior <strong>of</strong> <strong>the</strong>Common LispObject System. Asan<br />
object-ori ented descri pti on <strong>of</strong> <strong>the</strong> basi c CLOS behavior, <strong>the</strong>Metaobj ect <strong>Protocol</strong> makes i t<br />
possible to create <strong>the</strong>se extensionsbydeningspeci al i zed subclasses <strong>of</strong> existingmetaobj ect<br />
classes.<br />
<strong>The</strong> Metaobj ect <strong>Protocol</strong> provides this capability without interferingwith <strong>the</strong> implementor's<br />
abilityto devel op high-performance i mplementations. This bal ance between user<br />
extensibility<strong>and</strong>implementor freedomis mediatedbyplacingexplicit restrictions on each.<br />
Some <strong>of</strong><strong>the</strong>se restrictions are general |<strong>the</strong>y apply to <strong>the</strong>entire class graph<strong>and</strong><strong>the</strong>applicability<strong>of</strong><br />
all methods. <strong>The</strong>se are presented in this section.<br />
<strong>The</strong> followingadditional terminol ogy i s used to present<strong>the</strong>se restrictions:
NHER TANCE S TR CT RE O ETAO JECT C ASSES 9<br />
Metaobj ects are divided i nto three categori es. Those dened i n this document are<br />
called s eci ed; those dened by animplementati on but not mentioned i n this document<br />
are called imlementation-s eci c; <strong>and</strong>those dened byaportable programare<br />
called ort abl e.<br />
Aclass is inter osed between twoo<strong>the</strong>r cl asses<strong>and</strong> if <strong>and</strong>onlyif <strong>the</strong>re i s some<br />
path, followingdi rect superclasses, from<strong>the</strong>class to <strong>the</strong>class whichincl udes .<br />
Amethod i s s eci al i ed t o a class if <strong>and</strong>only if that cl ass i s i n <strong>the</strong> list <strong>of</strong> speci al i zers<br />
associ ated with<strong>the</strong>method; <strong>and</strong><strong>the</strong>methodis in<strong>the</strong> list <strong>of</strong> methods associ ated with<br />
somegeneri c functi on.<br />
Ina givenimplementation,aspeci ed methodis saidtohave been romot ed if <strong>and</strong>only<br />
if <strong>the</strong>speci al i zers <strong>of</strong> <strong>the</strong> method,: :: ,aredened i n this speci cati on as <strong>the</strong> classes<br />
::: , but in<strong>the</strong>implementation,oneormore <strong>of</strong> <strong>the</strong> speci al i zers i, is a supercl ass<br />
<strong>of</strong> <strong>the</strong> cl ass gi ven i n <strong>the</strong> speci cati i. on<br />
For a gi ven generi c functi on <strong>and</strong> set <strong>of</strong> arguments, a method e tends amethod<br />
if <strong>and</strong>onlyif:<br />
(i) <strong>and</strong> are both associ ated with<strong>the</strong>given generi c functi on,<br />
(ii) <strong>and</strong> are both applicable to <strong>the</strong>given arguments,<br />
(iii) <strong>the</strong> speci al i zers <strong>and</strong> qualiers <strong>of</strong> <strong>the</strong> methods are such that when <strong>the</strong> generi c<br />
functionis called, is executed bef ore ,<br />
(iv) will beexecuted if <strong>and</strong>onlyif call-ne t-methodis invoked fromwithin<strong>the</strong><br />
body <strong>of</strong> <strong>and</strong><br />
(v) call-ne t-method is invoked fromwithin<strong>the</strong>body <strong>of</strong> , <strong>the</strong>rebycausing<br />
to beexecuted.<br />
For a gi ven generi c functi on <strong>and</strong> set <strong>of</strong> arguments, a method o erri des amethod<br />
if <strong>and</strong>onlyif conditionsithrough i v above hol d <strong>and</strong><br />
,<strong>the</strong>rebyprevent-<br />
(v) call-ne t-methodis not i nvoked fromwithin<strong>the</strong>body <strong>of</strong><br />
ing frombei ngexecuted.<br />
estrictions on mplementations<br />
Implementations are allowedlatitude tomodify<strong>the</strong> structure <strong>of</strong> speci ed cl asses <strong>and</strong>methods.<br />
This incl udes: <strong>the</strong>interposition<strong>of</strong> implementation-speci c classes; <strong>the</strong>promoti on <strong>of</strong><br />
speci ed methods; <strong>and</strong><strong>the</strong> consolidati on <strong>of</strong> two or more speci ed methods into a singl e<br />
method speci al i zed to i nterposed classes.<br />
Any such modicati ons arepermitted onlyso long as f or any portabl e cl ass p that i s<br />
asubcl ass <strong>of</strong> one ormore speci ed cl asses::: i, <strong>the</strong> followingconditionsaremet:
10 CHAPTER 5 . CONCEPTS<br />
In <strong>the</strong>actual cl ass precedence list <strong>of</strong> p, <strong>the</strong> classes ::: i must appear i n <strong>the</strong> same<br />
order as <strong>the</strong>y wouldhave if noimplementation-speci c modicati ons had been made.<br />
<strong>The</strong> method applicabi l i ty <strong>of</strong> any speci ed generi c functi on must be<strong>the</strong>sameinterms<br />
<strong>of</strong> behaviorasitwouldhave been had no implementation-speci c changes been made.<br />
This incl udes speci ed generi c functi ons that have had portable methods added. In this<br />
context, <strong>the</strong>expression \<strong>the</strong>sameinterms<strong>of</strong>behavior" means that methods with<strong>the</strong><br />
samebehavior as those speci ed are applicable, <strong>and</strong>in<strong>the</strong>sameorder.<br />
<br />
oportabl e cl ass p may inheri t, byvirtue<strong>of</strong>bei ng adirect or indi rect subcl ass <strong>of</strong> a<br />
speci ed cl ass, any sl ot f or which<strong>the</strong>name isasymbol accessi ble in<strong>the</strong> common-lispuser<br />
package or exported byanypackage dened i n <strong>the</strong> ASI Common Lisp st<strong>and</strong>ard.<br />
Implementations are free to dene implementation-speci c before- <strong>and</strong> after-methods<br />
on speci ed generi c functi ons. Implementations are also free to dene implementationspeci<br />
c around-methods wi<strong>the</strong>xtendingbehavior.<br />
estrictions on ortable rograms<br />
Portableprograms are allowed to dene subclasses<strong>of</strong>speci ed classes, <strong>and</strong>arepermittedto<br />
dene methods onspeci ed generi c functi ons, with<strong>the</strong> following restrictions. <strong>The</strong> results<br />
are undened i f any<strong>of</strong> <strong>the</strong>se restrictionsisviolated.<br />
Portableprograms must not redene anyspeci ed classes, generi c functi ons, methods or<br />
method combinati ons. Anymethod dened byaportable programon a speci ed generi c<br />
functi on must have atleastonespeci al i zer that i s nei <strong>the</strong>r a speci ed cl ass nor an eql<br />
speci al i zer whose associ ated val ue isaninstance <strong>of</strong> a speci ed cl ass.<br />
Portableprograms may dene methods that extendspeci ed methods unless <strong>the</strong>descri p-<br />
ti on <strong>of</strong> <strong>the</strong> speci ed method explicitlyprohibits this. Unless <strong>the</strong>re i s a speci c statement<br />
to <strong>the</strong>contrary, <strong>the</strong>se extendingmethods must return whatever val ue was returned by<br />
<strong>the</strong> cal l to call-ne t-method.<br />
Portable programs may dene methods that overridespeci ed methods onlywhen <strong>the</strong><br />
descri pti on <strong>of</strong> <strong>the</strong> speci ed method explicitlyallows this. Typically, when a method i s<br />
allowed to be overridden, asmal l number <strong>of</strong> related methods will need to be overridden<br />
as well.<br />
An example <strong>of</strong> this is <strong>the</strong>speci ed methods on<strong>the</strong>generi c functi ons add-dependent,<br />
remove- dependent <strong>and</strong> map-dependents. Overridingaspeci ed method on one <strong>of</strong><br />
<strong>the</strong>se generi c functi ons requires that <strong>the</strong> correspondingmethod on <strong>the</strong> o<strong>the</strong>r twogeneri c<br />
functi ons beoverridden as well.<br />
Portablemethods onspeci ed generi c functi onsspeci al i zedto portablemetaobj ect cl asses<br />
must bedened bef ore any instances <strong>of</strong> those cl asses (or anysubclasses) are created, ei<strong>the</strong>r<br />
directly or indirectly byacall toma e- i nstance. Methods can be dened af ter
PROCES S N O THE SER NTER ACE ACROS 11<br />
instances are created by allocate-instance however. Portable metaobj ect cl asses cannot<br />
be redened.<br />
mplementation ote:<br />
<strong>The</strong> purpose <strong>of</strong> this last restriction is to permit implementations toprovideperformance<br />
optimi zati ons byanal yzi ng, at <strong>the</strong> time<strong>the</strong>rst instance <strong>of</strong> a metaobj ect cl ass<br />
is initialized,what portablemethods will beapplicabletoit. This canmake itpossible<br />
to optimize calls tothose speci ed generi c functi ons whichwouldhave noapplicable<br />
portable methods.<br />
ote:<br />
<strong>The</strong> speci cati on technol ogy used in this document needs fur<strong>the</strong>r devel opment. <strong>The</strong><br />
concepts <strong>of</strong> obj ect- ori ented protocols <strong>and</strong>subcl ass specialization are intuitivel y familiar<br />
to programmers <strong>of</strong> object-ori ented systems; <strong>the</strong> protocols presented here t<br />
quite naturally into this framework. one<strong>the</strong>l ess, i n prepari ng this document, we<br />
have found it di cul t to gi ve speci cati on-qualitydescri ptions <strong>of</strong> <strong>the</strong>protocols in a<br />
way that makes i t cl ear what extensionsusers can <strong>and</strong>cannot write. Object-ori ented<br />
protocol speci cation is inherently about speci fying l eeway, <strong>and</strong>thi s seems di cult<br />
usingcurrent technol ogy.<br />
rocessi n o t e ser Inter ace acros<br />
Alist inwhich<strong>the</strong>rst el ement isone<strong>of</strong><strong>the</strong>symbol s def cl ass, def method, def generi c,<br />
dene- method-combination, generic-functi on, generi c- et or generi c- l abel s, <strong>and</strong><br />
whichhas proper syntaxfor that macrois calledauser inter ace macro orm. Thisdocument<br />
provides an extended speci cati on <strong>of</strong> <strong>the</strong> def cl ass, def method <strong>and</strong> def generi c macros.<br />
<strong>The</strong> user interface macros def cl ass, def generi c <strong>and</strong> def methodcanbeusednot onlyto<br />
dene metaobj ects that are i nstances <strong>of</strong> <strong>the</strong> corresponding st<strong>and</strong>ard metaobj ect cl ass, but<br />
also to dene metaobj ects that are i nstances <strong>of</strong> appropriate portable metaobj ect cl asses.<br />
To make itpossible for portable metaobj ect cl asses to properl y process <strong>the</strong> information<br />
appeari ngin<strong>the</strong>macr<strong>of</strong>orm,this documentprovidesalimitedspeci cati on <strong>of</strong> <strong>the</strong> processing<br />
<strong>of</strong> <strong>the</strong>se macro forms.<br />
User interface macro forms can be e al uat ed or com iled <strong>and</strong> later e ecuted. <strong>The</strong> eect<br />
<strong>of</strong> eval uati ng or executing a user interface macro formis speci ed in terms <strong>of</strong> calls to<br />
speci ed functi ons <strong>and</strong>generi c functi ons whichprovide<strong>the</strong>actual behavior <strong>of</strong> <strong>the</strong>macro.<br />
<strong>The</strong> arguments recei ved by<strong>the</strong>se functi ons <strong>and</strong>generi c functi ons arederi ved i n a speci ed<br />
way from<strong>the</strong>macro form.<br />
Convertingauser interface macro forminto <strong>the</strong>arguments to <strong>the</strong>appropri ate f uncti ons<br />
<strong>and</strong> generi c functi ons has two maj or aspects: <strong>the</strong>conversion<strong>of</strong> <strong>the</strong>macro argument syntax<br />
into a f ormmore suitabl e f or l ater processing, <strong>and</strong><strong>the</strong>processing<strong>of</strong> macro arguments which<br />
are f orms tobeeval uated (i ncl udingmethod bodies).
12 CHAPTER 5 . CONCEPTS<br />
In <strong>the</strong>syntax <strong>of</strong> <strong>the</strong> def cl ass macro, <strong>the</strong> init orm<strong>and</strong> de aul t-initarg-initial- al ue- orm<br />
arguments are f orms which will be eval uated one or more ti mes af ter <strong>the</strong> macro formis<br />
eval uated or executed. Speci al processingmust bedone on<strong>the</strong>se arguments to ensure that<br />
<strong>the</strong>lexi cal scope <strong>of</strong><strong>the</strong> f orms iscaptured properl y. This is done bybuildingafuncti on <strong>of</strong><br />
zero arguments which, when cal l ed, returns<strong>the</strong>result <strong>of</strong> eval uati ng <strong>the</strong> f ormin<strong>the</strong>proper<br />
lexical environment.<br />
In <strong>the</strong> syntax <strong>of</strong> <strong>the</strong> def method macro <strong>the</strong> orm argument is a list <strong>of</strong> forms that<br />
comprise <strong>the</strong>body <strong>of</strong> <strong>the</strong>method denition. This list <strong>of</strong> formsmust beprocessed speci al l y<br />
to capture <strong>the</strong>lexi cal scope <strong>of</strong><strong>the</strong>macro form. In addition, <strong>the</strong>lexical functi ons avai l able<br />
only in <strong>the</strong> body <strong>of</strong> methods must be introduced. To allowthis <strong>and</strong>anyo<strong>the</strong>r speci al<br />
processing (such as sl ot access optimization), a speci al i zable protocol is used f or processing<br />
<strong>the</strong>body <strong>of</strong> methods. This is discussed in <strong>the</strong> secti on \ProcessingMethod Bodies."<br />
o ile le rocessi n o t e ser nter ace acros<br />
It is common practi ce f or Common Lispcompilers, while processingale or set <strong>of</strong> les, to<br />
mai ntain informati on about <strong>the</strong>denitionsthat have been compiledso far. Among o<strong>the</strong>r<br />
things, this makes i t possible to ensure that a gl obal macro denition (def macro form)<br />
whichappears inale will aect uses <strong>of</strong> <strong>the</strong>macrolater inthat le. This informati onabout<br />
<strong>the</strong> state <strong>of</strong> <strong>the</strong>compilationis called<strong>the</strong> com ile- le en ironment .<br />
When compilingles containingCLOS denitions, it is useful to mai ntain certain additional<br />
i nformati on i n <strong>the</strong> compile-le environment. This can make itpossible to issue<br />
vari ous kinds <strong>of</strong> warnings (e.g., lambda list congruence) <strong>and</strong> todovari ous performance<br />
optimi zati ons that wouldnot o<strong>the</strong>rwise bepossible.<br />
At this time, <strong>the</strong>re i s such si gnicant vari ance i n <strong>the</strong> way existingCommon Lisp implementations<br />
h<strong>and</strong>le compile-le environments that i t wouldbepremature to speci fy this<br />
mechanism. Consequently, this document speci es only<strong>the</strong>behavior <strong>of</strong> eval uati ng or executinguser<br />
interface macro forms. What f uncti ons <strong>and</strong>generi c functi ons are calledduring<br />
compile-le processing<strong>of</strong> auser interface macro formis not speci ed. Implementations are<br />
free to dene <strong>and</strong>document <strong>the</strong>i r ownbehavior. Users may need to check i mplementationspeci<br />
c behavior before attemptingtocompile certainportable programs.<br />
e e class acro<br />
<strong>The</strong> eval uati on or executi on <strong>of</strong> a def cl ass formresults inacall to<strong>the</strong> ensure-cl ass functi on.<br />
<strong>The</strong> arguments recei ved by ensure-cl ass are deri ved from<strong>the</strong> def cl ass formina dened<br />
way. <strong>The</strong> exact macro- expansi on <strong>of</strong> <strong>the</strong> def cl ass formis not dened, only<strong>the</strong> rel ati onship<br />
between <strong>the</strong> arguments to <strong>the</strong> def cl ass macro <strong>and</strong> <strong>the</strong>arguments recei ved by<strong>the</strong> ensurecl<br />
ass functi on. Examples <strong>of</strong> typical def cl ass forms<strong>and</strong>sample expansions are shown in<br />
Figures 5.1 <strong>and</strong>5.2.
PROCES S N O THE SER NTER ACE ACROS 13<br />
e class pla e mo i o ec rap ics o ec<br />
al i e i i orm accessor pla e al i e<br />
spee<br />
e a l i i ar s e i e e<br />
e s re class pla e<br />
irec s perclasses mo i o ec rap ics o ec<br />
irec slo s lis lis ame al i e<br />
i i orm<br />
i i c io lam a<br />
rea ers pla e al i e<br />
ri ers se pla e al i e<br />
lis ame spee<br />
irec e a l i i ar s lis lis e i e<br />
e<br />
lam a e<br />
e .1 e a r r<br />
r r r e e- a .<br />
<strong>The</strong> name argument todef cl ass becomes <strong>the</strong> val ue <strong>of</strong> <strong>the</strong>rst argument to ensurecl<br />
ass. This is <strong>the</strong>onlypositional argument accepted by ensure-cl ass; al l o<strong>the</strong>r arguments<br />
are keyword arguments.<br />
<strong>The</strong> di rect -su ercl asses argument todef cl ass becomes <strong>the</strong> val ue <strong>of</strong> <strong>the</strong> :direct-supercl<br />
asses keyword argument toensure-cl ass.<br />
<strong>The</strong> di rect sl ot s argument todef cl ass becomes <strong>the</strong> val ue <strong>of</strong><strong>the</strong> :direct-slots keyword<br />
argumenttoensure-cl ass. Speci al processing<strong>of</strong> this val ue isdone toregularize <strong>the</strong> f orm<br />
<strong>of</strong> each sl ot speci cati on <strong>and</strong> toproperl y capture <strong>the</strong>lexi cal scope <strong>of</strong><strong>the</strong>initialization<br />
forms. This is done byconvertingeachslot speci cation to a property list called a<br />
canoni cal i ed sl ot s eci cat i on. <strong>The</strong> resulting list <strong>of</strong> canonicalizedslot speci cati ons is<br />
<strong>the</strong>val ue <strong>of</strong> <strong>the</strong> :direct-slots keyword argument.<br />
Canonicalizedslot speci cati ons are later used as <strong>the</strong>keyword arguments to a generi c<br />
functi onwhichwill, inturn,pass <strong>the</strong>mto ma e- i nstance for use as a set <strong>of</strong> i nitialization<br />
arguments. Each canonicalizedslot speci cation is formed from<strong>the</strong> correspondingslot<br />
speci cati on as f ol l ows:<br />
<strong>The</strong> name <strong>of</strong><strong>the</strong>slotis<strong>the</strong>val ue <strong>of</strong> <strong>the</strong> :name property. This property appears i n<br />
every canonicalizedslot speci cati on.
14 CHAPTER 5 . CONCEPTS<br />
e class ss pla e<br />
mac ma s ep<br />
loca or ss mac<br />
loca or mac loca io<br />
rea er mac spee<br />
rea er mac<br />
me aclass as er class<br />
a o er op io oo ar<br />
e s re class ss<br />
irec s perclasses pla e<br />
irec slo s lis lis ame mac<br />
rea ers mac spee mac<br />
ma s ep<br />
loca or ss mac mac loca io<br />
me aclass as er class<br />
a o er op io oo ar<br />
e . e a r r<br />
r r r e e- a . r r<br />
r r r r r r<br />
r r r .
PROCES S N O THE SER NTER ACE ACROS 15<br />
When <strong>the</strong> :initformsl ot opti on i s present in <strong>the</strong>slotspeci cati on, <strong>the</strong>n both <strong>the</strong><br />
:initform<strong>and</strong> :initfuncti on properties are presentin<strong>the</strong>canonicalizedslot speci -<br />
cati on. <strong>The</strong> val ue <strong>of</strong><strong>the</strong> :initformproperty is <strong>the</strong>initializationform. <strong>The</strong> val ue<br />
<strong>of</strong> <strong>the</strong> :initfuncti on property is a functi on <strong>of</strong> zero arguments which, when cal l ed,<br />
returns <strong>the</strong>result <strong>of</strong> eval uati ng <strong>the</strong>initialization f orminits proper l exical environment.<br />
If <strong>the</strong> :initformsl ot opti on i s not present in <strong>the</strong>slotspeci cati on, <strong>the</strong>n ei <strong>the</strong>r<br />
<strong>the</strong> :initfuncti on property will not appear, or i ts val ue will be f al se. I n such cases,<br />
<strong>the</strong>val ue <strong>of</strong> <strong>the</strong> :initformproperty,orwhe<strong>the</strong>r i t appears, is unspeci ed.<br />
<strong>The</strong> val ue <strong>of</strong> <strong>the</strong> :initargs property is a list <strong>of</strong> <strong>the</strong> val ues <strong>of</strong> each :initarg slot<br />
option. If <strong>the</strong>re are no :initarg sl ot options, <strong>the</strong>n ei <strong>the</strong>r <strong>the</strong> :initargs property will<br />
not appear or i ts val ue will be<strong>the</strong>empty list.<br />
<strong>The</strong> val ue <strong>of</strong> <strong>the</strong> :readers propertyis a list <strong>of</strong> <strong>the</strong>val ues <strong>of</strong> each :reader <strong>and</strong> :accessor<br />
sl ot option. If <strong>the</strong>re are no :reader or :accessor sl ot options, <strong>the</strong>n ei <strong>the</strong>r <strong>the</strong><br />
:readers property will not appear or i ts val ue will be<strong>the</strong>empty list.<br />
<strong>The</strong> val ue <strong>of</strong> <strong>the</strong> :wri ters propertyis a list <strong>of</strong> <strong>the</strong>val ues speci ed by each :wri ter<br />
<strong>and</strong> :accessor sl ot option. <strong>The</strong> val ue speci ed bya:wri ter sl ot option is just <strong>the</strong><br />
val ue <strong>of</strong> <strong>the</strong>slotoption. <strong>The</strong> val ue speci ed byan:accessor sl ot opti on i s a two<br />
el ement list: <strong>the</strong>rst el ement is<strong>the</strong>symbol setf, <strong>the</strong> secondelement is<strong>the</strong>val ue <strong>of</strong><br />
<strong>the</strong>slotoption. If <strong>the</strong>re are no :wri ter or :accessor sl ot options, <strong>the</strong>n ei <strong>the</strong>r <strong>the</strong><br />
:wri ters property will not appearoritsval ue will be<strong>the</strong>emptylist.<br />
<strong>The</strong> val ue <strong>of</strong> <strong>the</strong> :documentati onpropertyis <strong>the</strong>val ue <strong>of</strong><strong>the</strong> :documentationslot<br />
option. If <strong>the</strong>re i s no :documentationsl ot option,<strong>the</strong>n ei <strong>the</strong>r <strong>the</strong> :documentati on<br />
property will not appear or i ts val ue will be f al se.<br />
Al l o<strong>the</strong>r sl ot optionsappear as <strong>the</strong> val ues <strong>of</strong> properties with<strong>the</strong>samename as<strong>the</strong><br />
sl ot option. ote that this incl udes not only <strong>the</strong>remai ning st<strong>and</strong>ard sl ot options<br />
(:allocation<strong>and</strong> :type), but alsoanyo<strong>the</strong>r options<strong>and</strong>val ues appeari ngin<strong>the</strong>slot<br />
speci cati on. If one<strong>of</strong><strong>the</strong>se sl ot optionsappears more than once, <strong>the</strong> val ue <strong>of</strong> <strong>the</strong><br />
property will be alist <strong>of</strong> <strong>the</strong>speci ed val ues.<br />
An implementation is free to addadditional properties to <strong>the</strong> canonicalized slot<br />
speci cati on provided <strong>the</strong>se are not symbols accessi ble in <strong>the</strong> common-lisp-user<br />
package, or exported byanypackage dened i n <strong>the</strong> ASI Common Lisp st<strong>and</strong>ard.<br />
Returningto<strong>the</strong> correspondence between arguments to <strong>the</strong> def cl ass macro <strong>and</strong> <strong>the</strong><br />
arguments recei ved by<strong>the</strong> ensure-class functi on:<br />
<strong>The</strong> de aul t ini t args cl ass option,ifitispresentin<strong>the</strong> def cl ass form,becomes <strong>the</strong> val ue<br />
<strong>of</strong> <strong>the</strong> :di rect- def ault-initargs keyword argumenttoensure-class. Speci al processing<br />
<strong>of</strong> this val ue isdone toproperl y capture <strong>the</strong>lexi cal scope <strong>of</strong><strong>the</strong>default val ue f orms. This<br />
is done byconvertingeachdefault initargin<strong>the</strong>classoptioninto a canoni cal i ed de aul t<br />
ini t arg. <strong>The</strong> resulting list <strong>of</strong> canonicalizeddefault ini targs i s <strong>the</strong> val ue <strong>of</strong> <strong>the</strong> :directdef<br />
ault-initargs keyword argument toensure-cl ass.
16 CHAPTER 5 . CONCEPTS<br />
Acanonicalizeddefault initargis alist <strong>of</strong> three elements. <strong>The</strong> rst el ement is<strong>the</strong>name;<br />
<strong>the</strong> secondis <strong>the</strong>actual f ormitself; <strong>and</strong><strong>the</strong>thirdis afuncti on <strong>of</strong> zero arguments which,<br />
when cal l ed, returns<strong>the</strong>result <strong>of</strong> eval uati ng <strong>the</strong>default val ue f orminits proper l exical<br />
environment.<br />
<strong>The</strong> met acl ass cl ass option, if it is presentin<strong>the</strong> def cl ass form, becomes <strong>the</strong> val ue <strong>of</strong><br />
<strong>the</strong> :metacl ass keyword argument toensure-cl ass.<br />
<strong>The</strong> documentation cl ass option,ifitispresentin<strong>the</strong> def cl ass form,becomes <strong>the</strong> val ue<br />
<strong>of</strong> <strong>the</strong> :documentation keyword argument toensure-class.<br />
Any o<strong>the</strong>r cl ass optionsbecome <strong>the</strong>val ue <strong>of</strong> keyword arguments with<strong>the</strong>samename.<br />
<strong>The</strong> val ue <strong>of</strong> <strong>the</strong>keyword argument is<strong>the</strong> tai l <strong>of</strong> <strong>the</strong> classoption. An error is signal ed<br />
if anyclass opti on appears more than once i n <strong>the</strong> def cl ass form.<br />
In <strong>the</strong> cal l to ensure-cl ass, every el ement <strong>of</strong> i ts arguments appears in <strong>the</strong>sameleftto-rightorder<br />
as <strong>the</strong> correspondingelement <strong>of</strong><strong>the</strong> def cl ass form,except that <strong>the</strong> order <strong>of</strong><br />
<strong>the</strong>properti es <strong>of</strong> canonicalized slot speci cati ons is unspeci ed. <strong>The</strong> val ues <strong>of</strong> properties<br />
in canonicalized slot speci cati ons do followthi s orderi ng requirement. O<strong>the</strong>r orderi ng<br />
relationshipsin<strong>the</strong>keyword arguments to ensure-cl ass are unspeci ed.<br />
<strong>The</strong> result <strong>of</strong> <strong>the</strong> cal l to ensure-cl ass is returned as <strong>the</strong>result <strong>of</strong> eval uati ngor executing<br />
<strong>the</strong> def cl ass form.<br />
e e et o acro<br />
<strong>The</strong> eval uati on or executi on <strong>of</strong> a def methodformrequires rst that <strong>the</strong> body<strong>of</strong> <strong>the</strong>method<br />
be convertedto a method f uncti on. This process i s descri bedin<strong>the</strong>next secti on. <strong>The</strong> result<br />
<strong>of</strong> this process i s a method f uncti on <strong>and</strong>aset <strong>of</strong> additional i nitializationarguments to be<br />
used when creati ng<strong>the</strong>newmethod. Given <strong>the</strong>se twoval ues, <strong>the</strong> eval uati on or executi on <strong>of</strong><br />
a def method formproceeds inthree steps.<br />
<strong>The</strong> rst step ensures <strong>the</strong>existence <strong>of</strong> a generi c functi on with<strong>the</strong>speci ed name. This<br />
is done bycalling<strong>the</strong>functi on ensure-generic-functi on. <strong>The</strong> rst argument inthis call<br />
is <strong>the</strong>generi c functi on name speci ed i n <strong>the</strong> def method form.<br />
<strong>The</strong> secondstepis <strong>the</strong> creati on <strong>of</strong> <strong>the</strong> newmethodmetaobj ect bycalling ma e- i nstance.<br />
<strong>The</strong> class <strong>of</strong> <strong>the</strong> new method metaobj ect i s determined by calling generi c- f uncti onmethod-class<br />
on <strong>the</strong> result <strong>of</strong> <strong>the</strong> cal l to ensure-generi c- f uncti on from<strong>the</strong>rst step.<br />
<strong>The</strong> initializationarguments recei ved by<strong>the</strong> cal l to ma e- i nstance are as f ol l ows:<br />
<strong>The</strong> val ue <strong>of</strong> <strong>the</strong> :qualiers initialization argument is a list <strong>of</strong> <strong>the</strong> qualiers which<br />
appeared i n <strong>the</strong> def method form. ospeci al processingisdone on<strong>the</strong>se val ues. <strong>The</strong><br />
order <strong>of</strong> <strong>the</strong> elements <strong>of</strong> this list is <strong>the</strong>sameasin<strong>the</strong> def method form.<br />
<strong>The</strong> val ue <strong>of</strong> <strong>the</strong> :lambda-list initializationargument is<strong>the</strong>unspeci al i zed l ambdalist<br />
from<strong>the</strong> def method form.
PROCES S N O THE SER NTER ACE ACROS 17<br />
<strong>The</strong> val ue <strong>of</strong><strong>the</strong> :speci alizers initializationargument is a list <strong>of</strong> <strong>the</strong> speci al i zers for<br />
<strong>the</strong>method. For speci al i zers which are classes, <strong>the</strong>speci al i zer i s <strong>the</strong> classmetaobj ect<br />
itself. In <strong>the</strong> case <strong>of</strong> eql speci al i zers, i t will beaneql-speci alizer metaobj ect obtained<br />
bycalling intern-eql-speci alizer on <strong>the</strong> result <strong>of</strong> eval uati ng <strong>the</strong> eql speci al i zer formin<br />
<strong>the</strong>lexical environment <strong>of</strong><strong>the</strong> def method form.<br />
<strong>The</strong> val ue <strong>of</strong><strong>the</strong> :functi on initializationargument is<strong>the</strong>method f uncti on.<br />
<strong>The</strong> val ue <strong>of</strong><strong>the</strong> :decl arations initializationargument isalist<strong>of</strong><strong>the</strong>decl arati ons from<br />
<strong>the</strong> def method form. If <strong>the</strong>re are nodecl arati ons in<strong>the</strong>macro form,this initialization<br />
argument ei<strong>the</strong>r doesn't appear, or appears withaval ue <strong>of</strong> <strong>the</strong>empty list.<br />
<strong>The</strong> val ue <strong>of</strong><strong>the</strong> :documentation initializationargument is<strong>the</strong>documentation string<br />
from<strong>the</strong> def method form. If <strong>the</strong>re i s nodocumentationstringin<strong>the</strong>macro formthis<br />
initializationargument ei<strong>the</strong>r doesn't appear, or appears withaval ue <strong>of</strong> f al se.<br />
Anyo<strong>the</strong>r i nitializationargumentproduced i n conjuncti on with<strong>the</strong>methodfunctionare<br />
al so i ncl uded.<br />
<strong>The</strong> implementationis free to incl ude additional i nitializationarguments provided <strong>the</strong>se<br />
are not symbol s accessi ble in<strong>the</strong> common-lisp-user package, or exported byanypackage<br />
dened i n <strong>the</strong> ASI Common Lisp st<strong>and</strong>ard.<br />
In <strong>the</strong>third step, add-method is calledtoadd<strong>the</strong>newl y created method to <strong>the</strong>set<strong>of</strong><br />
methods associ ated with<strong>the</strong>generi c functi on metaobj ect.<br />
<strong>The</strong> result <strong>of</strong> <strong>the</strong> cal l to add-methodis returned as <strong>the</strong>result <strong>of</strong> eval uati ngor executing<br />
<strong>the</strong> def method form.<br />
An example showingatypical def method form<strong>and</strong>asample expansion is shown in<br />
Figure 5. 3. <strong>The</strong> processing<strong>of</strong> <strong>the</strong>method body for this method i s shown inFigure 5. 4.<br />
rocessi n et o o ies<br />
Bef ore a method can be created, <strong>the</strong> list <strong>of</strong> formscomprising<strong>the</strong> method body must be<br />
converted to a method f uncti on. This conversionis a two step process.<br />
ote:<br />
<strong>The</strong> body <strong>of</strong> methods can al so appear i n <strong>the</strong> :initial-methods opti on <strong>of</strong> def generi c<br />
forms. Initial methods arenot considered byany<strong>of</strong> <strong>the</strong>protocols speci ed i n this document.<br />
<strong>The</strong> rst step occurs duringmacro- expansi on <strong>of</strong> <strong>the</strong> macro form. In this step, <strong>the</strong><br />
method l ambda list, decl arati ons <strong>and</strong>body areconverted to a lambda expression called a<br />
met hod lambda. This conversionis based on i nformati on associ ated with<strong>the</strong>generi c functi on<br />
denitionineect at <strong>the</strong> time<strong>the</strong>macro formis exp<strong>and</strong>ed.
18 CHAPTER 5 . CONCEPTS<br />
e me o mo e e ore p posi io l e l<br />
op io al isi l p<br />
e color<br />
se o ori i p<br />
e isi l p s o mo e p color<br />
le e s re e eric c io mo e<br />
a me o<br />
ma e i s a ce e eric c io me o class<br />
ali iers e ore<br />
speciali ers lis i class posi io<br />
i er e l speciali er<br />
lam a lis p l op io al isi l p<br />
e color<br />
c io c io met hod- l ambda<br />
a i io al i i ar<br />
a i io al i i ar<br />
e . e e r rr .<br />
r a e- e - a a r r<br />
. r r r r r<br />
r r r a e- e - a a.<br />
le e s re e eric c io mo e<br />
ma e me o lam a<br />
class pro o pe e eric c io me o class<br />
lam a p l op io al isi l p e color<br />
se o ori i p<br />
e isi l p s o mo e p color<br />
en ironment<br />
e . r r e e r r . r<br />
r r r .<br />
r r e e r r .
PROCES S N O THE SER NTER ACE ACROS 19<br />
<strong>The</strong> generi c functi on denitionis obtained bycalling ensure-generi c- f uncti on witha<br />
rst argument <strong>of</strong><strong>the</strong>generi c functi on name speci ed i n <strong>the</strong> macro form. <strong>The</strong> :lambda-list<br />
keyword argument isnot passed in this call.<br />
Given<strong>the</strong>generi c functi on, production<strong>of</strong> <strong>the</strong>method l ambdaproceeds bycalling ma e-<br />
method-lambda. <strong>The</strong> rst argument inthis call is <strong>the</strong>generi c functi on obtained as described<br />
above. <strong>The</strong> secondargument is<strong>the</strong>result <strong>of</strong> calling cl ass-prototype on <strong>the</strong> result<br />
<strong>of</strong> calling generic-functi on-method-class on <strong>the</strong> generi c functi on. <strong>The</strong> thirdargument<br />
is a lambda expression formed from<strong>the</strong>method l ambda list, decl arati ons <strong>and</strong>body. <strong>The</strong><br />
fourth argument is<strong>the</strong>macro- expansionenvironment <strong>of</strong><strong>the</strong>macro form;this is <strong>the</strong>val ue <strong>of</strong><br />
<strong>the</strong> environment argument to<strong>the</strong> def method macro.<br />
<strong>The</strong> generi c functi on ma e- method-lambda returns twoval ues. <strong>The</strong> rst is <strong>the</strong><br />
method l ambda itself. <strong>The</strong> secondis alist <strong>of</strong> initializationarguments <strong>and</strong>val ues. <strong>The</strong>se are<br />
incl uded i n <strong>the</strong> initializationarguments when <strong>the</strong> method i s created.<br />
In<strong>the</strong> secondstep,<strong>the</strong>method l ambdais convertedtoafuncti onwhichproperlycaptures<br />
<strong>the</strong>lexi cal scope <strong>of</strong><strong>the</strong>macro form. This is done byhaving<strong>the</strong>method l ambda appear i n<br />
<strong>the</strong>macro- expansi on as <strong>the</strong> argument <strong>of</strong><strong>the</strong> functi onspeci al form. During<strong>the</strong>subsequent<br />
eval uati on <strong>of</strong> <strong>the</strong> macro- expansion, <strong>the</strong>result <strong>of</strong> <strong>the</strong> functi on speci al formis <strong>the</strong>method<br />
functi on.<br />
e e eneric acro<br />
<strong>The</strong> eval uationor executi on <strong>of</strong> a def generi c formresults inacall to<strong>the</strong> ensure-generi c-<br />
functi onfuncti on. <strong>The</strong> arguments recei ved by ensure-generi c- f uncti onare deri ved from<br />
<strong>the</strong> def generi c forminadened way. Aswithdef cl ass <strong>and</strong> def method, <strong>the</strong>exact macroexpansi<br />
on <strong>of</strong> <strong>the</strong> def generi c formis not dened, only <strong>the</strong> rel ati onshipbetween <strong>the</strong> arguments<br />
to <strong>the</strong>macro <strong>and</strong> <strong>the</strong>arguments recei ved by ensure-generic-functi on.<br />
<strong>The</strong> unct i on-name argument to def generi c becomes <strong>the</strong> rst argument to ensuregeneri<br />
c- f uncti on. This is <strong>the</strong>onlypositional argument accepted by ensure-generi c-<br />
functi on; al l o<strong>the</strong>r arguments are keyword arguments.<br />
<strong>The</strong> lambda- l i st argumenttodef generi c becomes <strong>the</strong>val ue <strong>of</strong><strong>the</strong> :lambda-listkeyword<br />
argument toensure-generi c- f uncti on.<br />
For each <strong>of</strong> <strong>the</strong> options :argument-precedence-order, :documentati on, :generi c-<br />
functi on-class <strong>and</strong> :method-class, <strong>the</strong>val ue <strong>of</strong><strong>the</strong>opti on becomes <strong>the</strong> val ue <strong>of</strong><strong>the</strong><br />
keyword argument with <strong>the</strong> samename. If <strong>the</strong>opti on does not appear i n <strong>the</strong> macro<br />
form, <strong>the</strong>keyword argument does not appear i n <strong>the</strong> resulting cal l to ensure-generi c-<br />
functi on.<br />
For <strong>the</strong> option decl are, <strong>the</strong> list <strong>of</strong> decl arati ons becomes <strong>the</strong> val ue <strong>of</strong> <strong>the</strong> :decl arations<br />
keyword argument. If <strong>the</strong> decl are opti on does not appear i n <strong>the</strong> macro form,<strong>the</strong> :declarations<br />
keyword argument does not appear i n <strong>the</strong> cal l to ensure-generi c- f uncti on.
20 CHAPTER 5 . CONCEPTS<br />
<strong>The</strong> h<strong>and</strong>ling<strong>of</strong> <strong>the</strong> :method-combination opti on i s not speci ed.<br />
<strong>The</strong> result <strong>of</strong> <strong>the</strong> cal l to ensure-generic-functi onis returned as <strong>the</strong>result <strong>of</strong> eval uati ng<br />
or executing<strong>the</strong> def generi c form.<br />
ub rotocols<br />
This sectionprovides an overview<strong>of</strong> <strong>the</strong> Metaobj ect <strong>Protocol</strong>s. <strong>The</strong> detailedbehavi or <strong>of</strong> each<br />
functi on, generi c functi on <strong>and</strong>macro in <strong>the</strong>Metaobj ect <strong>Protocol</strong> is presented in Chapter 6.<br />
<strong>The</strong> remai nder <strong>of</strong> this chapter is intended to emphasi ze connecti ons among <strong>the</strong> parts <strong>of</strong><br />
<strong>the</strong>Metaobj ect <strong>Protocol</strong>, <strong>and</strong>toprovidesomeexamples <strong>of</strong> <strong>the</strong>kinds <strong>of</strong>specializations<strong>and</strong><br />
extensions<strong>the</strong>protocols are desi gned to support.<br />
etao ect nitializati on rotocols<br />
Likeo<strong>the</strong>r objects, metaobj ects can be created bycalling ma e- i nstance. <strong>The</strong> initialization<br />
arguments passed to ma e- i nstance are used to initialize<strong>the</strong>metaobj ect i n <strong>the</strong> usual way.<br />
<strong>The</strong> set <strong>of</strong> l egal i nitializationarguments, <strong>and</strong><strong>the</strong>i r i nterpretation, depends on <strong>the</strong>kind<strong>of</strong><br />
metaobj ect bei ngcreated. Implementations<strong>and</strong>portableprograms are free toextend<strong>the</strong>set<br />
<strong>of</strong> l egal i nitializationarguments. Detailedinformati onabout <strong>the</strong>initialization<strong>of</strong> eachkind<br />
<strong>of</strong> metaobj ect are provided i n Chapter 6; this sectionprovides an overview<strong>and</strong>examples <strong>of</strong><br />
this behavior.<br />
nitialization<strong>of</strong> Class <strong>Metaobject</strong>s<br />
Class metaobj ects created withma e- i nstance are usuallyanon mous; that i s, <strong>the</strong>y have<br />
no proper name. Ananonymous classmetaobj ect can be given a proper name using (setf<br />
nd-class) <strong>and</strong> (setf class-name).<br />
When a cl ass metaobj ect i s created withma e- i nstance, itisinitializedin<strong>the</strong>usual<br />
way. <strong>The</strong> initializationarguments passed to ma e- i nstance are use to establish<strong>the</strong>denition<strong>of</strong><br />
<strong>the</strong> class. Each i nitializationargument ischecked for errors <strong>and</strong> associ ated with<br />
<strong>the</strong>classmetaobj ect. <strong>The</strong> initializationarguments correspond roughlyto <strong>the</strong>arguments accepted<br />
by<strong>the</strong> def cl ass macro, <strong>and</strong> more closely to <strong>the</strong>arguments accepted by<strong>the</strong> ensurecl<br />
ass functi on.<br />
Some classmetaobj ect cl asses al l ow<strong>the</strong>i r i nstances to be redened. When permissible,<br />
this is done bycalling rei nitialize-instance. This is discussed in <strong>the</strong>next secti on.<br />
An exampl e <strong>of</strong> creati ngananonymous classdirectlyusing ma e- i nstance follows:<br />
le ero<br />
propellor propellor<br />
ma e i s a ce s a ar class<br />
ame m class oo
S PROTOCO S 21<br />
irec s perclasses lis i class pla e<br />
anot her- anon mous- cl ass<br />
irec slo s ame x<br />
i i orm<br />
i i c io ero<br />
i i ar s x<br />
rea ers posi io x<br />
ri ers se posi io x<br />
ame<br />
i i orm<br />
i i c io ero<br />
i i ar s<br />
rea ers posi io<br />
ri ers se posi io<br />
irec e a l i i ar s e i e propellor propellor<br />
ei nitialization<strong>of</strong> Class <strong>Metaobject</strong>s<br />
Some classmetaobj ect cl asses al l ow <strong>the</strong>i r i nstances to be reinitialized. This is done by<br />
calling rei nitialize-instance. <strong>The</strong> initializationarguments have <strong>the</strong>sameinterpretation<br />
as i n cl ass i nitialization.<br />
If <strong>the</strong>classmetaobj ect was nal i zed bef ore <strong>the</strong> cal l to rei nitialize-instance, nalizeinheri<br />
tance will be cal l ed agai n once al l <strong>the</strong> initializationarguments have been processed<br />
<strong>and</strong> associ ated with <strong>the</strong>classmetaobj ect. In addition, once nalizationis complete, any<br />
dependents <strong>of</strong> <strong>the</strong>classmetaobj ect will beupdated bycalling update-dependent.<br />
nitialization<strong>of</strong> Generi c Functi on<strong>and</strong>Method<strong>Metaobject</strong>s<br />
An exampl e <strong>of</strong> creati ng a generi c functi on <strong>and</strong>amethod metaobj ect, <strong>and</strong> <strong>the</strong>n adding<strong>the</strong><br />
methodto <strong>the</strong>generi c functi on i s shownbel ow. This example is comparable to <strong>the</strong>method<br />
denitionshown inFigure 5. 3.<br />
le ma e i s a ce s a ar e eric c io<br />
lam a lis p l op io al isi l p e<br />
me o class e eric c io me o class<br />
m l iple al e i lam a i i ar s<br />
ma e me o lam a<br />
class pro o pe me o class<br />
lam a p l op io al isi l p e color<br />
se o ori i p<br />
e isi l p s o mo e p color<br />
il
22 CHAPTER 5 . CONCEPTS<br />
a me o<br />
appl ma e i s a ce me o class<br />
c io compile il lam a<br />
speciali ers lis i class posi io<br />
i er e l speciali er<br />
ali iers<br />
lam a lis p l op io al isi l p<br />
e color<br />
i i ar s<br />
lass inalizati on rotocol<br />
Class nal i at i on is <strong>the</strong>process <strong>of</strong> computing<strong>the</strong>information a class inheri ts fromits supercl<br />
asses <strong>and</strong>prepari ng toactuallyallocate instances <strong>of</strong> <strong>the</strong> class. <strong>The</strong> classnalization<br />
process i ncl udes computing<strong>the</strong> class's class precedence list, <strong>the</strong>full set <strong>of</strong> slots accessible<br />
in instances <strong>of</strong> <strong>the</strong> class<strong>and</strong><strong>the</strong>full set <strong>of</strong> default initializationarguments for <strong>the</strong> class.<br />
<strong>The</strong>se val ues are associ ated with<strong>the</strong>classmetaobj ect <strong>and</strong> can be accessed bycalling<strong>the</strong><br />
appropri ate reader. In addition, <strong>the</strong>classnalizationprocess makes deci si ons about how<br />
instances <strong>of</strong> <strong>the</strong> classwill beimplemented.<br />
To support f orward-referenced superclasses, <strong>and</strong> to account for <strong>the</strong> f act that not al l<br />
classes are actuallyinstantiated,classnalizationis not done aspart <strong>of</strong> <strong>the</strong> initialization<strong>of</strong><br />
<strong>the</strong>classmetaobj ect. I nstead, nalizationis done asaseparate protocol, invoked bycalling<br />
<strong>the</strong>generi c functi on nalize-inheri tance. <strong>The</strong> exact poi nt atwhichnalize-inheri tance<br />
is calleddepends on<strong>the</strong> class <strong>of</strong> <strong>the</strong>classmetaobj ect; f or st<strong>and</strong>ard-class it is calledsometime<br />
af ter al l <strong>the</strong> classes superclasses are dened, but nolaterthan when <strong>the</strong> rst instance<br />
<strong>of</strong> <strong>the</strong> class is allocated(by allocate-instance).<br />
<strong>The</strong> rst step <strong>of</strong> class nalizationis computing<strong>the</strong>classprecedence list. Doi ng this rst<br />
allows subsequent steps to access <strong>the</strong>classprecedence list. This step is performed bycalling<br />
<strong>the</strong>generi c functi on compute-class-precedence-l i st. <strong>The</strong> val ue returned fromthis call is<br />
associ ated with<strong>the</strong>classmetaobj ect <strong>and</strong> can be accessed bycalling<strong>the</strong> cl ass-precedencelist<br />
generi c functi on.<br />
<strong>The</strong> second step is computing<strong>the</strong>full set <strong>of</strong> slots that will be accessi ble ininstances <strong>of</strong><br />
<strong>the</strong> class. This step is performed bycalling<strong>the</strong>generi c functi on compute-slots. <strong>The</strong> result<br />
<strong>of</strong> this call is alist <strong>of</strong> eecti ve slotdenitionmetaobj ects. This val ue i s associ ated with<strong>the</strong><br />
cl ass metaobj ect <strong>and</strong> can be accessed bycalling<strong>the</strong> cl ass-slots generi c functi on.<br />
<strong>The</strong> behavior <strong>of</strong> compute-slots is itself layered, consisting <strong>of</strong> calls to e ecti ve- sl otdenition-class<br />
<strong>and</strong> compute-e ecti ve- sl ot-denition.<br />
<strong>The</strong> nal step <strong>of</strong> class nalizationis computing<strong>the</strong>full set <strong>of</strong> initializationarguments<br />
for <strong>the</strong> class. This is done bycalling<strong>the</strong>generi c functi on compute-def ault-initargs. <strong>The</strong><br />
val ue returned bythi s generi c functi on i s associ ated with<strong>the</strong>classmetaobj ect <strong>and</strong> can be<br />
accessed bycalling cl ass-def ault-initargs.
S PROTOCO S 23<br />
If <strong>the</strong>classwas previously nal i zed, nalize-inheri tance may cal l ma e- i nstancesobsolete.<br />
<strong>The</strong> circumstances under whichthis happens are descri be in<strong>the</strong> secti on <strong>of</strong> <strong>the</strong><br />
CLOS speci cati on cal l ed \RedeningClasses."<br />
Forward-referenced cl asses, whichprovideatemporary denitionfor a class whichhas<br />
been referenced but not yet dened, can never be nal i zed. An error is signalledif nalizeinheri<br />
tance is calledonaforward-referenced cl ass.<br />
nstance Structure<br />
rotocol<br />
<strong>The</strong> instance structure protocol is responsible for implementing<strong>the</strong> behavior <strong>of</strong> <strong>the</strong> slot<br />
access functi ons like slot-value <strong>and</strong> (setf slot-value).<br />
For each CLOS sl ot access functi on o<strong>the</strong>r than slot-e ists-p, <strong>the</strong>re is a corresponding<br />
generi c functi on whichactuallyprovides <strong>the</strong> behavior <strong>of</strong> <strong>the</strong>functi on. When cal l ed, <strong>the</strong>slot<br />
access functi on nds <strong>the</strong>pertinent eecti ve slotdenitionmetaobj ect, cal l s <strong>the</strong> correspondinggeneri<br />
c functi on <strong>and</strong>returns its result. <strong>The</strong> arguments passed onto <strong>the</strong>generi c functi on<br />
incl ude oneadditional val ue, <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument, whichalways immediately<br />
precedes <strong>the</strong> obj ect argument<br />
<strong>The</strong> correspondences between sl ot access functi on <strong>and</strong> underl ying sl ot access generi c<br />
functionare as follows:<br />
lot ccess Functi on Corresponding lot ccess<br />
Generi c Functi on<br />
slot-boundp<br />
slot-ma unbound<br />
slot-value<br />
(setf slot-value)<br />
slot-boundp-using-class<br />
slot-ma unbound-using-class<br />
slot-value- usi ng-class<br />
(setf slot-value-using-class)<br />
At <strong>the</strong>lowest l evel , <strong>the</strong> instance structure protocol provides only limitedmechanisms<br />
for portable programs to control <strong>the</strong> implementation<strong>of</strong> instances <strong>and</strong> todi rectl y access<br />
<strong>the</strong> storage associated withinstances without goi ng through <strong>the</strong> indirection<strong>of</strong> slot access.<br />
This is done toallowportable programs toperformcertai n commonlyrequested sl ot access<br />
optimi zati ons.<br />
In particular, portable programs can control <strong>the</strong>implementati on <strong>of</strong> , <strong>and</strong> obtain di rect<br />
access to, sl ots with allocation:instance <strong>and</strong> type t. <strong>The</strong>se are cal l ed di rect l accessi bl e<br />
sl ot s.<br />
<strong>The</strong> rel evant speci ed around-method on compute-slots determines <strong>the</strong> implementati<br />
on <strong>of</strong> i nstances bydeci dinghoweach sl ot i n <strong>the</strong> instance will be stored. For each directly<br />
accessi bl e sl ot, this methodallocates alocat i on <strong>and</strong> associ ates i t with<strong>the</strong>eecti ve slotdefinitionmetaobj<br />
ect. <strong>The</strong> l ocati on can be accessed bycalling<strong>the</strong> slot-denition-location
24 CHAPTER 5 . CONCEPTS<br />
generi c functi on. Locati ons arenon-negati ve integers. For a gi ven class, <strong>the</strong> l ocati ons increase<br />
consecutivel y, in <strong>the</strong> order that <strong>the</strong> di rectl y accessi bl e sl ots appear i n <strong>the</strong> list <strong>of</strong><br />
eecti ve slots. ( ote that here, <strong>the</strong> next paragraph, <strong>and</strong><strong>the</strong>speci cati on <strong>of</strong> thi s aroundmethod<br />
are <strong>the</strong> onlypl aces where <strong>the</strong> val ue returned by compute-slots is descri bed as a<br />
list ra<strong>the</strong>r than a set. )<br />
Given <strong>the</strong> l ocati on <strong>of</strong> a di rectl y accessi bl e sl ot, <strong>the</strong> val ue <strong>of</strong> that sl ot i n an i nstance<br />
can be accessed with <strong>the</strong>appropriate accessor. For st<strong>and</strong>ard-class, thi s accessor i s <strong>the</strong><br />
functi on st<strong>and</strong>ard-instance-access. For funcallable-st<strong>and</strong>ard-class, thi s accessor i s<br />
<strong>the</strong>functi on funcallable-st<strong>and</strong>ard-instance-access. I n each case, <strong>the</strong> arguments to <strong>the</strong><br />
accessor are <strong>the</strong>instance <strong>and</strong><strong>the</strong> slot location, in that order. See <strong>the</strong> denition <strong>of</strong> each<br />
accessor i n Chapter 6 for additional restrictionson<strong>the</strong>use <strong>of</strong> <strong>the</strong>se functi on.<br />
Portable programs arepermitted to aect <strong>and</strong>relyon<strong>the</strong> al l ocati on <strong>of</strong> l ocati ons only<br />
in <strong>the</strong> following limited way: Byrst deningaportable primary method on computeslots<br />
whichorders <strong>the</strong> returned val ue inapredictable way, <strong>and</strong><strong>the</strong>n rel yingon<strong>the</strong>dened<br />
behavior <strong>of</strong> <strong>the</strong>speci ed around-method to assign locationstoalldi rectl y accessi ble slots.<br />
Portable programs may compile-incalls to low-level accessors whichtakeadvantage <strong>of</strong> <strong>the</strong><br />
resultingpredictabl e al l ocati on <strong>of</strong> sl ot l ocati ons.<br />
ample:<br />
<strong>The</strong>followingexampleshows <strong>the</strong>use <strong>of</strong> this mechanismtoimplementanewcl ass metaobject<br />
cl ass, ordered-class <strong>and</strong>class option:slot-order. This opti on provides control over<br />
<strong>the</strong> al l ocati on <strong>of</strong> sl ot l ocati ons. In this simple example implementation, <strong>the</strong> :slot-order<br />
opti on i s not i nheri ted bysubclasses; it controls onlyinstances <strong>of</strong> <strong>the</strong> class itself.<br />
e class or ere class s a ar class<br />
slo or er i i orm<br />
i i ar slo or er<br />
rea er class slo or er<br />
e me o comp e slo s class or ere class<br />
le or er class slo or er class<br />
sor cop lis call ex me o<br />
lam a a<br />
posi io slo e i i io ame a or er<br />
posi io slo e i i io ame a or er<br />
Fol l owingis <strong>the</strong>source code<strong>the</strong>user <strong>of</strong> this extensi on wouldwrite. ote that because<br />
<strong>the</strong>code above doesn't implement inheri tance <strong>of</strong> <strong>the</strong> :slot-order option, <strong>the</strong>functi on<br />
distance must not be calledoninstances <strong>of</strong> subclasses <strong>of</strong> point; i t can onlybe calledon<br />
instances <strong>of</strong> point itself.<br />
e class poi<br />
x i i orm
S PROTOCO S 25<br />
i i orm<br />
me aclass or ere<br />
slo or er x<br />
class<br />
e is a ce poi<br />
s r / exp s a ar i s a ce access poi<br />
exp s a ar i s a ce access poi<br />
.<br />
In more realistic uses <strong>of</strong> this mechanism, <strong>the</strong> calls to <strong>the</strong> low-level i nstance structure<br />
accessors wouldnot actuallyappear textuallyin<strong>the</strong>source program, but ra<strong>the</strong>r would<br />
be generated byameta- l evel anal ysis programrunduring<strong>the</strong>process <strong>of</strong> compiling<strong>the</strong><br />
source program.<br />
uncalla le nstances<br />
Instances <strong>of</strong> cl asses which are <strong>the</strong>mselves i nstances <strong>of</strong> funcallable-st<strong>and</strong>ard-class or one<br />
<strong>of</strong> i ts subclasses are called uncal l abl e i nstances. Funcallable instances can onlybecreated<br />
by allocate-instance (f uncallable-st<strong>and</strong>ard-class).<br />
Like st<strong>and</strong>ardinstances, funcallableinstances have slotswith<strong>the</strong>normal behavior. <strong>The</strong>y<br />
dier fromst<strong>and</strong>ard i nstances i n that <strong>the</strong>y can be used as functi ons aswell; that i s, <strong>the</strong>y<br />
can be passed to funcall <strong>and</strong> apply,<strong>and</strong><strong>the</strong>y can be stored as <strong>the</strong>denition<strong>of</strong> afuncti on<br />
name. Associ ated wi<strong>the</strong>achfuncallable instance i s <strong>the</strong> functi on whichit runs when it is<br />
called. This functi on can be changed withset-funcallable-instance-f uncti on.<br />
ample:<br />
<strong>The</strong> followingsimple example shows <strong>the</strong>use <strong>of</strong> funcallable instances to create a si mple,<br />
defstruct-like facility. (Funcallable instances are useful when a programneeds to construct<br />
<strong>and</strong>mai ntainaset <strong>of</strong> functi ons <strong>and</strong>informati on about those f uncti ons. <strong>The</strong>y make<br />
it possible tomai ntainboth as <strong>the</strong> same object ra<strong>the</strong>r than two separate obj ects l i nked,<br />
for example, byhash tables.)<br />
e class co s r c or<br />
ame i i ar ame accessor co s r c or ame<br />
iel s i i ar iel s accessor co s r c or iel s<br />
me aclass calla le s a ar class<br />
e me o i i iali e i s a ce a er c co s r c or e<br />
i slo s ame iel s c<br />
se calla le i s a ce c io<br />
c<br />
lam a<br />
le e ma e arra le iel s
26 CHAPTER 5 . CONCEPTS<br />
se are e ame<br />
e<br />
se c ma e i s a ce co s r c or<br />
ame posi io iel s x<br />
se p call c<br />
eneric uncti on n ocati on rotocol<br />
Associ ated wi<strong>the</strong>achgeneri c functi on i s i ts discriminati ng functi on. Each ti me <strong>the</strong>generi c<br />
functionis called,<strong>the</strong>discriminati ngfunctionis calledtoprovide<strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c<br />
functi on. <strong>The</strong> discriminati ng functi on recei ves <strong>the</strong> full set <strong>of</strong> arguments recei ved by <strong>the</strong><br />
generi c functi on. It must lookup <strong>and</strong>execute <strong>the</strong> appropriate methods, <strong>and</strong>return <strong>the</strong><br />
appropriate val ues.<br />
<strong>The</strong> discriminati ngfuncti oni s computedby<strong>the</strong>highest l ayer <strong>of</strong> <strong>the</strong>generi c functi oni nvocati<br />
on protocol, compute-discriminati ng-functi on. Whenever a generi c functi on metaobject<br />
is initialized,reinitialized,oramethodis added or removed, <strong>the</strong>discriminati ngfunction<br />
is recomputed. <strong>The</strong> newdiscriminati ng functi on i s <strong>the</strong>n stored withset-funcallableinstance-functi<br />
on.<br />
Discriminati ngfuncti ons cal l compute-applicable-methods <strong>and</strong> compute-applicablemethods-using-classes<br />
to compute <strong>the</strong>methods applicable to <strong>the</strong>generi c functi ons arguments.<br />
Applicable methods arecombined by compute-e ecti ve-method to produce an<br />
e ect i e met hod. Provisionsaremade to allowmemoization<strong>of</strong> <strong>the</strong>method applicability<br />
<strong>and</strong> eecti ve methods computations. (See <strong>the</strong> descri pti on <strong>of</strong> compute-discriminati ngfuncti<br />
on for details.)<br />
<strong>The</strong> body <strong>of</strong> method denitionsareprocessed by ma e- method-lambda. <strong>The</strong> result<br />
<strong>of</strong> thi s generi c functionis alambda expression whichis processed byei<strong>the</strong>r compileor <strong>the</strong><br />
le compiler toproduce a met hod unct i on. <strong>The</strong> arguments recei ved by<strong>the</strong>method f uncti on<br />
are controlled by<strong>the</strong> call-method formsappeari ng in<strong>the</strong>eecti ve methods. By default,<br />
method f uncti ons accept twoarguments: a list <strong>of</strong> arguments to <strong>the</strong>generi c functi on, <strong>and</strong>a<br />
list <strong>of</strong> next methods. <strong>The</strong> list <strong>of</strong> next methods corresponds to<strong>the</strong>next methods argument<br />
to call-method. If call-method appears withadditional arguments, <strong>the</strong>se will bepassed<br />
to <strong>the</strong>method f uncti ons aswell; in<strong>the</strong>se cases, ma e- method-lambda must have created<br />
<strong>the</strong>method l ambdas to expect additional arguments.<br />
e en ent aintenance rotocol<br />
It is convenient f or portable metaobj ects to be able to memoize informati on about o<strong>the</strong>r<br />
metaobj ects, portabl e or o<strong>the</strong>rwise. Because cl ass <strong>and</strong> generi c functi on metaobj ects can
S PROTOCO S 27<br />
be reinitialized, <strong>and</strong>generi c functi on metaobj ects can be modied byadding<strong>and</strong>removing<br />
methods, a means must beprovided to update this memoi zed i nformation.<br />
<strong>The</strong> dependent mai ntenance protocol supports this byprovidingaway to register an<br />
obj ect whichshouldbenoti ed whenever a cl ass or generi c functi on i s modied. An obj ect<br />
which has been registered this wayis called a de endent <strong>of</strong> <strong>the</strong> cl ass or generi c functi on<br />
metaobj ect. <strong>The</strong> dependents <strong>of</strong> cl ass <strong>and</strong> generi c functi on metaobj ects are mai ntained with<br />
add-dependent <strong>and</strong> remove- dependent. <strong>The</strong> dependents <strong>of</strong> a cl ass or generi c functi on<br />
metaobj ect can be accessed withmap-dependents. Dependents are noti ed about amodicati<br />
on bycalling update-dependent. (See <strong>the</strong> speci cati on <strong>of</strong> update-dependent for<br />
detaileddescri pti on <strong>of</strong> <strong>the</strong> circumstances under whichit is called.)<br />
To prevent conicts between twoportable programs, or between portable programs <strong>and</strong><br />
<strong>the</strong>implementation,portable codemust not register metaobj ects <strong>the</strong>mselves as dependents.<br />
Instead, portable programs which need to record a metaobj ect as a dependent, should<br />
encapsulate that metaobj ect i n some o<strong>the</strong>r kind <strong>of</strong> obj ect, <strong>and</strong> record that obj ect as <strong>the</strong><br />
dependent. <strong>The</strong> results are undened i f this restriction is violated.<br />
ample:<br />
This example shows a general facility for encapsulatingmetaobj ects before recording<br />
<strong>the</strong>mas dependents. <strong>The</strong> facilitydenes a basi c kind<strong>of</strong> encapsulating obj ect: an updater.<br />
Specializations<strong>of</strong><strong>the</strong>basi c cl ass can be dened withappropri ate speci al updati ng<br />
behavior. In this way, informati on about <strong>the</strong>updati ng requi red i s associ ated wi th each<br />
updater ra<strong>the</strong>r than with<strong>the</strong>metaobj ect bei ngupdated.<br />
Updaters are used to encapsulate anymetaobj ect which requires updati ng when a<br />
gi ven cl ass or generi c functi on i s modied. <strong>The</strong> functi on record-updater is called to<br />
both create an updater <strong>and</strong> addit to<strong>the</strong>dependents <strong>of</strong> <strong>the</strong> cl ass or generi c functi on.<br />
Methods on<strong>the</strong>generi c functi on update-dependent, speci al i zed to <strong>the</strong> speci c class<strong>of</strong><br />
updater do <strong>the</strong>appropriate update work.<br />
e class p a er<br />
epe e i i ar epe e rea er epe e<br />
e recor p a er class epe ee epe e res i i ar s<br />
le p a er appl ma e i s a ce class epe e epe e<br />
i i ar s<br />
a epe e epe ee p a er<br />
p a er<br />
A ush-cache- updater simply ushes <strong>the</strong> cache <strong>of</strong><strong>the</strong>dependentwhenitis updated.<br />
e class l s cac e p a er p a er<br />
e me o p a e epe e epe ee p a er l s cac e p a er<br />
res ar s
28 CHAPTER 5 . CONCEPTS<br />
eclare i ore ar s<br />
l s cac e epe e p a er
a<br />
ter<br />
ene n t ons n<br />
et o s<br />
This chapter descri bes each <strong>of</strong> <strong>the</strong> functi ons <strong>and</strong>generi c functi ons that make up<strong>the</strong>CLOS<br />
Metaobj ect <strong>Protocol</strong>. <strong>The</strong> descri ptionsappear inalphabeti cal order with<strong>the</strong>exception that<br />
al l <strong>the</strong> reader generi c functi ons for each kind<strong>of</strong> metaobj ect are grouped toge<strong>the</strong>r. So, f or<br />
example, method-functi on wouldbefound withmethod-qualiers <strong>and</strong> o<strong>the</strong>r method<br />
metaobj ect readers under \Readers f or Method Metaobj ects. "<br />
<strong>The</strong> descri pti on <strong>of</strong> f uncti ons follows <strong>the</strong>same f ormas used in <strong>the</strong>CLOS speci cati on.<br />
<strong>The</strong> descri pti on <strong>of</strong> generi c functi ons issimilar to that i n <strong>the</strong> CLOS speci cati on, but some<br />
minor changes have been made in<strong>the</strong>way methods arepresented.<br />
<strong>The</strong>followingis anexample<strong>of</strong> <strong>the</strong> f ormat f or <strong>the</strong> syntaxdescri pti on <strong>of</strong> a generi c functi on:<br />
gf1<br />
op io al<br />
e<br />
This descri ption indicates that gf1 is a generi c functi on with tworequired parameters,<br />
<strong>and</strong> , an optional parameter <strong>and</strong> akeyword parameter .<br />
<strong>The</strong> descri pti on <strong>of</strong> a generi c functionincl udes a descri pti on <strong>of</strong> i ts behavior. This provides<br />
<strong>the</strong>general behavi or, or protocol <strong>of</strong> <strong>the</strong>generi c functi on. All methods dened on <strong>the</strong>generi c<br />
functi on, both portable <strong>and</strong>speci ed, must have behavior consistentwiththis descri ption.<br />
Every generi c functi on descri bed i n this section is an instance <strong>of</strong> <strong>the</strong> classst<strong>and</strong>ardgeneri<br />
c- f uncti on <strong>and</strong> uses st<strong>and</strong>ard method combinati on.<br />
<strong>The</strong> descri pti on <strong>of</strong> a generi c functionalsoincl udes descri ptions<strong>of</strong><strong>the</strong>speci ed methods<br />
for that generi c functi on. In <strong>the</strong>descri pti on <strong>of</strong> <strong>the</strong>se methods, a met hod signat ure is used<br />
to descri be <strong>the</strong>parameters <strong>and</strong>parameter speci al i zers <strong>of</strong> each method. <strong>The</strong> followingis an<br />
example <strong>of</strong> <strong>the</strong> f ormat f or a method si gnature:<br />
29
30 add-dependent Chapter 6<br />
gf1 ri mar et hod<br />
cl ass op io al e<br />
This signature indicates that this primary method on <strong>the</strong> generi c functi on gf1has two<br />
required parameters, named <strong>and</strong> . In addition, <strong>the</strong>re i s an optional parameter<br />
<strong>and</strong> akeyword parameter . This signature also indicates that <strong>the</strong> method's parameter<br />
speci al i zers are <strong>the</strong> classes named cl ass <strong>and</strong> t.<br />
<strong>The</strong> descri pti on <strong>of</strong> each method i ncl udes a descri pti on <strong>of</strong> <strong>the</strong> behavior particular to<br />
that method.<br />
An abbreviatedsyntax is used when referringtoamethod dened el sewhere i n <strong>the</strong><br />
document. This abbreviatedsyntax incl udes <strong>the</strong> name <strong>of</strong> <strong>the</strong>generi c functi on, <strong>the</strong>qual -<br />
iers, <strong>and</strong><strong>the</strong> parameter speci al i zers. A reference to <strong>the</strong> method with <strong>the</strong> signature<br />
shown above iswritten as: gf1 (class t).<br />
a e en ent eneri c unct i on<br />
S<br />
add-dependent<br />
met aobj ect de endent<br />
A<br />
<strong>The</strong> met aobj ect argument isaclassorgeneri c functi on metaobj ect.<br />
<strong>The</strong> de endent argument i s an obj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s unspeci ed.<br />
P<br />
Thi s generi c functi on adds de endent to <strong>the</strong> dependents <strong>of</strong> met aobj ect . If de endent is<br />
al ready in<strong>the</strong> set <strong>of</strong> dependents it is not added agai n (no error is signal ed).<br />
<strong>The</strong> generi c functi on map-dependents can be cal l ed to access <strong>the</strong> set <strong>of</strong> dependents<br />
<strong>of</strong> a cl ass or generi c functi on. <strong>The</strong> generi c functi on remove- dependent can be calledto<br />
remove an obj ect f rom<strong>the</strong> set <strong>of</strong> dependents <strong>of</strong> a cl ass or generi c functi on. <strong>The</strong> eect <strong>of</strong><br />
calling add-dependent or remove- dependent while acall to map-dependents on <strong>the</strong><br />
same cl ass or generi c functionis inprogress i s unspeci ed.<br />
<strong>The</strong> situati ons inwhichadd-dependent is calledare not speci ed.<br />
M<br />
add-dependent ri mar et hod<br />
cl ass s a ar class de endent<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.
Generi c Functi ons <strong>and</strong>Methods add-di rect-method 31<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
remove-dependent (st<strong>and</strong>ard-class t)<br />
map-dependents (st<strong>and</strong>ard-class t)<br />
add-dependent ri mar et hod<br />
cl ass calla le s a ar class de endent<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
remove-dependent (funcallable-st<strong>and</strong>ard-class t)<br />
map-dependents (funcallable-st<strong>and</strong>ard-class t)<br />
add-dependent ri mar et hod<br />
generi c- unct i on s a ar e eric c io de endent<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
remove-dependent (st<strong>and</strong>ard-generic-functi ont)<br />
map-dependents (st<strong>and</strong>ard-generic-functi ont)<br />
R<br />
See <strong>the</strong>\Dependent Mai ntenance <strong>Protocol</strong>" sectionfor remarks about <strong>the</strong>use <strong>of</strong> this facility.<br />
a irect et o eneri c unct i on<br />
S<br />
add-direct-method<br />
s eci al i er met hod<br />
A<br />
<strong>The</strong> s eci al i er argument isaspeci al i zer metaobj ect.<br />
<strong>The</strong> met hod argument isamethod metaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s unspeci ed.
32 add-di rect-subcl ass Chapter 6<br />
P<br />
Thi s generi c functionis calledtomai ntaina set <strong>of</strong> backpoi nters fromaspeci al i zer to <strong>the</strong> set<br />
<strong>of</strong> methods speci al i zed to i t. If met hod i s al ready in<strong>the</strong>set, itisnot added agai n (no error<br />
is signal ed).<br />
Thi s set can be accessed as a list by calling<strong>the</strong>generi c functi on speci alizer-directmethods.<br />
Methods are removed from<strong>the</strong>setby remove- di rect- method.<br />
<strong>The</strong> generi c functi onadd-di rect- methodis calledby add-methodwhenever a method<br />
is added to a generi c functi on. It is calledonce f or each <strong>of</strong> <strong>the</strong> speci al i zers <strong>of</strong> <strong>the</strong> method.<br />
ote that i n cases where a speci al i zer appears more than once i n<strong>the</strong>speci al i zers <strong>of</strong> a method,<br />
thi s generi c functi on will be calledmore than once with<strong>the</strong>samespeci al i zer as argument.<br />
<strong>The</strong> results are undened i f <strong>the</strong> s eci al i er argument isnot one <strong>of</strong><strong>the</strong>speci al i zers <strong>of</strong> <strong>the</strong><br />
met hod argument.<br />
M<br />
add-direct-method ri mar et hod<br />
s eci al i er class<br />
met hod me o<br />
This method i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functi on f or cl ass speci al i zers. o<br />
behavior is speci ed for this method beyond that which is speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
remove-di rect- method(class method)<br />
speci alizer-di rect- generi c- f uncti ons (class)<br />
speci alizer-di rect- methods (class)<br />
add-direct-method ri mar et hod<br />
s eci al i er e l speciali er<br />
met hod me o<br />
This method i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functi on for eql speci al i zers. o<br />
behavior is speci ed for this method beyond that which is speci ed for <strong>the</strong> generi c<br />
functi on.<br />
a irect su class eneri c unct i on<br />
S<br />
add-direct-subcl ass<br />
su ercl ass subcl ass<br />
A<br />
<strong>The</strong> su ercl ass argument isaclassmetaobj ect.
Generi c Functi ons <strong>and</strong>Methods add-method 33<br />
<strong>The</strong> subcl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s unspeci ed.<br />
P<br />
Thi s generi c functionis calledto mai ntai n a set <strong>of</strong> backpoi nters froma class to its di rect<br />
subclasses. Thi s generi c functi on adds subcl ass to <strong>the</strong> set <strong>of</strong> di rect subclasses <strong>of</strong> su ercl ass.<br />
Whenaclass is initialized,thi s generi c functionis calledonce for each di rect supercl ass<br />
<strong>of</strong> <strong>the</strong> class.<br />
When a class is reinitialized, thi s generi c functionis calledonce f or each added di rect<br />
supercl ass <strong>of</strong> <strong>the</strong> class. <strong>The</strong> generi c functi on remove- direct-subcl ass is called once for<br />
each del eted di rect supercl ass <strong>of</strong> <strong>the</strong> class.<br />
M<br />
add-direct-subcl ass ri mar et hod<br />
su ercl ass class<br />
subcl ass class<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
remove-direct-subcl ass (class class)<br />
cl ass-direct-subcl asses (class)<br />
a et o eneri c unct i on<br />
S<br />
add-method<br />
generi c- unct i on met hod<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> met hod argument isamethod metaobj ect.<br />
<strong>The</strong> generi c- unct i on argument isreturned.<br />
P<br />
Thi s generi c functi on associ ates an unattached method wi th a generi c functi on.<br />
An error is signal ed i f <strong>the</strong> lambdalist <strong>of</strong> <strong>the</strong>method i s not congruent with<strong>the</strong>lambda<br />
list <strong>of</strong> <strong>the</strong>generi c functi on. An error is alsosignal ed i f <strong>the</strong> method i s al ready associ ated<br />
withsomeo<strong>the</strong>r generi c functi on.
34 allocate-instance Chapter 6<br />
If <strong>the</strong>givenmethod agrees withanexistingmethod <strong>of</strong> <strong>the</strong> generi c functiononparameter<br />
speci al i zers <strong>and</strong>qualiers, <strong>the</strong>existingmethod i s removed bycalling remove-method before<br />
<strong>the</strong>newmethodis added. See <strong>the</strong> secti on <strong>of</strong> <strong>the</strong> CLOSSpeci cati on cal l ed \Agreement<br />
on Parameter Speci al i zers <strong>and</strong> ualiers" for a denition<strong>of</strong> agreement inthis context.<br />
Associating<strong>the</strong>method with<strong>the</strong>generi c functi on <strong>the</strong>n proceeds in four steps: (i) add<br />
met hod to <strong>the</strong> set returned by generi c- f uncti on-methods <strong>and</strong> arrange f or methodgeneri<br />
c- f uncti on to return generi c- unct i on; (ii) call add-di rect- method f or each <strong>of</strong> <strong>the</strong><br />
method's specializers; (iii) call compute-discriminating-functi on <strong>and</strong> install its result<br />
withset-funcallable-instance-functi on; <strong>and</strong>(iv)update <strong>the</strong> dependents <strong>of</strong> <strong>the</strong>generi c<br />
functi on.<br />
<strong>The</strong> generi c functi on add-method can be calledby<strong>the</strong>user or <strong>the</strong>implementation.<br />
M<br />
add-method ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
met hod s a ar me o<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
allocate instance eneri c unct i on<br />
S<br />
allocate-instance<br />
cl ass res ini t args<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> ini t args argument consists <strong>of</strong> alternati ng initializationargument names <strong>and</strong>val ues.<br />
<strong>The</strong> val ue returned i s a newlyallocatedinstance <strong>of</strong> cl ass.<br />
P<br />
Thi s generi c function is called to create a new, uninitializedinstance <strong>of</strong> a class. <strong>The</strong> interpretation<br />
<strong>of</strong> <strong>the</strong>concept <strong>of</strong>an\uninitialized"instance depends on<strong>the</strong>classmetaobj ect<br />
class.<br />
Before al l ocati ng<strong>the</strong>newi nstance, cl ass-nalized-pis calledto see if cl ass has been<br />
nal i zed. If it has not been nal i zed, nalize-inheritance is calledbef ore <strong>the</strong> newi nstance<br />
is allocated.
Generi c Functi ons <strong>and</strong>Methods class-::: 35<br />
M<br />
allocate-instance ri mar et hod<br />
cl ass s a ar class res ini t args<br />
This method allocates storage in <strong>the</strong>instance for each sl ot withallocation:instance.<br />
<strong>The</strong>se sl ots are unbound. Slots withanyo<strong>the</strong>r al l ocati on are i gnored bythis method (no<br />
error is signal ed).<br />
allocate-instance ri mar et hod<br />
cl ass calla le s a ar class res ini t args<br />
This method allocates storage in <strong>the</strong>instance for each sl ot withallocation:instance.<br />
<strong>The</strong>se sl ots are unbound. Slots withanyo<strong>the</strong>r al l ocati on are i gnored bythis method (no<br />
error is signal ed).<br />
<strong>The</strong> funcallable instance functi on <strong>of</strong> <strong>the</strong> instance i s undened|<strong>the</strong>results are unde-<br />
ned i f <strong>the</strong>instance i s appliedtoarguments bef ore set-funcallable-instance-functi on<br />
has been used to set <strong>the</strong>funcallable instance functi on.<br />
allocate-instance ri mar et hod<br />
cl ass il i class res ini t args<br />
This method si gnals an error.<br />
class eneri c unct i on<br />
<strong>The</strong> following generi c functi ons are descri bed toge<strong>the</strong>r under \Readers for Class<br />
Metaobj ects" (page 75): cl ass-def ault-initargs, cl ass-di rect- def ault-initargs, cl assdirect-slots,<br />
cl ass-direct-subcl asses, cl ass-direct-supercl asses, cl ass-nalized-p,<br />
cl ass-name, cl ass-precedence-l i st, cl ass-prototype <strong>and</strong> cl ass-slots.<br />
co ute a lica le et o s eneri c unct i on<br />
S<br />
compute-applicable-methods<br />
generi c- unct i on arguments<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> arguments argument isalist<strong>of</strong>objects.<br />
Thi s generi c functi on returnsapossiblyemptylist <strong>of</strong> method metaobj ects.
36 compute-applicable-methods-using- cl asses Chapter 6<br />
P<br />
Thi s generi c functi on determines <strong>the</strong> method applicability<strong>of</strong> ageneri c functiongivenalist<br />
<strong>of</strong> requi red arguments. <strong>The</strong> returned list <strong>of</strong> method metaobj ects i s sorted by precedence<br />
order with <strong>the</strong>most speci c method appeari ng rst. If nomethods areapplicable to <strong>the</strong><br />
suppliedarguments <strong>the</strong>emptylistisreturned.<br />
When a generi c functi on i s i nvoked, <strong>the</strong> discriminati ng functi on must determine <strong>the</strong><br />
ordered l i st <strong>of</strong> methods applicable to <strong>the</strong>arguments. Dependingon<strong>the</strong>generi c function<strong>and</strong><br />
<strong>the</strong>arguments, this is done inone<strong>of</strong>three ways: usingamemoi zedval ue; calling computeapplicable-methods-using-classes;<br />
or calling compute-applicable-methods. (Refer<br />
to <strong>the</strong>descri pti on <strong>of</strong> compute-discriminati ng-functi on for <strong>the</strong>details <strong>of</strong> this process.)<br />
<strong>The</strong> arguments argumentispermittedtocontainmore el ements than <strong>the</strong> generi c functi on<br />
accepts requi red arguments; in <strong>the</strong>se cases <strong>the</strong> extra arguments will beignored. An error<br />
is signal ed i f arguments containsfewer el ements than <strong>the</strong> generi c functi on accepts required<br />
arguments.<br />
<strong>The</strong> list returned bythi s generi c functi on will not be mutated by<strong>the</strong>implementation.<br />
<strong>The</strong> results are undened i f a portable programmutates <strong>the</strong> list returned bythi s generi c<br />
functi on.<br />
M<br />
compute-applicable-methods ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
arguments<br />
This method si gnals an error if anymethod <strong>of</strong> <strong>the</strong> generi c functi on has a speci al i zer<br />
whichis nei <strong>the</strong>r a cl ass metaobj ect nor an eql speci al i zer metaobj ect.<br />
O<strong>the</strong>rwise, this method computes <strong>the</strong>sortedlist<strong>of</strong>applicable methods accordingto<br />
<strong>the</strong>rules descri bed i n <strong>the</strong> secti on <strong>of</strong> <strong>the</strong> CLOS Speci cati on cal l ed \Method Sel ecti on<br />
<strong>and</strong> Combinati on."<br />
This method can be overridden. Because <strong>of</strong> <strong>the</strong>consistency requirements between<br />
thi s generi c functi on <strong>and</strong> compute-applicable-methods-usi ng-classes, doi ngsomay<br />
require al so overriding compute-applicable-methods-usi ng-classes (st<strong>and</strong>ardgeneri<br />
c- f uncti ont).<br />
co ute a lica le et o s usi n classes eneri c unct i on<br />
S<br />
compute-applicable-methods-using-classes<br />
generi c- unction cl asses<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> cl asses argument is alist <strong>of</strong> class metaobj ects.
Generi c Functi ons <strong>and</strong>Methods compute-applicable-methods-using- cl asses 37<br />
Thi s generi c functi on returns twoval ues. <strong>The</strong> rst is a possibly empty list <strong>of</strong> method<br />
metaobj ects. <strong>The</strong> secondis ei<strong>the</strong>r true or f al se.<br />
P<br />
Thi s generi c functionis calledtoattempt todetermine<strong>the</strong>method applicability<strong>of</strong> ageneri c<br />
functiongiven only<strong>the</strong> classes <strong>of</strong> <strong>the</strong>requi red arguments.<br />
If it is possible to completely determine<strong>the</strong> ordered l i st <strong>of</strong> applicable methods based<br />
onlyon<strong>the</strong>supplied classes, thi s generi c functi on returnsthat list as its rst val ue <strong>and</strong>true<br />
as i ts secondval ue. <strong>The</strong> returnedlist <strong>of</strong> method metaobj ects i s sorted byprecedence order,<br />
<strong>the</strong>most speci c method comingrst. If nomethods areapplicabl e to arguments with<strong>the</strong><br />
speci ed classes, <strong>the</strong>emptylist <strong>and</strong> true are returned.<br />
If it is not possible tocompletelydetermine<strong>the</strong>ordered l i st <strong>of</strong> applicable methods based<br />
onlyon<strong>the</strong>suppliedclasses, thi s generi c functionreturnsanunspeci ed rst val ue <strong>and</strong>false<br />
as i ts secondval ue.<br />
When a generi c functi on i s i nvoked, <strong>the</strong> discriminati ng functi on must determine <strong>the</strong><br />
ordered l i st <strong>of</strong> methods applicable to <strong>the</strong>arguments. Dependingon<strong>the</strong>generi c function<strong>and</strong><br />
<strong>the</strong>arguments, this is done inone<strong>of</strong>three ways: usingamemoi zedval ue; calling computeapplicable-methods-using-classes;<br />
or calling compute-applicable-methods. (Refer<br />
to <strong>the</strong>descri pti on <strong>of</strong> compute-discriminati ng-functi on for <strong>the</strong>details <strong>of</strong> this process.)<br />
<strong>The</strong> followingconsistency relationshipbetweencompute-applicable-methods-usi ngcl<br />
asses <strong>and</strong> compute-applicable-methods must be mai ntained: for anygiven generi c<br />
functi on <strong>and</strong> set <strong>of</strong> arguments, if compute-applicable-methods-using-classes returns<br />
a second val ue <strong>of</strong> true, <strong>the</strong> rst val ue must beequal to <strong>the</strong>val ue that wouldbereturned<br />
by a corresponding cal l to compute-applicable-methods. <strong>The</strong> results are undened i f a<br />
portable method on ei <strong>the</strong>r <strong>of</strong> <strong>the</strong>se generi c functi ons causes this consistency to be violated.<br />
<strong>The</strong> list returned bythi s generi c functi on will not be mutated by<strong>the</strong>implementation.<br />
<strong>The</strong> results are undened i f a portable programmutates <strong>the</strong> list returned bythi s generi c<br />
functi on.<br />
M<br />
compute-applicable-methods-using-classes ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
cl asses<br />
If anymethod <strong>of</strong> <strong>the</strong> generi c functionhas a speci al i zer whichis nei <strong>the</strong>r a cl ass metaobj ect<br />
nor an eql speci al i zer metaobj ect, this method si gnals an error.<br />
In cases where <strong>the</strong> generi c functi on has no methods wi<strong>the</strong>ql speci al i zers, or has no<br />
methods with eql speci al i zers that could be applicabl e to arguments <strong>of</strong> <strong>the</strong> supplied<br />
classes, this method returns<strong>the</strong>ordered l i st <strong>of</strong> applicable methods asitsrst val ue <strong>and</strong><br />
true as its secondval ue.<br />
O<strong>the</strong>rwise this methodreturnsanunspeci ed rst val ue <strong>and</strong> f al se as i ts secondval ue.
38 compute-class-precedence-l i st Chapter 6<br />
This method can be overridden. Because <strong>of</strong> <strong>the</strong>consistency requirements between<br />
thi s generi c functi on <strong>and</strong> compute-applicable-methods, doi ng somay require also<br />
overriding compute-applicable-methods (st<strong>and</strong>ard-generi c- f uncti ont).<br />
R<br />
Thi s generi c functi on exists to allowuser extensionswhichalter method l ookup rules, but<br />
whichbase <strong>the</strong> newrules onlyon<strong>the</strong> classes <strong>of</strong> <strong>the</strong>requi red arguments, to takeadvantage<br />
<strong>of</strong> <strong>the</strong> class-based method l ookup memoi zati on found inmany implementations. (<strong>The</strong>re i s<br />
<strong>of</strong> course norequirement f or an i mplementationto providethis optimi zati on.)<br />
Such an extensioncanbeimplementedbytwomethods, oneonthi s generi c function<strong>and</strong><br />
one oncompute-applicable-methods. Whenever <strong>the</strong> user extensionis ineect, <strong>the</strong> rst<br />
method will return a secondval ue <strong>of</strong> true. This shouldallow<strong>the</strong> implementationto absorb<br />
<strong>the</strong>se cases i nto its ownmemoizationscheme.<br />
To get appropriate performance, o<strong>the</strong>r kinds <strong>of</strong> extensions may require methods on<br />
compute-discriminati ng-functi on whichimplement <strong>the</strong>i r ownmemoi zati on scheme.<br />
co ute class rece ence list eneri c unct i on<br />
S<br />
compute-class-precedence-list<br />
cl ass<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functionis alist <strong>of</strong> class metaobj ects.<br />
P<br />
Thi s generi c-functionis calledtodetermine<strong>the</strong>classprecedence list <strong>of</strong> aclass.<br />
<strong>The</strong> result is alist whichcontains each <strong>of</strong> cl ass <strong>and</strong> its supercl asses once <strong>and</strong>onlyonce.<br />
<strong>The</strong> rst el ement <strong>of</strong><strong>the</strong> list is cl ass <strong>and</strong> <strong>the</strong>lastelement is<strong>the</strong>classnamed t.<br />
All methods onthi s generi c functi onmust compute <strong>the</strong>classprecedence list as afuncti on<br />
<strong>of</strong> <strong>the</strong> ordered di rect supercl asses <strong>of</strong> <strong>the</strong> supercl asses <strong>of</strong> cl ass . <strong>The</strong> results are undened i f<br />
<strong>the</strong>rules used to compute <strong>the</strong>classprecedence list dependonanyo<strong>the</strong>r factors.<br />
Whenaclass is nal i zed, nalize-inheri tance calls thi s generi c function<strong>and</strong> associ ates<br />
<strong>the</strong>returned val ue with <strong>the</strong>classmetaobj ect. <strong>The</strong> val ue can<strong>the</strong>n be accessed bycalling<br />
cl ass-precedence-l i st.<br />
<strong>The</strong> list returned bythi s generi c functi on will not be mutated by<strong>the</strong>implementation.<br />
<strong>The</strong> results are undened i f a portable programmutates <strong>the</strong> list returned bythi s generi c<br />
functi on.
Generi c Functi ons <strong>and</strong>Methods compute-default-ini targs 39<br />
M<br />
compute-class-precedence-list ri mar et hod<br />
cl ass class<br />
This method computes <strong>the</strong>classprecedence l i st accordingto<strong>the</strong>rules descri bed i n <strong>the</strong><br />
secti on <strong>of</strong> <strong>the</strong> CLOS Speci cati on cal l ed \Determining<strong>the</strong>Class Precedence List."<br />
This method si gnals anerror if cl ass or any<strong>of</strong> its superclasses is a forwardreferenced<br />
class.<br />
This method can be overridden.<br />
co ute e ault initar s eneri c unct i on<br />
S<br />
compute-def ault-initargs<br />
cl ass<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c function is a list <strong>of</strong> canonicalized default initialization<br />
arguments.<br />
P<br />
Thi s generi c-functionis calledtodetermine<strong>the</strong>default initializationarguments for a class.<br />
<strong>The</strong> result is alist <strong>of</strong> canonicalizeddefault initializationarguments, withnoduplication<br />
among initializationargument names.<br />
All methods onthi s generi c functi on must compute <strong>the</strong>default initializationarguments<br />
as a f uncti on <strong>of</strong> only: (i) <strong>the</strong> class precedence list <strong>of</strong> cl ass , <strong>and</strong> (ii) <strong>the</strong> di rect default<br />
initializationarguments <strong>of</strong> each cl ass i n that list. <strong>The</strong> results are undened i f <strong>the</strong> rules used<br />
to compute <strong>the</strong>default initializationarguments dependonanyo<strong>the</strong>r factors.<br />
Whenaclass is nal i zed, nalize-inheri tance calls thi s generi c function<strong>and</strong> associ ates<br />
<strong>the</strong>returned val ue with <strong>the</strong>classmetaobj ect. <strong>The</strong> val ue can<strong>the</strong>n be accessed bycalling<br />
cl ass-def ault-initargs.<br />
<strong>The</strong> list returned bythi s generi c functi on will not be mutated by<strong>the</strong>implementation.<br />
<strong>The</strong> results are undened i f a portable programmutates <strong>the</strong> list returned bythi s generi c<br />
functi on.
40 compute-discriminati ng- f uncti on Chapter 6<br />
M<br />
compute-def ault-initargs ri mar et hod<br />
cl ass s a ar class<br />
compute-def ault-initargs ri mar et hod<br />
cl ass calla le s a ar class<br />
<strong>The</strong>se methods compute <strong>the</strong>default initializationarguments accordingto<strong>the</strong>rules described<br />
i n <strong>the</strong> secti on <strong>of</strong> <strong>the</strong> CLOS Speci cati on cal l ed \Defaulting<strong>of</strong> InitializationArguments."<br />
<strong>The</strong>se methods signal an error i f cl ass or any<strong>of</strong> its superclasses is aforwardreferenced<br />
class.<br />
<strong>The</strong>se methods can be overridden.<br />
co ute iscri inati n uncti on eneri c unct i on<br />
S<br />
compute-discriminati ng-functi on<br />
generi c- unct i on<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s a functi on.<br />
P<br />
Thi s generi c functioniscalledtodetermine<strong>the</strong>discriminati ngfunctionforageneri c functi on.<br />
When a generi c functionis called, <strong>the</strong> inst al l ed discriminati ng function is calledwith<strong>the</strong><br />
full set <strong>of</strong> arguments recei ved by<strong>the</strong>generi c functi on, <strong>and</strong>must implement <strong>the</strong>behavior <strong>of</strong><br />
calling<strong>the</strong>generi c functi on: determining<strong>the</strong>ordered set <strong>of</strong> applicablemethods, determining<br />
<strong>the</strong>eecti ve method, <strong>and</strong>running<strong>the</strong>eecti ve method.<br />
To determine<strong>the</strong> ordered set <strong>of</strong> applicable methods, <strong>the</strong> discriminati ng functi on rst<br />
calls compute-applicable-methods-using-classes. If compute-applicable-methodsusing-classes<br />
returns a second val ue <strong>of</strong> f al se, <strong>the</strong> discriminati ng functi on <strong>the</strong>n cal l s<br />
compute-applicable-methods.<br />
When compute-applicable-methods-using-classes returns a second val ue <strong>of</strong> true,<br />
<strong>the</strong>discriminati ngfuncti on i s permittedto memoi ze <strong>the</strong> rst returned val ueas follows. <strong>The</strong><br />
discriminati ngfuncti on mayreuse <strong>the</strong> list <strong>of</strong> applicable methods without calling computeapplicable-methods-using-classes<br />
agai n provided that:<br />
(i) <strong>the</strong>generi c functi on i s bei ng cal l ed agai n withrequi red arguments whichare<br />
instances <strong>of</strong> <strong>the</strong> same classes,<br />
(ii) <strong>the</strong>generi c functi on has not been rei nitialized,
Generi c Functi ons <strong>and</strong>Methods compute-eecti ve-method 41<br />
(iii) nomethod has been added to or removed from<strong>the</strong>generi c functi on,<br />
(iv) f or al l <strong>the</strong> speci al i zers <strong>of</strong> al l <strong>the</strong> generi c functi on's methods whichare classes,<br />
<strong>the</strong>i r cl ass precedence lists have not changed <strong>and</strong><br />
(v) f or any such memoi zed val ue, <strong>the</strong> classprecedence list <strong>of</strong> <strong>the</strong> cl ass <strong>of</strong> each <strong>of</strong><br />
<strong>the</strong>requi red arguments has not changed.<br />
Determinati on <strong>of</strong> <strong>the</strong> eecti ve method i s done bycalling compute-e ecti ve- method.<br />
When <strong>the</strong> eecti ve method i s run, each method's functionis called, <strong>and</strong> recei ves as arguments:<br />
(i) a list <strong>of</strong> <strong>the</strong>arguments to <strong>the</strong>generi c functi on, <strong>and</strong>(ii) whatever o<strong>the</strong>r arguments<br />
are speci ed i n <strong>the</strong> call-method formindicatingthat <strong>the</strong> method shouldbe called. (See<br />
ma e- method-lambda for more i nformati on about howmethod f uncti ons are called.)<br />
<strong>The</strong> generi c functi on compute-discriminating-functi on is called, <strong>and</strong> its result<br />
installed, by add-method, remove- method, initialize-instance <strong>and</strong> rei nitializeinstance.<br />
M<br />
compute-discriminati ng-functi on ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
obehaviorisspeci ed for this method beyond that speci ed for <strong>the</strong> generi c functi on.<br />
This method can be overridden.<br />
co ute e ecti e et o eneri c unct i on<br />
S<br />
compute-e ecti ve- method<br />
generi c- unct i on met hod- combi nat i on met hods<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> met hod- combi nat i on argument isamethod combinati on metaobj ect.<br />
<strong>The</strong> met hods argument isalist<strong>of</strong>method metaobj ects.<br />
Thi s generi c functi on returns twoval ues. <strong>The</strong> rst is an eecti ve method, <strong>the</strong> secondisa<br />
list <strong>of</strong> eecti ve method options.<br />
P<br />
Thi s generi c functionis calledtodetermine<strong>the</strong>eecti vemethodfromasortedlist <strong>of</strong> method<br />
metaobj ects.<br />
An eecti ve method i s a f ormthat descri bes how <strong>the</strong> applicable methods are to be<br />
combined. Inside<strong>of</strong>eecti ve method f orms arecall-method formswhichindi cate that a<br />
particular methodis tobe called. <strong>The</strong> arguments to <strong>the</strong> call-methodformindi cate exactl y
42 compute-eecti ve-sl ot-denition Chapter 6<br />
how<strong>the</strong> method f uncti on <strong>of</strong> <strong>the</strong> method shouldbe called. (See ma e- method-lambda for<br />
more details about method f uncti ons.)<br />
An eecti ve method opti on has <strong>the</strong> sameinterpretation <strong>and</strong>syntax as ei<strong>the</strong>r <strong>the</strong> :arguments<br />
or <strong>the</strong> :generi c- f uncti onoptionin<strong>the</strong>long f orm<strong>of</strong> dene- method-combination.<br />
More i nformati on about <strong>the</strong> f orm<strong>and</strong> interpretation <strong>of</strong> eecti ve methods <strong>and</strong>eecti ve<br />
method options can be found under <strong>the</strong> descri pti on <strong>of</strong> <strong>the</strong> dene- method-combinati on<br />
macro in <strong>the</strong>CLOS speci cati on.<br />
Thi s generi c functi on can be calledby<strong>the</strong>user or <strong>the</strong>implementation. Itiscalledby<br />
discriminati ng functi ons whenever a sorted list <strong>of</strong> applicable methods must beconvertedto<br />
an eecti ve method.<br />
M<br />
compute-e ecti ve- method ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
met hod- combi nat i on<br />
met hods<br />
This method computes <strong>the</strong>eecti ve method accordingto<strong>the</strong>rules <strong>of</strong> <strong>the</strong>method combinati<br />
on type implementedby met hod- combi nat i on.<br />
This method can be overridden.<br />
co ute e ecti e sl ot e nition eneri c unct i on<br />
S<br />
compute-e ecti ve- sl ot-denition<br />
cl ass name di rect - sl ot - de nitions<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> name argument i s a sl ot name.<br />
<strong>The</strong> di rect -sl ot -de nitions argument isanordered l i st <strong>of</strong> di rect sl ot denitionmetaobjects.<br />
<strong>The</strong> most speci c di rect sl ot denitionmetaobj ect appears rst in <strong>the</strong> list.<br />
<strong>The</strong> val ue returned bythi s generi c functionis aneecti ve slotdenitionmetaobj ect.<br />
P<br />
Thi s generi c functi on determines <strong>the</strong> eecti ve slotdenitionfor aslot inaclass. It is called<br />
by compute-slots once for each sl ot accessi ble ininstances <strong>of</strong> cl ass.<br />
Thi s generi c functi on uses <strong>the</strong>suppliedlist <strong>of</strong> di rect sl ot denitionmetaobj ects to compute<br />
<strong>the</strong>inheri tance <strong>of</strong> sl ot properties for a singl e sl ot. <strong>The</strong> returned eecti veslotdenition<br />
represents <strong>the</strong> resul t <strong>of</strong> computing<strong>the</strong> inheri tance. <strong>The</strong> name <strong>of</strong> <strong>the</strong> new eecti ve slot<br />
denitionis <strong>the</strong>sameas<strong>the</strong>name <strong>of</strong><strong>the</strong>di rect sl ot denitionssupplied.
Generi c Functi ons <strong>and</strong>Methods compute-slots 43<br />
<strong>The</strong> class <strong>of</strong> <strong>the</strong>eecti ve slotdenitionmetaobj ect i s determined bycalling e ecti veslot-denition-class.<br />
<strong>The</strong> eecti ve slot denition is <strong>the</strong>n created by calling ma e-<br />
instance. <strong>The</strong> initializationarguments passed in this call to ma e- i nstance are used to<br />
initialize <strong>the</strong>neweecti ve slotdenitionmetaobj ect. See \I nitialization<strong>of</strong> Slot Denition<br />
Metaobj ects" f or details.<br />
M<br />
compute-e ecti ve- sl ot-denition ri mar et hod<br />
cl ass s a ar class<br />
name<br />
di rect -sl ot -de nitions<br />
This method i mplements <strong>the</strong>inheri tance <strong>and</strong>defaulting<strong>of</strong> slot options following<strong>the</strong>rules<br />
descri bed i n <strong>the</strong> \Inheri tance <strong>of</strong> Slots <strong>and</strong>Options" section <strong>of</strong> <strong>the</strong>CLOS Speci cati on.<br />
This method can be extended, but <strong>the</strong>val ue returned by<strong>the</strong>extendingmethod must<br />
be <strong>the</strong>val ue returned bythis method.<br />
compute-e ecti ve- sl ot-denition ri mar et hod<br />
cl ass calla le s a ar class<br />
name<br />
di rect -sl ot -de nitions<br />
This method i mplements <strong>the</strong>inheri tance <strong>and</strong>defaulting<strong>of</strong> slot options following<strong>the</strong>rules<br />
descri bed i n <strong>the</strong> \Inheri tance <strong>of</strong> Slots <strong>and</strong>Options" section <strong>of</strong> <strong>the</strong>CLOS Speci cati on.<br />
This method can be extended, but <strong>the</strong>val ue returned by<strong>the</strong>extendingmethod must<br />
be <strong>the</strong>val ue returned bythis method.<br />
co ute sl ots eneri c unct i on<br />
S<br />
compute-slots<br />
cl ass<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> val ue returned i s a set <strong>of</strong> eecti ve slotdenitionmetaobj ects.<br />
P<br />
Thi s generi c functi on computes a set <strong>of</strong> eecti ve slotdenition metaobj ects f or <strong>the</strong> class<br />
cl ass . <strong>The</strong> result is alist <strong>of</strong> eecti ve slotdenitionmetaobj ects: one for each sl ot that will<br />
be accessi ble ininstances <strong>of</strong> cl ass.<br />
Thi s generi c functi on proceeds in 3 steps:
44 compute-slots Chapter 6<br />
<strong>The</strong> rst step collects <strong>the</strong>full set <strong>of</strong> di rect sl ot denitionsfrom<strong>the</strong>supercl asses <strong>of</strong> cl ass.<br />
<strong>The</strong> di rect sl ot denitions are <strong>the</strong>n col l ected i nto individual lists, one l i st for each sl ot<br />
name associ ated withany<strong>of</strong> <strong>the</strong>di rect sl ot denitions. <strong>The</strong> slotnames are compared with<br />
eql . Each such list is <strong>the</strong>n sorted into class precedence list order. Di rect sl ot denitions<br />
comingfromcl asses earl i er i n <strong>the</strong> classprecedence list <strong>of</strong> cl ass appear bef ore those coming<br />
f romcl asses l ater i n <strong>the</strong> class precedence list. For each sl ot name, <strong>the</strong> generi c functi on<br />
compute-e ecti ve- sl ot-denition is calledto compute an eecti ve slotdenition. <strong>The</strong><br />
result <strong>of</strong> compute-slots is alist <strong>of</strong> <strong>the</strong>se eecti ve slotdenitions, in unspeci ed order.<br />
In <strong>the</strong>nal step, <strong>the</strong> l ocati on for each eecti ve slotdenitionis set. This is done by<br />
speci ed around-methods; portable methods cannot take over this behavior. For more<br />
informati on on <strong>the</strong> slotdenitionlocations, see <strong>the</strong> secti on \Instance Structure <strong>Protocol</strong>."<br />
<strong>The</strong> list returned bythi s generi c functi on will not be mutated by<strong>the</strong>implementation.<br />
<strong>The</strong> results are undened i f a portable programmutates <strong>the</strong> list returned bythi s generi c<br />
functi on.<br />
M<br />
compute-slots ri mar et hod<br />
cl ass s a ar class<br />
This method i mplements <strong>the</strong>speci ed behavior <strong>of</strong> <strong>the</strong>generi c functi on.<br />
This method can be overridden.<br />
compute-slots ri mar et hod<br />
cl ass calla le s a ar class<br />
This method i mplements <strong>the</strong>speci ed behavior <strong>of</strong> <strong>the</strong>generi c functi on.<br />
This method can be overridden.<br />
compute-slots round- et hod<br />
cl ass s a ar class<br />
This method i mplements <strong>the</strong>speci ed behavior <strong>of</strong> computing<strong>and</strong>storingslot locations.<br />
This method cannot be overridden.<br />
compute-slots round- et hod<br />
cl ass calla le s a ar class<br />
This method i mplements <strong>the</strong>speci ed behavior <strong>of</strong> computing<strong>and</strong>storingslot locations.<br />
This method cannot be overridden.
Generi c Functi ons <strong>and</strong>Methods direct-slot-denition-class 45<br />
irect sl ot e nition class eneri c unct i on<br />
S<br />
direct-slot-denition-class<br />
cl ass res ini t args<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> ini t args argument isaset<strong>of</strong>initializationarguments <strong>and</strong>val ues.<br />
<strong>The</strong> val ue returned i s a subcl ass <strong>of</strong> <strong>the</strong> classdi rect- sl ot-denition.<br />
P<br />
Whena class is initialized, each <strong>of</strong> <strong>the</strong>canonicalizedslot speci cati ons must beconverted<br />
to a di rect sl ot denitionmetaobj ect. Thi s generi c functionis calledtodetermine<strong>the</strong>class<br />
<strong>of</strong> that di rect sl ot denitionmetaobj ect.<br />
<strong>The</strong> ini t args argument issimply<strong>the</strong>canonicalizedslot speci cati on f or <strong>the</strong> slot.<br />
M<br />
direct-slot-denition-class ri mar et hod<br />
cl ass s a ar class<br />
res ini t args<br />
This method returns<strong>the</strong>classst<strong>and</strong>ard-di rect- sl ot-denition.<br />
This method can be overridden.<br />
direct-slot-denition-class ri mar et hod<br />
cl ass calla le s a ar class<br />
res ini t args<br />
This method returns<strong>the</strong>classst<strong>and</strong>ard-di rect- sl ot-denition.<br />
This method can be overridden.<br />
e ecti e sl ot e nition class eneri c unct i on<br />
S<br />
e ecti ve-slot-denition-class<br />
cl ass res ini t args<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> ini t args argument isaset<strong>of</strong>initializationarguments <strong>and</strong>val ues.
46 ensure-class Chapter 6<br />
<strong>The</strong> val ue returned i s a subcl ass <strong>of</strong> <strong>the</strong> classe ecti ve- sl ot-denition-class.<br />
P<br />
Thi s generi c function is called by compute-e ecti ve- sl ot-denition to determine <strong>the</strong><br />
cl ass <strong>of</strong> <strong>the</strong> resultingeecti veslotdenitionmetaobj ect. <strong>The</strong> ini t args argumentis<strong>the</strong>set<strong>of</strong><br />
initializationarguments <strong>and</strong>val ues that will bepassedtoma e- i nstance when <strong>the</strong>eecti ve<br />
sl ot denitionmetaobj ect i s created.<br />
M<br />
e ecti ve-slot-denition-class ri mar et hod<br />
cl ass s a ar class<br />
res i i ar s<br />
This method returns<strong>the</strong>classst<strong>and</strong>ard-e ecti ve- sl ot-denition.<br />
This method can be overridden.<br />
e ecti ve-slot-denition-class ri mar et hod<br />
cl ass calla le s a ar class<br />
res i i ar s<br />
This method returns<strong>the</strong>classst<strong>and</strong>ard-e ecti ve- sl ot-denition.<br />
This method can be overridden.<br />
ensure class<br />
unct i on<br />
S<br />
ensure-cl ass<br />
name e allo o er e s<br />
A<br />
<strong>The</strong> name argument isasymbol .<br />
Some <strong>of</strong> <strong>the</strong> keyword arguments accepted bythis function are actually processed by<br />
ensure-cl ass-using-class, o<strong>the</strong>rs are processedduringinitialization<strong>of</strong> <strong>the</strong>classmetaobj ect<br />
(as descri bed i n <strong>the</strong> sectioncalled\Initialization<strong>of</strong> Class Metaobj ects").<br />
<strong>The</strong> result is aclass metaobj ect.<br />
P<br />
This functionis calledtodene orredene aclasswith<strong>the</strong>speci ed name, <strong>and</strong> can becalled<br />
by <strong>the</strong>user or <strong>the</strong>implementation. It is <strong>the</strong>functi onal equival ent <strong>of</strong>def cl ass, <strong>and</strong>is called<br />
by <strong>the</strong>expansi on <strong>of</strong> <strong>the</strong> def cl ass macro.
Generi c Functi ons <strong>and</strong>Methods ensure-class-using- cl ass 47<br />
<strong>The</strong> behavior <strong>of</strong> this functi on i s actuallyimplemented by<strong>the</strong>generi c functi on ensurecl<br />
ass-using-class. When ensure-class is called,itimmediatelycalls ensure-class-usi ngcl<br />
ass <strong>and</strong> returnsthat result as its own.<br />
<strong>The</strong> rst argument toensure-class-using-class is computedas follows:<br />
If name names a cl ass (nd-class returnsaclasswhen cal l ed withname) use that cl ass.<br />
O<strong>the</strong>rwise use nil.<br />
<strong>The</strong> secondargument isname. <strong>The</strong> remai ningarguments are <strong>the</strong> complete set <strong>of</strong> keyword<br />
arguments recei ved by<strong>the</strong> ensure-class functi on.<br />
ensure class usi n class eneri c unct i on<br />
S<br />
ensure-cl ass-using-class<br />
cl ass name e irec e a l i i ar s irec slo s<br />
irec s perclasses ame<br />
me aclass<br />
allo o er e s<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect or nil.<br />
<strong>The</strong> name argument isaclassname.<br />
<strong>The</strong> :metacl ass argument isaclassmetaobj ect cl ass or a cl ass metaobj ect cl ass name.<br />
If thi s argument isnot supplied, it defaults to <strong>the</strong>classnamed st<strong>and</strong>ard-class. I f a cl ass<br />
name issupplied,itisinterpreted as <strong>the</strong>classwiththat name. If a cl ass name issupplied,<br />
but <strong>the</strong>re i s nosuch class, an error is signal ed.<br />
<strong>The</strong> :direct-supercl asses argument isalist<strong>of</strong>whicheachelementisaclassmetaobj ect<br />
or a cl ass name. An errorissignal ed i f thi s argument isnot a proper list.<br />
For <strong>the</strong> interpretation<strong>of</strong> additional keyword arguments, see \Initialization<strong>of</strong> Class <strong>Metaobject</strong>s"<br />
(page 57).<br />
<strong>The</strong> result is aclass metaobj ect.<br />
P<br />
Thi s generi c functionis calledtodene ormodify<strong>the</strong>denition<strong>of</strong> anamedcl ass. It i s cal l ed<br />
by <strong>the</strong> ensure-cl ass functi on. I t can al so be calleddirectly.<br />
<strong>The</strong> rst step performed bythi s generi c functi on i s to compute <strong>the</strong>set<strong>of</strong>initialization<br />
arguments whichwill beusedtocreateor reinitialize <strong>the</strong>named cl ass. <strong>The</strong> initialization<br />
arguments are computed f rom<strong>the</strong> full set <strong>of</strong> keyword arguments recei ved bythi s generi c<br />
functionas follows:
48 ensure-class-using- cl ass Chapter 6<br />
<strong>The</strong> :metacl ass argument isnot i ncl uded i n <strong>the</strong> initializationarguments.<br />
If <strong>the</strong> :direct-supercl asses argument was recei ved bythi s generi c functi on, it is converted<br />
into a list <strong>of</strong> class metaobj ects. This conversion does not aect <strong>the</strong> structure<br />
<strong>of</strong> <strong>the</strong> supplied :direct-supercl asses argument. For each el ement in <strong>the</strong> :directsupercl<br />
asses argument:<br />
If <strong>the</strong>element isaclassmetaobj ect, that cl ass metaobj ect i s used.<br />
If <strong>the</strong>element names a class, that cl ass metaobj ect i s used.<br />
O<strong>the</strong>rwise aninstance <strong>of</strong> <strong>the</strong> classforward-ref erenced-class i s created <strong>and</strong>used.<br />
<strong>The</strong> proper name <strong>of</strong> <strong>the</strong>newl y created forward referenced cl ass metaobj ect i s set to<br />
name.<br />
Al l o<strong>the</strong>r keyword arguments are i ncl uded directlyin<strong>the</strong>initializationarguments.<br />
If <strong>the</strong> cl ass argument is nil, a new cl ass metaobj ect i s created by calling<strong>the</strong> ma e-<br />
instance generi c functi on with<strong>the</strong>val ue <strong>of</strong> <strong>the</strong> :metacl ass argumentasitsrst argument,<br />
<strong>and</strong><strong>the</strong>previouslycomputedinitializationarguments. <strong>The</strong> proper name <strong>of</strong> <strong>the</strong>newl ycreated<br />
cl ass metaobj ect i s set to name. <strong>The</strong> newl y created cl ass metaobj ect i s returned.<br />
If <strong>the</strong> cl ass argument isaforward referenced class, change- cl ass is called to change<br />
its class to <strong>the</strong>val ue speci ed by<strong>the</strong> :metacl ass argument. <strong>The</strong> classmetaobj ect i s <strong>the</strong>n<br />
reinitializedwith<strong>the</strong>previously initializationarguments. (This is a documented violation<br />
<strong>of</strong> <strong>the</strong> general constraintthat change- cl ass not be used withclass metaobj ects. )<br />
If <strong>the</strong> class <strong>of</strong> <strong>the</strong> cl ass argumentisnot <strong>the</strong> sameas<strong>the</strong> class speci ed by<strong>the</strong> :metacl ass<br />
argument, an error is signal ed.<br />
O<strong>the</strong>rwise, <strong>the</strong>classmetaobj ect cl ass is redened bycalling<strong>the</strong> rei nitialize-instance<br />
generi c functi on with cl ass <strong>and</strong> <strong>the</strong>initializationarguments. <strong>The</strong> cl ass argument is<strong>the</strong>n<br />
returned.<br />
M<br />
ensure-cl ass-using-class ri mar et hod<br />
cl ass class<br />
name<br />
e me aclass<br />
irec s perclasses<br />
allo o er e s<br />
This methodimplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functionin<strong>the</strong>casewhere <strong>the</strong> cl ass<br />
argument is a class.<br />
This method can be overridden.
Generi c Functi ons <strong>and</strong>Methods ensure-generic-functi on 49<br />
ensure-cl ass-using-class ri mar et hod<br />
cl ass or ar re ere ce class<br />
name<br />
e<br />
me aclass<br />
irec s perclasses<br />
allo o er e s<br />
This methodimplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functionin<strong>the</strong>casewhere <strong>the</strong> cl ass<br />
argument isaforward referenced cl ass.<br />
ensure-cl ass-using-class ri mar et hod<br />
cl ass ll<br />
name<br />
e me aclass<br />
irec s perclasses<br />
allo o er e s<br />
This methodimplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functionin<strong>the</strong>casewhere <strong>the</strong> cl ass<br />
argument isnil.<br />
ensure eneric uncti on unct i on<br />
S<br />
ensure-generi c- f uncti on<br />
unct i on-name e allo o er e s<br />
A<br />
<strong>The</strong> unct i on-name argument isasymbol or a l i st <strong>of</strong> <strong>the</strong> f orm se s mbol .<br />
Some <strong>of</strong> <strong>the</strong> keyword arguments accepted bythis function are actually processed by<br />
ensure-generi c- f uncti on-using-class, o<strong>the</strong>rs are processed duringinitialization<strong>of</strong> <strong>the</strong><br />
generi c functi on metaobj ect (as descri bed i n <strong>the</strong> section called \Initialization<strong>of</strong> Generi c<br />
Functi on Metaobj ects").<br />
<strong>The</strong> result is ageneri c functi on metaobj ect.<br />
P<br />
This functionis calledto dene a gl oballynamed generi c functi on or to speci fy or modify<br />
options<strong>and</strong>decl arati ons that pertain to a globallynamed generi c functi on as a whol e. It<br />
can be calledby<strong>the</strong>user or <strong>the</strong>implementation.
50 ensure-generi c-functi on-using- cl ass Chapter 6<br />
It is <strong>the</strong> functi onal equival ent <strong>of</strong> def generi c, <strong>and</strong>is calledby<strong>the</strong> expansi on <strong>of</strong> <strong>the</strong><br />
def generi c <strong>and</strong> def method macros.<br />
<strong>The</strong> behavior <strong>of</strong> this functi on i s actuallyimplemented by<strong>the</strong>generi c functi on ensuregeneri<br />
c- f uncti on-using-class. When ensure-generic-functi onis called,itimmediately<br />
calls ensure-generic-functi on-using-class <strong>and</strong> returnsthat result as its own.<br />
<strong>The</strong> rst argument toensure-generi c- f uncti on-usi ng-class is computedas follows:<br />
If unct i on-name names a non-generi c functi on, a macro, or a speci al form, an error is<br />
signal ed.<br />
If<br />
unct i on-name names a generi c functi on, that generi c functi on metaobj ect i s used.<br />
O<strong>the</strong>rwise, nil is used.<br />
<strong>The</strong> secondargument is unct i on-name. <strong>The</strong> remai ningarguments are <strong>the</strong> complete set<br />
<strong>of</strong> keyword arguments recei ved by ensure-generic-functi on.<br />
ensure eneric uncti on usi n class eneri c unct i on<br />
S<br />
ensure-generi c- f uncti on-using-class<br />
generi c- unct i on<br />
unct i on-name<br />
e ar me prece e ce or er eclara io s<br />
oc me a io e eric c io class<br />
lam a lis me o class<br />
me o com i a io ame<br />
allo o er e s<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect or nil.<br />
<strong>The</strong> unct i on-name argument isasymbol or a l i st <strong>of</strong> <strong>the</strong> f orm se s mbol .<br />
<strong>The</strong> :generi c- f uncti on-class argument isaclassmetaobj ect or a cl ass name. If it is<br />
not supplied, it defaults to <strong>the</strong>classnamed st<strong>and</strong>ard-generi c- f uncti on. If a class name<br />
is supplied, it is interpreted as <strong>the</strong>classwiththat name. If a cl ass name issupplied, but<br />
<strong>the</strong>re i s nosuch class, an error is signal ed.<br />
For <strong>the</strong> interpretation <strong>of</strong> additional keyword arguments, see \Initialization<strong>of</strong> Generi c<br />
Functi on Metaobj ects" (page 61).<br />
<strong>The</strong> result is ageneri c functi on metaobj ect.
Generi c Functi ons <strong>and</strong>Methods ensure-generic-functi on-using- cl ass 51<br />
P<br />
<strong>The</strong> generi c functi on ensure-generi c- f uncti on-usi ng-class is calledto dene ormodify<br />
<strong>the</strong>denition <strong>of</strong> a globally named generi c functi on. It is called by<strong>the</strong> ensure-generi c-<br />
functi on functi on. I t can al so be calleddirectly.<br />
<strong>The</strong> rst step performed bythi s generi c functi on i s to compute <strong>the</strong>set<strong>of</strong>initialization<br />
arguments whichwill beusedtocreateor reinitialize <strong>the</strong>globallynamed generi c functi on.<br />
<strong>The</strong>se i nitializationarguments are computedfrom<strong>the</strong>fullset<strong>of</strong>keyword arguments recei ved<br />
by thi s generi c functionas follows:<br />
<strong>The</strong> :generi c- f uncti on-class argument isnot i ncl uded i n <strong>the</strong> initializationarguments.<br />
If <strong>the</strong> :method-class argument was recei ved by thi s generi c functi on, it is converted<br />
into a class metaobj ect. This is done bylookingup<strong>the</strong>classname withnd-class. If<br />
<strong>the</strong>re i s nosuch class, an error is signalled.<br />
Al l o<strong>the</strong>r keyword arguments are i ncl uded directlyin<strong>the</strong>initializationarguments.<br />
If <strong>the</strong> generi c- unct i on argumentisnil,aninstance <strong>of</strong> <strong>the</strong> class speci ed by<strong>the</strong> :generi c-<br />
functi on-class argument i s created by calling ma e- i nstance with <strong>the</strong>previously computedinitializationarguments.<br />
<strong>The</strong> functionname unct i on-name is set toname <strong>the</strong>generi c<br />
functi on. <strong>The</strong> newl y created generi c functi on metaobj ect i s returned.<br />
If <strong>the</strong> class <strong>of</strong> <strong>the</strong> generi c- unct i on argument isnot <strong>the</strong> sameas<strong>the</strong> class speci ed by<br />
<strong>the</strong> :generi c- f uncti on-class argument, an error is signal ed.<br />
O<strong>the</strong>rwise <strong>the</strong>generi c functi on generi c- unct i on is redened bycalling<strong>the</strong> rei nitializeinstance<br />
generi c functi on with generi c- unct i on <strong>and</strong> <strong>the</strong> initializationarguments. <strong>The</strong><br />
generi c- unct i on argument is<strong>the</strong>n returned.<br />
M<br />
ensure-generi c- f uncti on-using-class ri mar et hod<br />
generi c- unct i on e eric c io<br />
unct i on-name<br />
e e eric c io class<br />
allo o er e s<br />
This method i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functionin<strong>the</strong>casewhere unct i onname<br />
names an existinggeneri c functi on.<br />
This method can be overridden.
52 extract-lambda- l i st Chapter 6<br />
ensure-generi c- f uncti on-using-class ri mar et hod<br />
generi c- unct i on ll<br />
unct i on-name<br />
e e eric c io class<br />
allo o er e s<br />
This method i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functionin<strong>the</strong>casewhere unct i onname<br />
names n<strong>of</strong>uncti on, generi c functi on, macro or speci al form.<br />
e l s ecializer o ect unct i on<br />
S<br />
eql-speci alizer-object<br />
e l-s eci al i er<br />
A<br />
<strong>The</strong> e l-s eci al i er argument isaneql speci al i zer metaobj ect.<br />
<strong>The</strong> val ue returned bythis functi on i s an object.<br />
P<br />
This functi on returns <strong>the</strong> object associ ated with e l-s eci al i er duringinitialization. <strong>The</strong><br />
val ue isguaranteed to be eql to <strong>the</strong>val ue ori gi nallypassed to intern-eql-speci alizer,but<br />
it is not necessarily eq to that val ue.<br />
This functionsignals an error if e l-s eci al i er is not an eql speci al i zer.<br />
e tract la a list unct i on<br />
S<br />
e tract-l ambda-list<br />
s eci al i ed- l ambda- l i st<br />
A<br />
<strong>The</strong> s eci al i ed- l ambda- l i st argumentisaspeci al i zed l ambdal i st as acceptedby def method.<br />
<strong>The</strong> result is anunspeci al i zed l ambda list.
Generi c Functi ons <strong>and</strong>Methods extract-speci al i zer-names 53<br />
P<br />
This functi ontakes a speci al i zed l ambdalist<strong>and</strong>returns<strong>the</strong>lambdalist with<strong>the</strong>speci al i zers<br />
removed. This is anon-destructi ve operati on. Whe<strong>the</strong>r <strong>the</strong> result shares anystructure with<br />
<strong>the</strong>argument isunspeci ed.<br />
If <strong>the</strong> s eci al i ed- l ambda- l i st argument does not have l egal syntax, an error is signal ed.<br />
This syntax checkingdoes not check <strong>the</strong> syntax <strong>of</strong> <strong>the</strong>actual speci al i zer names, only <strong>the</strong><br />
syntax <strong>of</strong> <strong>the</strong>lambdalist <strong>and</strong>where <strong>the</strong> speci al i zers appear.<br />
E<br />
ex rac lam a lis p posi io<br />
ex rac lam a lis p posi io x<br />
ex rac lam a lis a e l x c res i<br />
e tract s ecializer na es unct i on<br />
S<br />
e tract-speci alizer-names<br />
s eci al i ed- l ambda- l i st<br />
A<br />
<strong>The</strong> s eci al i ed- l ambda- l i st argumentisaspeci al i zed l ambdal i st as acceptedby def method.<br />
<strong>The</strong> result is alist <strong>of</strong> speci al i zer names.<br />
P<br />
This functiontakes a speci al i zed l ambdalist <strong>and</strong>returns its speci al i zer names. This is anondestructi<br />
veoperati on. Whe<strong>the</strong>r <strong>the</strong>result shares structure with<strong>the</strong>argumentisunspeci ed.<br />
<strong>The</strong> results are undened i f <strong>the</strong> result <strong>of</strong> this functi on i s modied.<br />
<strong>The</strong> result <strong>of</strong> this functi on will be alist withanumber <strong>of</strong> el ements equal to <strong>the</strong>number<br />
<strong>of</strong> requi red arguments in s eci al i ed- l ambda- l i st . Speci al i zers are defaulted to <strong>the</strong>symbol t.<br />
If <strong>the</strong> s eci al i ed- l ambda- l i st argument does not have l egal syntax, an error is signal ed.<br />
This syntax checkingdoes not check <strong>the</strong> syntax <strong>of</strong> <strong>the</strong>actual speci al i zer names, only <strong>the</strong><br />
syntax <strong>of</strong> <strong>the</strong>lambdalist <strong>and</strong>where <strong>the</strong> speci al i zers appear.<br />
E<br />
ex rac speciali er ames p posi io<br />
ex rac speciali er ames p posi io x<br />
ex rac speciali er ames a e l x c res i
54 nd-method-combinati on Chapter 6<br />
nalize in eritance eneri c unct i on<br />
S<br />
nalize-inheri tance<br />
cl ass<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s unspeci ed.<br />
P<br />
Thi s generi c functionis calledtonalizeaclass metaobj ect. This is descri bedin<strong>the</strong>Secti on<br />
named \Class Finalization<strong>Protocol</strong>."<br />
After nalize-inheri tance returns, <strong>the</strong>classmetaobj ect i s nal i zed <strong>and</strong><strong>the</strong>result <strong>of</strong><br />
calling cl ass-nalized-pon <strong>the</strong> classmetaobj ect will be true.<br />
M<br />
nalize-inheri tance ri mar et hod<br />
cl ass s a ar class<br />
nalize-inheri tance ri mar et hod<br />
cl ass calla le s a ar class<br />
obehavior is speci ed for <strong>the</strong>se methods beyondthat whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
nalize-inheri tance ri mar et hod<br />
cl ass or ar re ere ce class<br />
This method si gnals an error.<br />
n et o co inati on eneri c unct i on<br />
S<br />
nd-method-combinati on<br />
generi c- unct i on<br />
met hod- combi nat i on-t e-name<br />
met hod- combi nat i on-o tions<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.
Generi c Functi ons <strong>and</strong>Methods funcallable-st<strong>and</strong>ard-instance-access 55<br />
<strong>The</strong> met hod- combi nat i on-t e-name argumentisasymbol whichnames a type <strong>of</strong>method<br />
combinati on.<br />
<strong>The</strong> met hod- combi nat i on-o tions argument is alist <strong>of</strong> arguments to <strong>the</strong>method combinati<br />
on type.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s a method combinati on metaobj ect.<br />
P<br />
Thi s generi c functionis calledtodetermine<strong>the</strong>method combinati on obj ect usedby a generi c<br />
functi on.<br />
R<br />
Fur<strong>the</strong>r detai l s <strong>of</strong> method combinati on metaobj ects are not speci ed.<br />
uncalla le stan ar instance access unct i on<br />
S<br />
funcallable-st<strong>and</strong>ard-instance-access<br />
instance l ocation<br />
A<br />
<strong>The</strong> instance argument i s an obj ect.<br />
<strong>The</strong> locat i on argument is a slot location.<br />
<strong>The</strong> result <strong>of</strong> this functi on i s an object.<br />
P<br />
This functionis calledto providedi rect access to a sl ot i n an i nstance. By usurping<strong>the</strong><br />
normal sl ot l ookupprotocol, this functi on i s i ntended to providehighlyoptimi zed access to<br />
<strong>the</strong> slots associated withaninstance.<br />
<strong>The</strong> following restrictionsapply to <strong>the</strong>use <strong>of</strong> this functi on:<br />
<strong>The</strong> instance argument must beafuncallable instance (i t must have been returned by<br />
allocate-instance (f uncallable-st<strong>and</strong>ard-class)).<br />
<strong>The</strong> instance argument cannot be annon-updated obsolete instance.<br />
<strong>The</strong> locat i on argument must be a l ocati on <strong>of</strong> one <strong>of</strong><strong>the</strong>di rectl y accessi bl e sl ots <strong>of</strong> <strong>the</strong><br />
instance' s cl ass.<br />
<strong>The</strong> slotmust bebound.<br />
<strong>The</strong> results are undened i f any<strong>of</strong> <strong>the</strong>se restrictionsarenot met.
56 generi c-functi on- ::: Chapter 6<br />
eneric uncti on eneri c unct i on<br />
<strong>The</strong> followinggeneri c functi ons are descri bed toge<strong>the</strong>r under \Readers f or Generi c Functi<br />
on Metaobj ects" (page 79): generi c- f uncti on-argument-precedence-order, generi c-<br />
functi on-decl arati ons, generi c- f uncti on-lambda-list, generi c- f uncti on-methodcl<br />
ass, generi c- f uncti on-method-combination, generi c- f uncti on-methods <strong>and</strong> generi c-<br />
functi on-name.
Generi c Functi ons <strong>and</strong>Methods Initialization<strong>of</strong> Class Metaobj ects 57<br />
nitializati on o lass etao ects<br />
Aclass metaobj ect can be created by calling ma e- i nstance. <strong>The</strong> initializationarguments<br />
establish<strong>the</strong>denition<strong>of</strong> <strong>the</strong> class. Aclass metaobj ect can be redened bycalling<br />
rei nitialize-instance. Some classes <strong>of</strong> class metaobj ect do not support redenition; in<br />
<strong>the</strong>se cases, rei nitialize-instance signals an error.<br />
Initialization<strong>of</strong> aclass metaobj ect must bedone bycalling ma e- i nstance <strong>and</strong>allowing<br />
it tocall initialize-instance. Rei nitialization<strong>of</strong> aclass metaobj ect must bedone bycalling<br />
rei nitialize-instance. Portable programs must not cal l initialize-instance directly to<br />
initialize a class metaobj ect. Portable programs must not cal l shared-initialize directly<br />
to initialize or reinitialize a class metaobj ect. Portable programs must not cal l changecl<br />
ass to change <strong>the</strong> cl ass <strong>of</strong> any class metaobj ect or to turn a non-class object into a class<br />
metaobj ect.<br />
Since metaobj ect cl asses may not be redened, nobehavior is speci ed for <strong>the</strong> result<br />
<strong>of</strong> calls to update-instance-f or-redened-class on cl ass metaobj ects. Since <strong>the</strong> class<strong>of</strong><br />
cl ass metaobj ects may not be changed, nobehavior is speci ed for <strong>the</strong> result <strong>of</strong> calls to<br />
update-instance-f or-di erent-cl ass on cl ass metaobj ects.<br />
Duringinitializationor reinitialization, each i nitializationargumentischeckedfor errors<br />
<strong>and</strong> <strong>the</strong>n associ ated with<strong>the</strong>classmetaobj ect. <strong>The</strong> val ue can<strong>the</strong>n be accessed bycalling<br />
<strong>the</strong>appropriate accessor as shown inTabl e 6. 1.<br />
This section begi ns with a descri pti on <strong>of</strong> <strong>the</strong> error checking<strong>and</strong>processing <strong>of</strong> each<br />
initializationargument. This is followed byatable showing<strong>the</strong>generi c functi ons that can<br />
be used to access <strong>the</strong> stored initialization arguments. Initialization behavior speci c to<br />
<strong>the</strong>dierent speci ed cl ass metaobj ect cl asses comes next. <strong>The</strong> secti on ends witha set <strong>of</strong><br />
restrictionsonportablemethods aecti ngclass metaobj ect i nitialization<strong>and</strong>reinitialization.<br />
In <strong>the</strong>se descri ptions, <strong>the</strong> phrase \thi s argument defaults to al ue" means that when<br />
that i nitializationargument isnot supplied, initializationor reinitializationis performed as<br />
if al ue had been supplied. For some initializationarguments this couldbedone by<strong>the</strong>use<br />
<strong>of</strong> default initializationarguments, but whe<strong>the</strong>r it is done this way is not speci ed. Implementations<br />
are free to dene default initializationarguments for speci ed cl ass metaobj ect<br />
classes. Portable programs are free to dene default initializationarguments for portable<br />
subclasses<strong>of</strong><strong>the</strong>classcl ass.<br />
Unless <strong>the</strong>reisaspeci c note to <strong>the</strong> contrary, <strong>the</strong>n duringreinitialization, if an initializationargument<br />
isnot supplied, <strong>the</strong>previously stored val ue isleftunchanged.<br />
<strong>The</strong> :di rect- def ault-initargs argument is a list <strong>of</strong> canonicalizeddefault initialization<br />
arguments.<br />
An error is signal ed i f this val ue isnot a proper list, or if anyelement <strong>of</strong><strong>the</strong> list is not<br />
acanonicalizeddefault initializationargument.<br />
If <strong>the</strong>classmetaobj ect i s bei nginitialized, thi s argument defaults to<strong>the</strong>emptylist.
58 Initialization<strong>of</strong> Class Metaobj ects Chapter 6<br />
<strong>The</strong> :direct-slots argument isalist<strong>of</strong>canonicalizedslot speci cati ons.<br />
An errorissignal ed i f this val ue isnot a properlistorifanyelement <strong>of</strong><strong>the</strong> list is not a<br />
canonicalizedslot speci cati on.<br />
After error checking, this val ue isconverted to a list <strong>of</strong> di rect sl ot denition metaobjects<br />
before i t i s associ ated with<strong>the</strong>classmetaobj ect. Conversi on <strong>of</strong> each canonicalized<br />
slot speci cation to a di rect sl ot denitionmetaobj ect i s a two-step process. First, <strong>the</strong><br />
generi c functi on direct-slot-denition-class is called with <strong>the</strong>classmetaobj ect <strong>and</strong><br />
<strong>the</strong>canonicalizedslot speci cationto determine<strong>the</strong> class <strong>of</strong> <strong>the</strong>newdi rect sl ot denition<br />
metaobj ect; this permits both <strong>the</strong> classmetaobj ect <strong>and</strong> <strong>the</strong>canonicalizedslot speci -<br />
cation to control <strong>the</strong>resultingdi rect sl ot denition metaobj ect cl ass. Second, ma e-<br />
instance is appliedto <strong>the</strong>di rect sl ot denitionmetaobj ect cl ass <strong>and</strong> <strong>the</strong>canonicalized<br />
slot speci cati on. This conversioncouldbeimplementedas shownin<strong>the</strong> followingcode:<br />
e co er o irec slo e i i io class ca o icali e slo<br />
appl ma e i s a ce<br />
appl irec slo e i i io class<br />
class ca o icali e slo<br />
ca o icali e slo<br />
If <strong>the</strong>classmetaobj ect i s bei nginitialized, thi s argument defaults to<strong>the</strong>emptylist.<br />
Once <strong>the</strong> di rect sl ot denitionmetaobj ects have been created, <strong>the</strong>speci ed reader <strong>and</strong><br />
writer methods are created. <strong>The</strong> generi c functi ons reader- method-class <strong>and</strong> wri termethod-class<br />
are cal l ed to determine<strong>the</strong> classes <strong>of</strong> <strong>the</strong>method metaobj ects created.<br />
<strong>The</strong> :direct-supercl asses argument is alist <strong>of</strong> class metaobj ects. Classes whichdonot<br />
support multiple inheri tance si gnal an error i f <strong>the</strong> list containsmore than one element.<br />
An error is signal ed i f this val ue isnot a proper list or if validate-supercl ass applied<br />
to cl ass <strong>and</strong> anyelement <strong>of</strong>this list returns f al se.<br />
When <strong>the</strong> classmetaobj ect i s bei nginitialized,<strong>and</strong>thi s argument isei<strong>the</strong>r not supplied<br />
or i s <strong>the</strong> empty list, thi s argument defaults as follows: if <strong>the</strong> class is an instance <strong>of</strong><br />
st<strong>and</strong>ard-class or one <strong>of</strong> its subclasses <strong>the</strong>default val ueis alist <strong>of</strong> <strong>the</strong>classst<strong>and</strong>ardobject;if<strong>the</strong>class<br />
is aninstance <strong>of</strong> funcallable-st<strong>and</strong>ard-class or one <strong>of</strong> its subclasses<br />
<strong>the</strong>default val ue is list <strong>of</strong> <strong>the</strong>classfuncallable-st<strong>and</strong>ard-object.<br />
After anydefaulting<strong>of</strong> <strong>the</strong>val ue, <strong>the</strong> generi c functi on add-direct-subcl ass is called<br />
once f or each el ement <strong>of</strong><strong>the</strong> list.<br />
When <strong>the</strong> class metaobj ect i s bei ng reinitialized <strong>and</strong>thi s argument is supplied, <strong>the</strong><br />
generi c functi on remove-direct-subcl ass is called once f or each cl ass metaobj ect i n<br />
<strong>the</strong>previously stored val ue but not i n <strong>the</strong> newval ue; <strong>the</strong> generi c functi on add-directsubcl<br />
ass is calledonce f or each cl ass metaobj ect i n <strong>the</strong> newval ue but not i n <strong>the</strong> previously<br />
stored val ue.
Generi c Functi ons <strong>and</strong>Methods Initialization<strong>of</strong> Class Metaobj ects 59<br />
<strong>The</strong> :documentati on argument is a stringornil.<br />
An error is signal ed i f this val ue isnot a stringornil.<br />
If <strong>the</strong>classmetaobj ect i s bei nginitialized, thi s argument defaults tonil.<br />
<strong>The</strong> :name argument i s an obj ect.<br />
If <strong>the</strong> class is bei nginitialized,thi s argument defaults tonil.<br />
After <strong>the</strong>processing<strong>and</strong>defaulting<strong>of</strong> initializationarguments descri bed above, <strong>the</strong>val ue<br />
<strong>of</strong> each i nitializationargument i s associ ated with <strong>the</strong>classmetaobj ect. <strong>The</strong>se val ues can<br />
<strong>the</strong>n be accessed bycalling<strong>the</strong> correspondinggeneri c functi on. <strong>The</strong> correspondences are as<br />
follows:<br />
nitialization rgument Generi c Functi on<br />
:di rect- def ault-initargs<br />
:direct-slots<br />
:direct-supercl asses<br />
:documentation<br />
:name<br />
cl ass-di rect- default-initargs<br />
cl ass-direct-slots<br />
cl ass-direct-supercl asses<br />
documentati on<br />
cl ass-name<br />
a e .1 r r r .<br />
Instances <strong>of</strong> <strong>the</strong> classst<strong>and</strong>ard-class support multiple inheri tance <strong>and</strong>reinitialization.<br />
Instances <strong>of</strong> <strong>the</strong> classfuncallable-st<strong>and</strong>ard-class support multiple inheri tance <strong>and</strong>reinitialization.<br />
For f orward referenced cl asses, al l <strong>of</strong> <strong>the</strong> initialization arguments default to<br />
nil.<br />
Since built-inclasses cannot be created or rei nitializedby<strong>the</strong>user, anerror is signal ed i f<br />
initialize-instance or rei nitialize-instance are calledtoinitializeor reinitializeaderi ved<br />
instance <strong>of</strong> <strong>the</strong> classbuilt-in-class.<br />
M<br />
It is not speci ed which methods provide <strong>the</strong> initialization <strong>and</strong>reinitialization behavior<br />
descri bed above. Instead, <strong>the</strong>informati on needed to allowportable programs tospeci al i ze<br />
this behavior is presented as a set <strong>of</strong> restrictions on <strong>the</strong>methods aportable programcan<br />
dene. <strong>The</strong> model i s that portableinitializationmethods have access to <strong>the</strong>classmetaobj ect<br />
when ei <strong>the</strong>r al l or none <strong>of</strong><strong>the</strong>speci ed i nitializationhas taken eect.<br />
<strong>The</strong>se restrictions govern<strong>the</strong>methods that a portable programcan dene on<strong>the</strong>generi c<br />
functi ons initialize-instance, rei nitialize-instance, <strong>and</strong> shared-initialize. <strong>The</strong>se restrictions<br />
apply only to methods on<strong>the</strong>se generi c functi ons f or which<strong>the</strong>rst speci al i zer<br />
is asubcl ass <strong>of</strong> <strong>the</strong> classcl ass. O<strong>the</strong>r portable methods on<strong>the</strong>se generi c functi ons arenot<br />
aected by<strong>the</strong>se restrictions.
60 Initialization<strong>of</strong> Class Metaobj ects Chapter 6<br />
Portable programs must not dene methods onshared-initialize.<br />
For initialize-instance <strong>and</strong> rei nitialize-instance:<br />
Portable programs must not dene primary methods.<br />
Portable programs may dene around-methods, but <strong>the</strong>se must beextending, not<br />
overridingmethods.<br />
Portablebefore-methods must assume that when <strong>the</strong>y are run, none <strong>of</strong><strong>the</strong>initializati<br />
on behavior descri bed above has been completed.<br />
Portable after-methods must assume that when <strong>the</strong>y are run, all <strong>of</strong> <strong>the</strong>initialization<br />
behavior descri bed above has been completed.<br />
<strong>The</strong> results are undened i f any<strong>of</strong> <strong>the</strong>se restrictionsareviolated.
Generi c Functi ons <strong>and</strong>Methods Initialization<strong>of</strong> Generi c Functi on Metaobj ects 61<br />
nitializati on o eneric uncti on etao ects<br />
Ageneri c functi on metaobj ect can be created bycalling ma e- i nstance. <strong>The</strong> initialization<br />
arguments establish<strong>the</strong>denition<strong>of</strong> <strong>the</strong>generi c functi on. Ageneri c functi onmetaobj ect can<br />
be redened bycalling rei nitialize-instance. Some classes <strong>of</strong> generi c functi on metaobj ect<br />
do not support redenition; in <strong>the</strong>se cases, rei nitialize-instance signals an error.<br />
Initialization<strong>of</strong> ageneri c functi on metaobj ect must bedone bycalling ma e- i nstance<br />
<strong>and</strong>allowing i t to cal l initialize-instance. Rei nitialization <strong>of</strong> a generi c-functionmetaobj ect<br />
must bedone bycalling rei nitialize-instance. Portableprograms must not cal l initializeinstance<br />
directlyto initialize a generi c functi on metaobj ect. Portable programs must not<br />
cal l shared-initialize directly to initialize or reinitialize a generi c functi on metaobj ect.<br />
Portable programs must not cal l change- cl ass to change <strong>the</strong> cl ass <strong>of</strong> any generi c functi on<br />
metaobj ect or to turnanon-generi c-functi on object i nto a generi c functi on metaobj ect.<br />
Since metaobj ect cl asses may not be redened, nobehavior is speci ed for <strong>the</strong> result <strong>of</strong><br />
calls toupdate-instance-f or-redened-class on generi c functi on metaobj ects. Since <strong>the</strong><br />
cl ass <strong>of</strong> a generi c functi on metaobj ect may not be changed, nobehavior is speci ed for <strong>the</strong><br />
results <strong>of</strong> calls toupdate-instance-for-di erent-class on generi c functi on metaobj ects.<br />
Duringinitializationor reinitialization, each i nitializationargumentischeckedfor errors<br />
<strong>and</strong> <strong>the</strong>n associ ated with<strong>the</strong>generi c functi on metaobj ect. <strong>The</strong> val ue can<strong>the</strong>n be accessed<br />
bycalling<strong>the</strong>appropriate accessor as shown inTabl e 6. 2.<br />
This section begi ns with a descri pti on <strong>of</strong> <strong>the</strong> error checking<strong>and</strong>processing <strong>of</strong> each<br />
initialization argument. This is followed by atable showing<strong>the</strong> generi c functi ons that<br />
can be used to access <strong>the</strong> stored initializationarguments. <strong>The</strong> secti on ends with a set <strong>of</strong><br />
restrictions on portable methods aecti ng generi c functi on metaobj ect i nitialization <strong>and</strong><br />
reinitialization.<br />
In <strong>the</strong>se descri ptions, <strong>the</strong> phrase \thi s argument defaults to al ue" means that when<br />
that i nitializationargument isnot supplied, initializationor reinitializationis performed as<br />
if al ue had been supplied. For some initializationarguments this couldbedone by<strong>the</strong>use<br />
<strong>of</strong> default initializationarguments, but whe<strong>the</strong>r it is done this way is not speci ed. Implementations<br />
are free to dene default initializationarguments for speci ed generi c functi on<br />
metaobj ect cl asses. Portableprograms are free to dene default initializationarguments for<br />
portable subclasses<strong>of</strong><strong>the</strong>classgeneri c- f uncti on.<br />
Unless <strong>the</strong>reisaspeci c note to <strong>the</strong> contrary, <strong>the</strong>n duringreinitialization, if an initializationargument<br />
isnot supplied, <strong>the</strong>previously stored val ue isleftunchanged.<br />
<strong>The</strong> :argument-precedence-order argument isalist<strong>of</strong>symbol s.<br />
An error is signal ed i f thi s argument appears but <strong>the</strong> :lambda-list argument does not<br />
appear. An error is signal ed i f this val ue isnot a proper list or if this val ue isnot<br />
apermutation <strong>of</strong> <strong>the</strong> symbol s f rom<strong>the</strong> requi red arguments part <strong>of</strong> <strong>the</strong> :lambda-list<br />
initializationargument.
62 Initialization<strong>of</strong> Generi c Functi on Metaobj ects Chapter 6<br />
When <strong>the</strong> generi c functi on i s bei nginitializedor reinitialized, <strong>and</strong>thi s argument isnot<br />
supplied, but <strong>the</strong> :lambda-list argument issupplied, this val ue defaults to<strong>the</strong>symbol s<br />
from<strong>the</strong> requi red arguments part <strong>of</strong> <strong>the</strong> :lambda-list argument, in <strong>the</strong> order <strong>the</strong>y<br />
appear i n that argument. If nei <strong>the</strong>r argument issupplied,nei <strong>the</strong>r are i nitialized(see <strong>the</strong><br />
descri pti on <strong>of</strong> :lambda-list.)<br />
<strong>The</strong> :decl arations argument is alist <strong>of</strong> decl arati ons.<br />
An error is signal ed i f this val ue isnot a proper l i st or i f each <strong>of</strong> i ts el ements is not a<br />
l egal decl arati on.<br />
When <strong>the</strong> generi c functi on i s bei ng initialized, <strong>and</strong>thi s argument is not supplied, it<br />
defaults to<strong>the</strong>empty list.<br />
<strong>The</strong> :documentati on argument is a stringornil.<br />
An error is signal ed i f this val ue isnot a stringornil.<br />
If <strong>the</strong>generi c functi on i s bei nginitialized,thi s argument defaults tonil.<br />
<strong>The</strong> :lambda-list argument isalambda list.<br />
An error is signal ed i f this val ue isnot a proper generi c functi on l ambda list.<br />
When <strong>the</strong> generi c functi on i s bei ng initialized, <strong>and</strong>thi s argument isnot supplied, <strong>the</strong><br />
generi c functi on's lambda listisnot i nitialized. <strong>The</strong> lambdalist will beinitializedlater,<br />
ei <strong>the</strong>r when <strong>the</strong> rst method i s added to <strong>the</strong>generi c functi on, or a later reinitialization<br />
<strong>of</strong> <strong>the</strong> generi c functi on.<br />
<strong>The</strong> :method-combination argument isamethod combinati on metaobj ect.<br />
<strong>The</strong> :method-class argument isaclassmetaobj ect.<br />
An error is signal ed i f this val ue isnot a subcl ass <strong>of</strong> <strong>the</strong> classmethod.<br />
When <strong>the</strong> generi c functi on i s bei ng initialized, <strong>and</strong>thi s argument is not supplied, it<br />
defaults to<strong>the</strong>classst<strong>and</strong>ard-method.<br />
<strong>The</strong> :name argument i s an obj ect.<br />
If <strong>the</strong>generi c functi on i s bei nginitialized,thi s argument defaults tonil.<br />
After <strong>the</strong> processing <strong>and</strong>defaulting<strong>of</strong> initializationarguments descri bed above, <strong>the</strong><br />
val ue <strong>of</strong> each i nitializationargument i s associ ated with <strong>the</strong> generi c functi on metaobj ect.<br />
<strong>The</strong>se val ues can <strong>the</strong>n be accessed by calling<strong>the</strong> correspondinggeneri c functi on. <strong>The</strong><br />
correspondences are as follows:
Generi c Functi ons <strong>and</strong>Methods Initialization<strong>of</strong> Generi c Functi on Metaobj ects 63<br />
nitialization rgument Generi c Functi on<br />
:argument-precedence-order<br />
:decl arations<br />
:documentation<br />
:lambda-list<br />
:method-combination<br />
:method-class<br />
:name<br />
generi c- f uncti on-argument-precedence-order<br />
generi c- f uncti on-decl arations<br />
documentation<br />
generi c- f uncti on-lambda-list<br />
generi c- f uncti on-method-combinati on<br />
generi c- f uncti on-method-class<br />
generi c- f uncti on-name<br />
a e . r r r r .<br />
M<br />
It is not speci ed which methods provide <strong>the</strong> initialization <strong>and</strong>reinitialization behavior<br />
descri bed above. Instead, <strong>the</strong>informati on needed to allowportable programs tospeci al i ze<br />
this behavior is presented as a set <strong>of</strong> restrictions on <strong>the</strong>methods aportable programcan<br />
dene. <strong>The</strong> model i s that portable initializationmethods have access to <strong>the</strong>generi c functi on<br />
metaobj ect when ei <strong>the</strong>r al l or none <strong>of</strong><strong>the</strong>speci ed i nitializationhas taken eect.<br />
<strong>The</strong>se restrictions govern<strong>the</strong>methods that a portable programcan dene on<strong>the</strong>generi c<br />
functi ons initialize-instance, rei nitialize-instance, <strong>and</strong> shared-initialize. <strong>The</strong>se restrictions<br />
apply only to methods on<strong>the</strong>se generi c functi ons f or which<strong>the</strong>rst speci al i zer<br />
is a subcl ass <strong>of</strong> <strong>the</strong> class generi c- f uncti on. O<strong>the</strong>r portable methods on <strong>the</strong>se generi c<br />
functi ons arenot aected by<strong>the</strong>se restrictions.<br />
Portable programs must not dene methods onshared-initialize.<br />
For initialize-instance <strong>and</strong> rei nitialize-instance:<br />
Portable programs must not dene primary methods.<br />
Portable programs may dene around-methods, but <strong>the</strong>se must beextending, not<br />
overridingmethods.<br />
Portablebefore-methods must assume that when <strong>the</strong>y are run, none <strong>of</strong><strong>the</strong>initializati<br />
on behavior descri bed above has been completed.<br />
Portable after-methods must assume that when <strong>the</strong>y are run, all <strong>of</strong> <strong>the</strong>initialization<br />
behavior descri bed above has been completed.<br />
<strong>The</strong> results are undened i f any<strong>of</strong> <strong>the</strong>se restrictionsareviolated.
64 Initialization<strong>of</strong> Method Metaobj ects Chapter 6<br />
nitializati on o et o etao ects<br />
Amethod metaobj ect can be created bycalling ma e- i nstance. <strong>The</strong> initializationarguments<br />
establish <strong>the</strong>denition<strong>of</strong> <strong>the</strong>method. Amethod metaobj ect cannot be redened;<br />
calling rei nitialize-instance signals an error.<br />
Initialization<strong>of</strong> amethod metaobj ect must bedone bycalling ma e- i nstance <strong>and</strong>allowingit<br />
tocall initialize-instance. Portable programs must not cal l initialize-instance directlytoinitialize<br />
amethod metaoject. Portable programs must not cal l shared-initialize<br />
directlytoinitialize amethod metaobj ect. Portable programs must not cal l change- cl ass<br />
to change <strong>the</strong> cl ass <strong>of</strong> anymethod metaobj ect or to turna non-method obj ect i ntoa method<br />
metaobj ect.<br />
Since metaobj ect cl asses may not be redened, nobehavior is speci ed for <strong>the</strong> result <strong>of</strong><br />
calls toupdate-instance-f or-redened-class on method metaobj ects. Since <strong>the</strong> class<strong>of</strong><br />
amethod metaobj ect cannot be changed, nobehavior is speci ed for <strong>the</strong> result <strong>of</strong> calls to<br />
update-instance-f or-di erent-cl ass on method metaobj ects.<br />
Duringinitialization, each i nitializationargument ischecked for errors <strong>and</strong><strong>the</strong>n associ -<br />
ated with<strong>the</strong>method metaobj ect. <strong>The</strong> val ue can<strong>the</strong>n be accessed bycalling<strong>the</strong>appropri ate<br />
accessor as shown inTabl e 6. 3.<br />
This section begi ns with a descri pti on <strong>of</strong> <strong>the</strong> error checking<strong>and</strong>processing <strong>of</strong> each<br />
initialization argument. This is followed by atable showing<strong>the</strong> generi c functi ons that<br />
can be used to access <strong>the</strong> stored initializationarguments. <strong>The</strong> secti on ends with a set <strong>of</strong><br />
restrictionsonportable methods aecti ngmethod metaobj ect i nitialization.<br />
In <strong>the</strong>se descri ptions, <strong>the</strong> phrase \thi s argument defaults to al ue" means that when<br />
that i nitializationargument isnot supplied, initializationis performed as i f al ue had been<br />
supplied. For some initializationarguments this couldbedone by<strong>the</strong>use <strong>of</strong> default initializationarguments,<br />
but whe<strong>the</strong>r it is done this wayis not speci ed. Implementationsarefree<br />
to dene default initializationarguments for speci ed method metaobj ect cl asses. Portable<br />
programs are free to dene default initializationarguments for portable subclasses <strong>of</strong> <strong>the</strong><br />
cl ass method.<br />
<strong>The</strong> :qualiers argument is alist <strong>of</strong> method qualiers. Anerror is signal ed i f this val ue<br />
is not a proper list, or if anyelement <strong>of</strong><strong>the</strong>listisnot a non-nul l atom. Thi s argument<br />
defaults to<strong>the</strong>empty list.<br />
<strong>The</strong> :lambda-list argument is<strong>the</strong>unspeci al i zed l ambdalist <strong>of</strong> <strong>the</strong>method. An error is<br />
signal ed i f this val ue isnot a proper l ambda list. If this val ue isnot supplied, an error<br />
is signal ed.<br />
<strong>The</strong> :speci alizers argument isalist<strong>of</strong><strong>the</strong>speci al i zer metaobj ects f or <strong>the</strong> method. An<br />
error is signal ed i f this val ue isnot a proper list, or if <strong>the</strong>length <strong>of</strong> <strong>the</strong> list diers from<br />
<strong>the</strong>number <strong>of</strong> requi red arguments in <strong>the</strong> :lambda-list argument, or i f any element <strong>of</strong><br />
<strong>the</strong> list is not a speci al i zer metaobj ect. I f this val ue isnot supplied, an error is signal ed.
Generi c Functi ons <strong>and</strong>Methods Initialization<strong>of</strong> Method Metaobj ects 65<br />
<strong>The</strong> :functi onargumentisamethod f uncti on. It must becompati blewith<strong>the</strong>methods<br />
on compute-e ecti ve- method dened for this class <strong>of</strong> method <strong>and</strong> generi c functi on<br />
withwhichit will beused. That i s, i t must accept <strong>the</strong>samenumber <strong>of</strong> arguments as<br />
al l uses <strong>of</strong> call-method that will call it supply. (See compute-e ecti ve- method for<br />
more i nformati on.) An error is signal ed i f thi s argument isnot supplied.<br />
When <strong>the</strong> method bei nginitializedis aninstance <strong>of</strong> a subcl ass <strong>of</strong> st<strong>and</strong>ard-accessormethod,<br />
<strong>the</strong> :slot-denitioninitializationargumentmust beprovided. Its val ue is<strong>the</strong><br />
di rect sl ot denitionmetaobj ect whichdenes thi s accessor method. Anerror is signal ed<br />
if <strong>the</strong>val ue isnot an i nstance <strong>of</strong> a subcl ass <strong>of</strong> direct-slot-denition.<br />
<strong>The</strong> :documentation argument is a stringor nil. An error is signal ed i f this val ue is<br />
not a stringornil. Thi s argument defaults tonil.<br />
After <strong>the</strong>processing<strong>and</strong>defaulting<strong>of</strong> initializationarguments descri bed above, <strong>the</strong>val ue<br />
<strong>of</strong> each i nitializationargument i s associ ated with<strong>the</strong>method metaobj ect. <strong>The</strong>se val ues can<br />
<strong>the</strong>n be accessed bycalling<strong>the</strong> correspondinggeneri c functi on. <strong>The</strong> correspondences are as<br />
follows:<br />
nitialization rgument Generi c Functi on<br />
:qualiers<br />
:lambda-list<br />
:speci alizers<br />
:functi on<br />
:slot-denition<br />
:documentation<br />
method-qualiers<br />
method-lambda-list<br />
method-speci alizers<br />
method-functi on<br />
accessor-method-slot-denition<br />
documentati on<br />
a e . r r r .<br />
M<br />
It is not speci ed whichmethods provide<strong>the</strong>initializationbehavior descri bed above. Instead,<br />
<strong>the</strong> informati on needed to allowportable programs to speci al i ze this behavior is<br />
presented in as a set <strong>of</strong> restrictions on <strong>the</strong>methods a portable programcan dene. <strong>The</strong><br />
model i s that portable initializationmethods have access to <strong>the</strong> method metaobj ect when<br />
ei <strong>the</strong>r al l or none <strong>of</strong><strong>the</strong>speci ed i nitializationhas taken eect.<br />
<strong>The</strong>se restrictions govern<strong>the</strong>methods that a portable programcan dene on<strong>the</strong>generi c<br />
functi ons initialize-instance, rei nitialize-instance, <strong>and</strong> shared-initialize. <strong>The</strong>se restrictionsapplyonlytomethods<br />
on<strong>the</strong>se generi c functi ons f or which<strong>the</strong>rst speci al i zer i s<br />
asubcl ass <strong>of</strong> <strong>the</strong> classmethod. O<strong>the</strong>r portable methods on<strong>the</strong>se generi c functi ons arenot<br />
aected by<strong>the</strong>se restrictions.
66 Initialization<strong>of</strong> Method Metaobj ects Chapter 6<br />
Portable programs must not dene methods on shared-initialize or rei nitializeinstance.<br />
For initialize-instance:<br />
Portable programs must not dene primary methods.<br />
Portable programs may dene around-methods, but <strong>the</strong>se must beextending, not<br />
overridingmethods.<br />
Portablebefore-methods must assume that when <strong>the</strong>y are run, none <strong>of</strong><strong>the</strong>initializati<br />
on behavior descri bed above has been completed.<br />
Portable after-methods must assume that when <strong>the</strong>y are run, all <strong>of</strong> <strong>the</strong>initialization<br />
behavior descri bed above has been completed.<br />
<strong>The</strong> results are undened i f any<strong>of</strong> <strong>the</strong>se restrictionsareviolated.
Generi c Functi ons <strong>and</strong>Methods Initialization<strong>of</strong> Slot DenitionMetaobj ects 67<br />
nitializati on o Slot e nition etao ects<br />
Aslot denitionmetaobj ect can be created bycalling ma e- i nstance. <strong>The</strong> initialization<br />
arguments establish<strong>the</strong>denition<strong>of</strong> <strong>the</strong>slotdenition. Asl ot denitionmetaobj ect cannot<br />
be redened; calling rei nitialize-instance signals an error.<br />
Initialization<strong>of</strong> a slot denition metaobj ect must bedone by calling ma e- i nstance<br />
<strong>and</strong> allowing i t to cal l initialize-instance. Portable programs must not cal l initializeinstance<br />
directly to initialize a slot denition metaobj ect. Portable programs must not<br />
cal l shared-initializedirectlytoinitialize aslot denitionmetaobj ect. Portable programs<br />
must not cal l change-class to change <strong>the</strong> cl ass <strong>of</strong> any slot denitionmetaobj ect or to turn<br />
anon-slot-denitionobject into a slot denitionmetaobj ect.<br />
Since metaobj ect cl asses may not be redened, nobehavior is speci ed for <strong>the</strong> result<br />
<strong>of</strong> calls toupdate-instance-f or-redened-class on sl ot denitionmetaobj ects. Since <strong>the</strong><br />
cl ass <strong>of</strong> a sl ot denitionmetaobj ect cannot be changed, nobehavioris speci ed for <strong>the</strong>result<br />
<strong>of</strong> calls toupdate-instance-for-di erent-class on sl ot denitionmetaobj ects.<br />
Duringinitialization, each i nitializationargument ischecked for errors <strong>and</strong><strong>the</strong>n associ<br />
ated with<strong>the</strong>slotdenitionmetaobj ect. <strong>The</strong> val ue can<strong>the</strong>n be accessed bycalling<strong>the</strong><br />
appropriate accessor as showninTabl e 6. 4.<br />
This section begi ns with a descri pti on <strong>of</strong> <strong>the</strong> error checking<strong>and</strong>processing <strong>of</strong> each<br />
initializationargument. This is followed byatable showing<strong>the</strong>generi c functi ons that can<br />
be used to access <strong>the</strong> stored initializationarguments.<br />
In <strong>the</strong>se descri ptions, <strong>the</strong> phrase \thi s argument defaults to al ue" means that when<br />
that i nitializationargument isnot supplied, initializationis performed as i f al ue had been<br />
supplied. For some initializationarguments this couldbedone by<strong>the</strong>use <strong>of</strong> default initializationarguments,<br />
but whe<strong>the</strong>r it is done this way is not speci ed. Implementationsare<br />
free todene default initializationarguments for speci ed sl ot denitionmetaobj ect cl asses.<br />
Portable programs are free to dene default initializationarguments for portable subclasses<br />
<strong>of</strong> <strong>the</strong> classslot-denition.<br />
<strong>The</strong> :name argument i s a sl ot name. An error is signal ed i f thi s argument isnot a<br />
symbol whi ch can be used as a vari able name. An error is signal ed i f thi s argument is<br />
not supplied.<br />
<strong>The</strong> :initformargumentisaform. <strong>The</strong> :initformargumentdefaults tonil. Anerror is<br />
signal ed i f <strong>the</strong> :initformargument issupplied, but <strong>the</strong> :initfuncti on argument isnot<br />
supplied.<br />
<strong>The</strong> :initfuncti on argument isafuncti on <strong>of</strong> zero arguments which,when cal l ed, eval u-<br />
ates <strong>the</strong> :initformin<strong>the</strong>appropriate lexical environment. <strong>The</strong> :initfuncti onargument<br />
defaults t<strong>of</strong>alse. Anerrorissignal ed i f <strong>the</strong> :initfuncti onargumentissupplied,but <strong>the</strong><br />
:initformargument isnot supplied.
68 Initialization<strong>of</strong> Slot DenitionMetaobj ects Chapter 6<br />
<strong>The</strong> :type argumentisatype speci er name. Anerror is signal ed o<strong>the</strong>rwise. <strong>The</strong> :type<br />
argument defaults to<strong>the</strong>symbol t.<br />
<strong>The</strong> :allocationargumentisasymbol . Anerror is signal ed o<strong>the</strong>rwise. <strong>The</strong> :allocation<br />
argument defaults to<strong>the</strong>symbol :instance.<br />
<strong>The</strong> :initargs argument is a list <strong>of</strong> symbol s. An error is signal ed i f thi s argument is<br />
not a proper list, or if anyelement <strong>of</strong>this list is not a symbol . <strong>The</strong> :initargs argument<br />
defaults to<strong>the</strong>empty list.<br />
<strong>The</strong> :readers argument is a list <strong>of</strong> functi on names. An error is signaledif it is not a<br />
proper list, or if anyelement isnot a validfuncti on name. It defaults to<strong>the</strong>empty list.<br />
An error is signal ed i f thi s argument issupplied<strong>and</strong><strong>the</strong>metaobj ect i s not a di rect sl ot<br />
denition.<br />
<strong>The</strong> :wri ters argument is a list <strong>of</strong> functi on names. An error is signaledif it is not a<br />
proper list, or if anyelement isnot a validfuncti on name. It defaults to<strong>the</strong>empty list.<br />
An error is signal ed i f thi s argument issupplied<strong>and</strong><strong>the</strong>metaobj ect i s not a di rect sl ot<br />
denition.<br />
<strong>The</strong> :documentation argument is a stringornil. An error is signal ed o<strong>the</strong>rwise. <strong>The</strong><br />
:documentation argument defaults tonil.<br />
After <strong>the</strong>processing<strong>and</strong>defaulting<strong>of</strong> initializationarguments descri bed above, <strong>the</strong>val ue<br />
<strong>of</strong> eachi nitializationargument i s associ atedwith<strong>the</strong>slotdenitionmetaobj ect. <strong>The</strong>se val ues<br />
can <strong>the</strong>n be accessed bycalling<strong>the</strong> correspondinggeneri c functi on. <strong>The</strong> correspondences<br />
are as f ol l ows:
Generi c Functi ons <strong>and</strong>Methods Initialization<strong>of</strong> Slot DenitionMetaobj ects 69<br />
nitialization rgument Generi c Functi on<br />
:name<br />
:initform<br />
:initfuncti on<br />
:type<br />
:allocation<br />
:initargs<br />
:readers<br />
:wri ters<br />
:documentation<br />
slot-denition-name<br />
slot-denition-initform<br />
slot-denition-initfuncti on<br />
slot-denition-type<br />
slot-denition-allocation<br />
slot-denition-initargs<br />
slot-denition-readers<br />
slot-denition-writers<br />
documentation<br />
a e . r r r<br />
.<br />
M<br />
It is not speci ed which methods provide <strong>the</strong> initialization <strong>and</strong>reinitialization behavior<br />
descri bed above. Instead, <strong>the</strong>informati on needed to allowportable programs tospeci al i ze<br />
this behavior is presented as a set <strong>of</strong> restrictions on <strong>the</strong>methods aportable programcan<br />
dene. <strong>The</strong> model i s that portable initializationmethods have access to <strong>the</strong> slotdenition<br />
metaobj ect when ei <strong>the</strong>r al l or none <strong>of</strong><strong>the</strong>speci ed i nitializationhas taken eect.<br />
<strong>The</strong>se restrictions govern<strong>the</strong>methods that a portable programcan dene on<strong>the</strong>generi c<br />
functi ons initialize-instance, rei nitialize-instance, <strong>and</strong> shared-initialize. <strong>The</strong>se restrictionsapplyonlytomethods<br />
on<strong>the</strong>se generi c functi ons f or which<strong>the</strong>rst speci al i zer i s<br />
asubcl ass <strong>of</strong> <strong>the</strong> classslot-denition. O<strong>the</strong>r portable methods on<strong>the</strong>se generi c functi ons<br />
are not aected by<strong>the</strong>se restrictions.<br />
Portable programs must not dene methods on shared-initialize or rei nitializeinstance.<br />
For initialize-instance:<br />
Portable programs must not dene primary methods.<br />
Portable programs may dene around-methods, but <strong>the</strong>se must beextending, not<br />
overridingmethods.<br />
Portablebefore-methods must assume that when <strong>the</strong>y are run, none <strong>of</strong><strong>the</strong>initializati<br />
on behavior descri bed above has been completed.<br />
Portable after-methods must assume that when <strong>the</strong>y are run, all <strong>of</strong> <strong>the</strong>initialization<br />
behavior descri bed above has been completed.<br />
<strong>The</strong> results are undened i f any<strong>of</strong> <strong>the</strong>se restrictionsareviolated.
70 make-instance Chapter 6<br />
intern e l s ecializer unct i on<br />
S<br />
intern-eql-speci alizer<br />
obj ect<br />
A<br />
<strong>The</strong> obj ect argument isanyLi sp obj ect.<br />
<strong>The</strong> result is <strong>the</strong> eql speci al i zer metaobj ect f or obj ect .<br />
P<br />
This functi on returns<strong>the</strong>unique eql speci al i zer metaobj ect f or obj ect , creatingoneifnecessary.<br />
Twocalls tointern-eql-speci alizer wi<strong>the</strong>ql arguments will return <strong>the</strong>same (i.e.,<br />
eq) val ue.<br />
R<br />
<strong>The</strong> result <strong>of</strong> calling eql-speci alizer-object on <strong>the</strong> resul t <strong>of</strong> a cal l to intern-eql-speci alizer<br />
is onlyguaranteed to be eql to <strong>the</strong> ori gi nal obj ect argument, not necessarily eq.<br />
a e instance eneri c unct i on<br />
S<br />
ma e- i nstance<br />
cl ass res ini t args<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect or a cl ass name.<br />
<strong>The</strong> ini t args argument is alist <strong>of</strong> alternati ng initializationargument names <strong>and</strong>val ues.<br />
<strong>The</strong> result is anewlyallocated<strong>and</strong>initializedinstance <strong>of</strong> cl ass.<br />
P<br />
<strong>The</strong> generi c functi on ma e- i nstance creates <strong>and</strong>returnsanewi nstance <strong>of</strong> <strong>the</strong> given cl ass.<br />
Its behavior <strong>and</strong>use is descri bed i n <strong>the</strong> CLOS speci cati on.<br />
M<br />
ma e- i nstance ri mar et hod<br />
cl ass s m ol res ini t args<br />
This method si mplyinvokes ma e- i nstance recursivel y on <strong>the</strong> arguments i class<br />
cl ass <strong>and</strong> ini t args.
Generi c Functi ons <strong>and</strong>Methods make-method-lambda 71<br />
ma e- i nstance ri mar et hod<br />
cl ass s a ar class res ini t args<br />
ma e- i nstance ri mar et hod<br />
cl ass calla le s a ar class res ini t args<br />
<strong>The</strong>se methods implement<strong>the</strong>behavior <strong>of</strong> ma e- i nstance descri bed i n <strong>the</strong>CLOS specicati<br />
on secti on named \Object Creati on <strong>and</strong> Initialization."<br />
a e et o la a eneri c unct i on<br />
S<br />
ma e- method-lambda<br />
generi c- unct i on met hod lambda- e<br />
ressi on en ironment<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> met hod argument isa(possiblyuninitialized)method metaobj ect.<br />
<strong>The</strong> lambda- e ression argument isalambda expression.<br />
<strong>The</strong> en ironment argument is <strong>the</strong> same as <strong>the</strong> environment argument to macro<br />
expansion functi ons.<br />
Thi s generi c functi on returnstwoval ues. <strong>The</strong> rst is a lambda expression, <strong>the</strong> secondisa<br />
list <strong>of</strong> initializationarguments <strong>and</strong>val ues.<br />
P<br />
Thi s generi c functionis calledto produce a l ambda expression whichcanitself beused to<br />
produce a method f uncti on for a method <strong>and</strong> generi c functi on with <strong>the</strong>speci ed classes.<br />
<strong>The</strong> generi c functi on <strong>and</strong>method <strong>the</strong> method f uncti on will beused withare not required<br />
to be<strong>the</strong>given ones. Moreover, <strong>the</strong> method metaobj ect may beuninitialized.<br />
Ei<strong>the</strong>r <strong>the</strong> functi on compile,<strong>the</strong>speci al formfuncti onor <strong>the</strong> functi on coerce must be<br />
usedtoconvert <strong>the</strong> lambda expression a method f uncti on. <strong>The</strong> method f unctionitself can<br />
be appliedtoarguments withapplyor funcall.<br />
When a method i s actually calledbyaneecti ve method, its rst argument will bea<br />
list <strong>of</strong> <strong>the</strong>arguments to <strong>the</strong>generi c functi on. Its remai ningarguments will beallbut <strong>the</strong><br />
rst argument passed to call-method. Bydefault, all method f uncti ons must accept two<br />
arguments: <strong>the</strong> list <strong>of</strong> arguments to <strong>the</strong>generi c functi on <strong>and</strong><strong>the</strong> list <strong>of</strong> next methods.<br />
For a gi ven generi c functi on <strong>and</strong> method class, <strong>the</strong> applicable methods on ma e-<br />
method-lambda <strong>and</strong> compute-e ecti ve-method must be consistent in <strong>the</strong> following<br />
way: each use <strong>of</strong> call-method returned by<strong>the</strong>method on compute-e ecti ve-method<br />
must have <strong>the</strong>samenumber <strong>of</strong> arguments, <strong>and</strong><strong>the</strong>method l ambdareturned by<strong>the</strong>method<br />
on ma e- method-lambda must accept a correspondingnumber <strong>of</strong> arguments.
72 make-method-lambda Chapter 6<br />
ote that <strong>the</strong> system-suppliedimplementation<strong>of</strong> call-ne t-method is not requiredto<br />
h<strong>and</strong>le extra arguments to <strong>the</strong>method f uncti on. Users who dene additional arguments to<br />
<strong>the</strong>method f uncti on must ei<strong>the</strong>r redene or f orego call-ne t-method. (See <strong>the</strong> example<br />
bel ow.)<br />
When <strong>the</strong> method metaobj ect i s created with ma e- i nstance, <strong>the</strong> method f uncti on<br />
must be<strong>the</strong>val ue <strong>of</strong><strong>the</strong> :functi on initializationargument. <strong>The</strong> additional i nitialization<br />
arguments, returned as <strong>the</strong> secondval ue <strong>of</strong> thi s generi c functi on, must also bepassedinthis<br />
cal l to ma e- i nstance.<br />
M<br />
ma e- method-lambda ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
met hod s a ar me o<br />
lambda- e ression<br />
en ironment<br />
This method returns a method l ambda whi ch accepts twoarguments, <strong>the</strong> list <strong>of</strong> arguments<br />
to <strong>the</strong> generi c functi on, <strong>and</strong><strong>the</strong> list <strong>of</strong> next methods. What i nitialization<br />
arguments may be returned i n <strong>the</strong> secondval ue areunspeci ed.<br />
This method can be overridden.<br />
ample:<br />
This example shows howto dene akind<strong>of</strong> method which,fromwithin<strong>the</strong>body<br />
<strong>of</strong> <strong>the</strong> method, has access to <strong>the</strong> actual method metaobj ect f or <strong>the</strong> method. This<br />
simplied code overrides whatever method combination is speci ed for <strong>the</strong> generi c<br />
functi on, implementingasimplemethod combinationsupportingonlyprimary methods,<br />
call-ne t-method <strong>and</strong> ne t-method-p. (In addition, its a simplied version<br />
<strong>of</strong> call-ne t-method whichdoes no error checking. )<br />
oti ce that <strong>the</strong> extra lexical functi onbindings get wrapped around<strong>the</strong>bodybef ore<br />
call-ne t-method is called. In this way, <strong>the</strong>user's denition<strong>of</strong> call-ne t-method<br />
<strong>and</strong> ne t-method-pare sure to override<strong>the</strong>system's denitions.<br />
e class m e eric c io s a ar e eric c io<br />
e a l i i ar s me o class i class m me o<br />
e class m me o s a ar me o<br />
e me o ma e me o lam a m e eric c io<br />
me o m me o<br />
lam a expressio<br />
e iro me<br />
eclare i ore e iro me
Generi c Functi ons <strong>and</strong>Methods map-dependents 73<br />
lam a ar s ex me o s is me o<br />
call ex me o me o<br />
lam a ca r lam a expressio<br />
le is me o is me o<br />
call ex me o res c m ar s<br />
call me o c io car ex me o s<br />
or c m ar s ar s<br />
c r ex me o s<br />
car ex me o s<br />
ex me o p<br />
o ll ex me o s<br />
c r lam a expressio<br />
e iro me<br />
ar s ex me o s<br />
e me o comp e e ec i e me o m e eric c io<br />
me o com i a io<br />
me o s<br />
call me o car me o s c r me o s car me o s<br />
a e en ents eneri c unct i on<br />
S<br />
map-dependents<br />
met aobj ect<br />
unct i on<br />
A<br />
<strong>The</strong> met aobj ect argument isaclassorgeneri c functi on metaobj ect.<br />
<strong>The</strong> unct i on argument isafuncti on whi ch accepts oneargument.<br />
<strong>The</strong> val ue returned i s unspeci ed.<br />
P<br />
Thi s generi c functionapplies unct i on to each <strong>of</strong> <strong>the</strong>dependents <strong>of</strong> met aobj ect . <strong>The</strong> order i n<br />
which<strong>the</strong>dependents are processed is not speci ed, but unct i on is appliedtoeachdependent<br />
once <strong>and</strong>onlyonce. If, during<strong>the</strong>mapping, add-dependent or remove- dependent<br />
is calledtoalter <strong>the</strong>dependents <strong>of</strong> met aobj ect , it is not speci ed whe<strong>the</strong>r <strong>the</strong> newlyadded<br />
or removed dependent will have unct i on appliedtoit.
74 method- ::: Chapter 6<br />
M<br />
map-dependents ri mar et hod<br />
met aobj ect s a ar class unct i on<br />
This method has no speci ed behavior beyond that which is speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-dependent (st<strong>and</strong>ard-class t)<br />
remove-dependent (st<strong>and</strong>ard-class t)<br />
map-dependents ri mar et hod<br />
met aobj ect calla le s a ar class unct i on<br />
This method has no speci ed behavior beyond that which is speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-dependent (funcallable-st<strong>and</strong>ard-class t)<br />
remove-dependent (funcallable-st<strong>and</strong>ard-class t)<br />
map-dependents ri mar et hod<br />
met aobj ect s a ar e eric c io unct i on<br />
This method has no speci ed behavior beyond that which is speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-dependent (st<strong>and</strong>ard-generi c- f uncti ont)<br />
remove-dependent (st<strong>and</strong>ard-generic-functi ont)<br />
R<br />
See <strong>the</strong>\Dependent Mai ntenance <strong>Protocol</strong>" sectionfor remarks about <strong>the</strong>use <strong>of</strong> this facility.<br />
et o eneri c unct i on<br />
<strong>The</strong> followinggeneri c functi ons aredescri bed toge<strong>the</strong>r under \Readers f or Method <strong>Metaobject</strong>s"<br />
(page 81): method-functi on, method-generic-functi on, method-lambda-list,<br />
method-speci alizers, method-qualiers <strong>and</strong> accessor-method-slot-denition.
Generi c Functi ons <strong>and</strong>Methods Readers f or Class Metaobj ects 75<br />
ea ers or lass etao ects<br />
Inthis <strong>and</strong><strong>the</strong>immediatelyfollowing secti ons, <strong>the</strong>\reader" generi c functi ons whichsimply<br />
return informati on associ ated withaparticular kind<strong>of</strong> metaobj ect are presented toge<strong>the</strong>r.<br />
General i nformationis presented rst, followed byadescri pti on <strong>of</strong> <strong>the</strong> purpose <strong>of</strong> each, <strong>and</strong><br />
endingwith<strong>the</strong>speci ed methods for<strong>the</strong>se generi c functi ons.<br />
<strong>The</strong> reader generi c functi onswhichsimplyreturninformati on associ ated withclass metaobj<br />
ects are presented toge<strong>the</strong>r i n this section.<br />
Each <strong>of</strong> <strong>the</strong> reader generi c functi ons f or cl ass metaobj ects has <strong>the</strong> samesyntax, accepting<br />
one requi red argument calledcl ass , whichmust beanclassmetaobj ect; o<strong>the</strong>rwi se, an error<br />
is signal ed. Anerror is alsosignal ed i f <strong>the</strong> classmetaobj ect has not been i nitialized.<br />
<strong>The</strong>se generi c functi ons can be calledby<strong>the</strong>useror<strong>the</strong>implementation.<br />
For any<strong>of</strong> <strong>the</strong>se generi c functi ons whichreturns a list, such lists will not be mutatedby<br />
<strong>the</strong>implementation. <strong>The</strong> results are undened i f a portable programallows sucha list to<br />
be mutated.<br />
cl ass-def ault-initargs eneri c unct i on<br />
cl ass<br />
Returns alist <strong>of</strong> <strong>the</strong>default initializationarguments for cl ass. Each el ement <strong>of</strong>this list<br />
is acanonicalizeddefault initializationargument. <strong>The</strong> emptylist is returned i f cl ass has<br />
no default initializationarguments.<br />
Duringnalizationnalize-inheri tance calls compute-def ault-initargs to compute<br />
<strong>the</strong>default initializationarguments for <strong>the</strong> class. That val ue i s associ ated with<strong>the</strong><br />
cl ass metaobj ect <strong>and</strong> is returned by cl ass-def ault-initargs.<br />
Thi s generi c functionsignals an error if cl ass has not been nal i zed.<br />
cl ass-di rect- def ault-initargs eneri c unct i on<br />
cl ass<br />
Returns a list <strong>of</strong> <strong>the</strong>di rect default initializationarguments for cl ass. Each el ement <strong>of</strong><br />
this list is a canonicalized default initializationargument. <strong>The</strong> empty list is returned<br />
if cl ass has no di rect default initializationarguments. This is <strong>the</strong> defaulted val ue <strong>of</strong><br />
<strong>the</strong> :di rect- def ault-initargs initializationargument that was associ ated with<strong>the</strong>class<br />
duringinitializationor reinitialization.<br />
cl ass-di rect- sl ots eneri c unct i on<br />
cl ass<br />
Returnsaset<strong>of</strong><strong>the</strong>di rect sl ots <strong>of</strong> cl ass. <strong>The</strong> elements <strong>of</strong> this set are di rect sl ot denition<br />
metaobj ects. If <strong>the</strong> class has no direct slots, <strong>the</strong> empty set is returned. This is <strong>the</strong>
76 Readers f or Class Metaobj ects Chapter 6<br />
defaultedval ue <strong>of</strong> <strong>the</strong> :direct-slots initializationargumentthat was associ ated with<strong>the</strong><br />
cl ass duringinitialization<strong>and</strong>reinitialization.<br />
cl ass-direct-subcl asses eneri c unct i on<br />
cl ass<br />
Returnsaset<strong>of</strong><strong>the</strong>di rect subclasses <strong>of</strong> cl ass. <strong>The</strong> elements <strong>of</strong> this set are class metaobj<br />
ects that al l mention thi s cl ass among <strong>the</strong>i r di rect superclasses. <strong>The</strong> empty set is<br />
returned i f cl ass has no di rect subclasses. This val ue ismai ntained by<strong>the</strong>generi c functions<br />
add-direct-subcl ass <strong>and</strong> remove- direct-subcl ass.<br />
cl ass-direct-supercl asses eneri c unct i on<br />
cl ass<br />
Returns a list <strong>of</strong> <strong>the</strong> di rect supercl asses <strong>of</strong> cl ass. <strong>The</strong> elements <strong>of</strong> this list are class<br />
metaobj ects. <strong>The</strong> emptylist is returned i f cl ass has no di rect superclasses. This is <strong>the</strong><br />
defaultedval ue <strong>of</strong> <strong>the</strong> :direct-supercl asses initializationargumentthat was associ ated<br />
with<strong>the</strong>classduringinitializationor reinitialization.<br />
cl ass-nalized-p eneri c unct i on<br />
cl ass<br />
Returns trueif cl ass has been nal i zed. Returns f al se o<strong>the</strong>rwise. Also returns false if<br />
<strong>the</strong>classhas not been i nitialized.<br />
cl ass-name eneri c unct i on<br />
cl ass<br />
Returns<strong>the</strong>name <strong>of</strong> cl ass. This val ue can be anyLi sp obj ect, but isusuallyasymbol ,<br />
or nil if <strong>the</strong>classhas no name. This is <strong>the</strong>defaultedval ue <strong>of</strong><strong>the</strong> :name initialization<br />
argumentthat was associ ated with<strong>the</strong>classduringinitializationorreinitialization. (Also<br />
see (setf class-name).)<br />
cl ass-precedence-l i st eneri c unct i on<br />
cl ass<br />
Returns<strong>the</strong>classprecedence list <strong>of</strong> cl ass. <strong>The</strong> elements <strong>of</strong> this list are class metaobj ects.<br />
Duringclass nalization nalize-inheri tance calls compute-class-precedencelist<br />
to compute <strong>the</strong>classprecedence list <strong>of</strong> <strong>the</strong> class. That val ue i s associ ated with<strong>the</strong><br />
cl ass metaobj ect <strong>and</strong> is returned by cl ass-precedence-l i st.<br />
Thi s generi c functionsignals an error if cl ass has not been nal i zed.
Generi c Functi ons <strong>and</strong>Methods Readers f or Class Metaobj ects 77<br />
cl ass-prototype eneri c unct i on<br />
cl ass<br />
Returnsaprototype instance <strong>of</strong> cl ass. Whe<strong>the</strong>r <strong>the</strong>instanceis initializedis not speci ed.<br />
<strong>The</strong> results are undened i f a portable programmodies <strong>the</strong> binding<strong>of</strong> anyslot <strong>of</strong><br />
prototype instance.<br />
Thi s generi c functionsignals an error if cl ass has not been nal i zed.<br />
cl ass-slots eneri c unct i on<br />
cl ass<br />
Returnsapossiblyempty set <strong>of</strong> <strong>the</strong> slots accessible ininstances <strong>of</strong> cl ass . <strong>The</strong> elements<br />
<strong>of</strong> this set are eecti ve slotdenitionmetaobj ects.<br />
Duringclass nalizationnalize-inheritance calls compute-slots to compute <strong>the</strong><br />
sl ots <strong>of</strong> <strong>the</strong> class. That val ue i s associ ated with<strong>the</strong>classmetaobj ect <strong>and</strong> is returned by<br />
cl ass-slots.<br />
Thi s generi c functionsignals an error if cl ass has not been nal i zed.<br />
M<br />
<strong>The</strong> speci ed methods for<strong>the</strong>classmetaobj ect reader generi c functi ons arepresentedbel ow.<br />
Each entry in <strong>the</strong> table indicates a method on one <strong>of</strong> <strong>the</strong> reader generi c functi ons,<br />
speci al i zed to a speci ed cl ass. <strong>The</strong> number i neachentry i s a reference to<strong>the</strong>full descri ption<br />
<strong>of</strong> <strong>the</strong> method. <strong>The</strong> full descri ptionsappear after <strong>the</strong> table.
78 Readers f or Class Metaobj ects Chapter 6<br />
st<strong>and</strong>ard-class forward- built-in<strong>and</strong><br />
referenced- cl ass<br />
funcallable- cl ass<br />
st<strong>and</strong>ard-class<br />
cl ass-def ault-initargs 2 3 4<br />
cl ass-direct-def ault-initargs 1 4 4<br />
cl ass-direct-sl ots 1 4 4<br />
cl ass-direct-subcl asses 9 9 7<br />
cl ass-direct-supercl asses 1 4 7<br />
cl ass-nalized-p 2 6 5<br />
cl ass-name 1 1 8<br />
cl ass-precedence-l i st 2 3 7<br />
cl ass-prototype 10 10 10<br />
cl ass-slots 2 3 4<br />
1. This method returns <strong>the</strong>val ue whichwas associ ated with<strong>the</strong>classmetaobj ect during<br />
initializationor reinitialization.<br />
2. This method returns <strong>the</strong> val ue associ ated with <strong>the</strong> class metaobj ect by nalizeinheri<br />
tance (st<strong>and</strong>ard-class) or nalize-inheri tance (funcallable-st<strong>and</strong>ardcl<br />
ass).<br />
3. This method si gnals an error.<br />
4. This method returns<strong>the</strong>empty list.<br />
5. This method returns true.<br />
6. This method returns f al se.<br />
7. This method returns a val ue deri ved from<strong>the</strong> informati on i n Tabl e 5. 1, except that<br />
implementation-speci cmodicati ons arepermitted as descri bed i n secti on \Implementation<br />
<strong>and</strong>User Specialization."<br />
8. This method returns<strong>the</strong>name <strong>of</strong><strong>the</strong>built-inclass.<br />
9. This methods returnsaval ue whichis mai ntainedby add-direct-subcl ass (class class)<br />
<strong>and</strong> remove-direct-subcl ass (class class). This method can be overridden only if<br />
those methods areoverridden as well.<br />
10. obehaviorisspeci ed for this method beyond that speci ed for <strong>the</strong> generi c functi on.
Generi c Functi ons <strong>and</strong>Methods Readers f or Generi c Functi on Metaobj ects 79<br />
ea ers or eneric uncti on etao ects<br />
<strong>The</strong> reader generi c functi ons whichsimplyreturn informati on associ ated withgeneri c functi<br />
on metaobj ects are presented toge<strong>the</strong>r i n this section.<br />
Each <strong>of</strong> <strong>the</strong> reader generi c functi ons f or generi c functi on metaobj ects has <strong>the</strong> samesyntax,<br />
acceptingonerequi red argument calledgeneri c- unct i on, whichmust be a generi c functi<br />
on metaobj ect; o<strong>the</strong>rwise, an error is signal ed. An error is also signal ed i f <strong>the</strong> generi c<br />
functi on metaobj ect has not been i nitialized.<br />
<strong>The</strong>se generi c functi ons can be calledby<strong>the</strong>useror<strong>the</strong>implementation.<br />
<strong>The</strong> list returned bythi s generi c functi on will not be mutated by<strong>the</strong>implementation.<br />
<strong>The</strong> results are undened i f a portable programmutates <strong>the</strong> list returned bythi s generi c<br />
functi on.<br />
generi c- f uncti on-argument-precedence-order eneri c unct i on<br />
generi c- unct i on<br />
Returns <strong>the</strong> argument precedence order <strong>of</strong> <strong>the</strong> generi c functi on. This val ue is a list<br />
<strong>of</strong> symbol s, a permutation <strong>of</strong> <strong>the</strong>requiredparameters i n <strong>the</strong> lambdalist <strong>of</strong> <strong>the</strong>generi c<br />
functi on. This is<strong>the</strong>defaultedval ue <strong>of</strong> <strong>the</strong> :argument-precedence-order initialization<br />
argument that was associ ated with<strong>the</strong>generi c functi on metaobj ect duringinitialization<br />
or rei nitialization.<br />
generi c- f uncti on-decl arations eneri c unct i on<br />
generi c- unct i on<br />
Returnsapossiblyemptylist <strong>of</strong> <strong>the</strong>decl arati ons <strong>of</strong><strong>the</strong>generi c functi on. <strong>The</strong> elements<br />
<strong>of</strong> this list are decl arati ons. This list is <strong>the</strong>defaulted val ue <strong>of</strong> <strong>the</strong> :decl arations initializationargument<br />
that was associ ated with <strong>the</strong> generi c functi on metaobj ect during<br />
initializationor reinitialization.<br />
generi c- f uncti on-lambda-list eneri c unct i on<br />
generi c- unct i on<br />
Returns <strong>the</strong> lambda list <strong>of</strong> <strong>the</strong> generi c functi on. This is <strong>the</strong> defaulted val ue <strong>of</strong> <strong>the</strong><br />
:lambda-listinitializationargumentthat was associ ated with<strong>the</strong>generi c functi onmetaobj<br />
ect duringinitializationor reinitialization. An error is signal ed i f <strong>the</strong> lambdalist has<br />
yet to be supplied.
80 Readers f or Generi c Functi on Metaobj ects Chapter 6<br />
generi c- f uncti on-method-class eneri c unct i on<br />
generi c- unct i on<br />
Returns<strong>the</strong>default method cl ass <strong>of</strong> <strong>the</strong> generi c functi on. This class must beasubcl ass<br />
<strong>of</strong> <strong>the</strong> classmethod. This is <strong>the</strong>defaulted val ue <strong>of</strong><strong>the</strong> :method-class initialization<br />
argument that was associ ated with<strong>the</strong>generi c functi on metaobj ect duringinitialization<br />
or rei nitialization.<br />
generi c- f uncti on-method-combination eneri c unct i on<br />
generi c- unct i on<br />
Returns<strong>the</strong>method combinati on <strong>of</strong> <strong>the</strong> generi c functi on. This is amethod combination<br />
metaobj ect. This is <strong>the</strong> defaulted val ue <strong>of</strong> <strong>the</strong> :method-combination initialization<br />
argument that was associ ated with<strong>the</strong>generi c functi on metaobj ect duringinitialization<br />
or rei nitialization.<br />
generi c- f uncti on-methods eneri c unct i on<br />
generi c- unct i on<br />
Returns<strong>the</strong> set <strong>of</strong> methods currently connected to <strong>the</strong> generi c functi on. This is aset <strong>of</strong><br />
method metaobj ects. This val ue ismai ntained by<strong>the</strong>generi c functi ons add-method<br />
<strong>and</strong> remove-method.<br />
generi c- f uncti on-name eneri c unct i on<br />
generi c- unct i on<br />
Returns <strong>the</strong>name <strong>of</strong><strong>the</strong>generi c functi on, or nil if <strong>the</strong>generi c functi on has no name.<br />
This is <strong>the</strong>defaulted val ue <strong>of</strong><strong>the</strong> :name initializationargument that was associ ated<br />
with<strong>the</strong>generi c functi on metaobj ect duringinitializationor reinitialization. (Also see<br />
(setf generic-functi on-name).)<br />
M<br />
<strong>The</strong> speci ed methods for <strong>the</strong> generi c functi on metaobj ect reader generi c functi ons are<br />
presented bel ow.
Generi c Functi ons <strong>and</strong>Methods Readers f or Method Metaobj ects 81<br />
generi c- f uncti on-argument-precedence-order ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
generi c- f uncti on-decl arations ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
generi c- f uncti on-lambda-list ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
generi c- f uncti on-method-class ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
generi c- f uncti on-method-combination ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
generi c- f uncti on-name ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
obehavior is speci ed for <strong>the</strong>se methods beyond that whichis speci ed for <strong>the</strong>i r respecti<br />
ve generi c functi ons.<br />
generi c- f uncti on-methods ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
obehaviorisspeci ed for this method beyondthat whichis speci ed for <strong>the</strong>i r respecti ve<br />
generi c functi ons.<br />
<strong>The</strong> val ue returned by this method i s mai ntained by add-method (st<strong>and</strong>ardgeneri<br />
c- f uncti on st<strong>and</strong>ard-method) <strong>and</strong> remove- method (st<strong>and</strong>ard-generi c-<br />
functi onst<strong>and</strong>ard-method).<br />
ea ers or et o etao ects<br />
<strong>The</strong> reader generi c functi ons whichsimplyreturninformati on associ ated withmethod metaobj<br />
ects are presented toge<strong>the</strong>r here i n <strong>the</strong> f ormat descri bed under \Readers f or Class Metaobj<br />
ects. "<br />
Each <strong>of</strong> <strong>the</strong>se reader generi c functi ons have <strong>the</strong> samesyntax, acceptingone required<br />
argumentcalledmet hod, whichmust beamethodmetaobj ect; o<strong>the</strong>rwise,anerrorissignal ed.<br />
Anerror is alsosignal ed i f <strong>the</strong> method metaobj ect has not been i nitialized.<br />
<strong>The</strong>se generi c functi ons can be calledby<strong>the</strong>useror<strong>the</strong>implementation.<br />
For any<strong>of</strong> <strong>the</strong>se generi c functi ons whichreturns a list, such lists will not be mutatedby<br />
<strong>the</strong>implementation. <strong>The</strong> results are undened i f a portable programallows sucha list to<br />
be mutated.
82 Readers f or Method Metaobj ects Chapter 6<br />
method-functi on eneri c unct i on<br />
met hod<br />
Returns <strong>the</strong>method f uncti on <strong>of</strong> met hod. This is <strong>the</strong>defaulted val ue <strong>of</strong><strong>the</strong> :functi on<br />
initializationargument that was associ ated with<strong>the</strong>method duringinitialization.<br />
method-generi c- f uncti on eneri c unct i on<br />
met hod<br />
Returns <strong>the</strong>generi c functi on that met hod is currently connected to, or nil if it is not<br />
currently connected to any generi c functi on. This val ue isei<strong>the</strong>r a generi c functi on<br />
metaobj ect or nil. When a method i s rst created it is not connected to anygeneri c<br />
functi on. This connecti on i s mai ntained by <strong>the</strong> generi c functi ons add-method <strong>and</strong><br />
remove- method.<br />
method-lambda-list eneri c unct i on<br />
met hod<br />
Returns<strong>the</strong>(unspeci al i zed) lambdalist <strong>of</strong> met hod. This val ue isaCommon Lisplambda<br />
list. This is <strong>the</strong>defaulted val ue <strong>of</strong> <strong>the</strong> :lambda-list initializationargument that was<br />
associ ated with<strong>the</strong>method duringinitialization.<br />
method-speci alizers eneri c unct i on<br />
met hod<br />
Returns a list <strong>of</strong> <strong>the</strong>speci al i zers <strong>of</strong> met hod. This val ue isalist<strong>of</strong>speci al i zer metaobjects.<br />
This is <strong>the</strong>defaultedval ue <strong>of</strong> <strong>the</strong> :speci alizers initializationargument that was<br />
associ ated with<strong>the</strong>method duringinitialization.<br />
method-qualiers eneri c unct i on<br />
met hod<br />
Returnsa(possiblyempty) list <strong>of</strong> <strong>the</strong>qualiers <strong>of</strong> met hod. This val ue isalist<strong>of</strong>non- nil<br />
atoms. This is <strong>the</strong>defaultedval ue <strong>of</strong> <strong>the</strong> :qualiers initializationargument that was<br />
associ ated with<strong>the</strong>method duringinitialization.<br />
accessor-method-slot-denition eneri c unct i on<br />
met hod<br />
Thi s accessor can only be calledonaccessor methods. It returns <strong>the</strong>di rect sl ot denitionmetaobj<br />
ect that dened this method. This is <strong>the</strong>val ue <strong>of</strong> <strong>the</strong> :slot-denition<br />
initializationargument associ ated with<strong>the</strong>method duringinitialization.<br />
M<br />
<strong>The</strong> speci ed methods for<strong>the</strong>method metaobj ect readers are presented bel ow.
Generi c Functi ons <strong>and</strong>Methods Readers f or Slot DenitionMetaobj ects 83<br />
method-functi on ri mar et hod<br />
met hod s a ar me o<br />
method-lambda-list ri mar et hod<br />
met hod s a ar me o<br />
method-speci alizers ri mar et hod<br />
met hod s a ar me o<br />
method-qualiers ri mar et hod<br />
met hod s a ar me o<br />
obehavior is speci ed for <strong>the</strong>se methods beyond that whichis speci ed for <strong>the</strong>i r respecti<br />
ve generi c functi ons.<br />
method-generi c- f uncti on ri mar et hod<br />
met hod s a ar me o<br />
obehavior is speci ed for this method beyond that whichis speci ed f or i ts generi c<br />
functi on.<br />
<strong>The</strong> val ue returned by this method i s mai ntained by add-method (st<strong>and</strong>ardgeneri<br />
c- f uncti on st<strong>and</strong>ard-method) <strong>and</strong> remove- method (st<strong>and</strong>ard-generi c-<br />
functi onst<strong>and</strong>ard-method).<br />
accessor-method-slot-denition ri mar et hod<br />
met hod s a ar accessor me o<br />
obehavior is speci ed for this method beyond that whichis speci ed f or i ts generi c<br />
functi on.<br />
ea ers or Slot e nition etao ects<br />
<strong>The</strong> reader generi c functi ons whichsimplyreturninformati on associ ated withslot denition<br />
metaobj ects are presented toge<strong>the</strong>r here i n <strong>the</strong> f ormat descri bed under \Readers f or Class<br />
Metaobj ects. "<br />
Each <strong>of</strong> <strong>the</strong> reader generi c functi ons f or sl ot denitionmetaobj ects has <strong>the</strong> samesyntax,<br />
acceptingonerequi red argument called sl ot, which must be a sl ot denition metaobj ect;<br />
o<strong>the</strong>rwise, anerror is signal ed. Anerror is alsosignal ed i f <strong>the</strong> slotdenitionmetaobj ect has<br />
not been i nitialized.<br />
<strong>The</strong>se generi c functi ons can be calledby<strong>the</strong>useror<strong>the</strong>implementation.
84 Readers f or Slot DenitionMetaobj ects Chapter 6<br />
For any<strong>of</strong> <strong>the</strong>se generi c functi ons whichreturns a list, such lists will not be mutatedby<br />
<strong>the</strong>implementation. <strong>The</strong> results are undened i f a portable programallows sucha list to<br />
be mutated.<br />
G F<br />
slot-denition-allocation eneri c unct i on<br />
sl ot<br />
Returns<strong>the</strong> al l ocati on <strong>of</strong> sl ot. This is asymbol . This is <strong>the</strong>defaultedval ue <strong>of</strong> <strong>the</strong> :allocation<br />
initializationargument that was associ ated with<strong>the</strong>slotdenitionmetaobj ect<br />
duringinitialization.<br />
slot-denition-initargs eneri c unct i on<br />
sl ot<br />
Returns<strong>the</strong>set<strong>of</strong>initializationargument keywords forsl ot. This is <strong>the</strong>defaultedval ue<br />
<strong>of</strong> <strong>the</strong> :initargs initialization argument that was associ ated with <strong>the</strong> slot denition<br />
metaobj ect duringinitialization.<br />
slot-denition-initform eneri c unct i on<br />
sl ot<br />
Returns<strong>the</strong>initializationform<strong>of</strong> sl ot. This canbeany f orm. This is <strong>the</strong>defaultedval ue<br />
<strong>of</strong> <strong>the</strong> :initforminitialization argument that was associ ated with <strong>the</strong> slot denition<br />
metaobj ect duringinitialization. When sl ot has noinitialization f orm, <strong>the</strong>val ue returned<br />
is unspeci ed (however, slot-denition-initfuncti on is guaranteed to return nil).<br />
slot-denition-initfuncti on eneri c unct i on<br />
sl ot<br />
Returns<strong>the</strong>initializationfuncti on<strong>of</strong> sl ot. This val ue isei<strong>the</strong>r a functi on<strong>of</strong> noarguments,<br />
or nil,indicatingthat <strong>the</strong> slothas no initializationfuncti on. This is <strong>the</strong>defaultedval ue<br />
<strong>of</strong> <strong>the</strong> :initfuncti on initializationargumentthat was associ ated with<strong>the</strong>slotdenition<br />
metaobj ect duringinitialization.<br />
slot-denition-name eneri c unct i on<br />
sl ot<br />
Returns<strong>the</strong>name <strong>of</strong> sl ot. This val ue isasymbol that can be used as a vari able name.<br />
This is <strong>the</strong>val ue <strong>of</strong> <strong>the</strong> :name initializationargument that was associ ated with<strong>the</strong>slot<br />
denitionmetaobj ect duringinitialization.
Generi c Functi ons <strong>and</strong>Methods Readers f or Slot DenitionMetaobj ects 85<br />
slot-denition-type eneri c unct i on<br />
sl ot<br />
Returns <strong>the</strong> al l ocati on <strong>of</strong> sl ot. This is a type speci er name. This is <strong>the</strong> defaulted<br />
val ue <strong>of</strong><strong>the</strong> :name initializationargument that was associ ated with<strong>the</strong>slotdenition<br />
metaobj ect duringinitialization.<br />
M<br />
<strong>The</strong> speci ed methods for<strong>the</strong>slotdenitionmetaobj ect readers are presented bel ow.<br />
slot-denition-allocation ri mar et hod<br />
sl ot - de nition s a ar slo e i i io<br />
slot-denition-initargs ri mar et hod<br />
sl ot - de nition s a ar slo e i i io<br />
slot-denition-initform ri mar et hod<br />
sl ot - de nition s a ar slo e i i io<br />
slot-denition-initfuncti on ri mar et hod<br />
sl ot - de nition s a ar slo e i i io<br />
slot-denition-name ri mar et hod<br />
sl ot - de nition s a ar slo e i i io<br />
slot-denition-type ri mar et hod<br />
sl ot - de nition s a ar slo e i i io<br />
obehavior is speci ed for <strong>the</strong>se methods beyond that whichis speci ed for <strong>the</strong>i r respecti<br />
ve generi c functi ons.<br />
D S D M<br />
<strong>The</strong> followingadditional reader generi c functi ons aredened for di rect sl ot denitionmetaobj<br />
ects.<br />
slot-denition-readers eneri c unct i on<br />
di rect -sl ot<br />
Returns a (possibly empty) set <strong>of</strong> readers <strong>of</strong> <strong>the</strong> di rect sl ot. This val ue is a list <strong>of</strong><br />
functi on names. This is <strong>the</strong>defaultedval ue <strong>of</strong> <strong>the</strong> :readers initializationargument that<br />
was associ ated with<strong>the</strong>di rect sl ot denitionmetaobj ect duringinitialization.
86 reader-method-class Chapter 6<br />
slot-denition-wri ters eneri c unct i on<br />
di rect -sl ot<br />
Returns a (possibly empty) set <strong>of</strong> writers <strong>of</strong> <strong>the</strong> di rect sl ot. This val ue is a list <strong>of</strong><br />
functi on names. This is <strong>the</strong>defaultedval ue <strong>of</strong> <strong>the</strong> :wri ters initializationargument that<br />
was associ ated with<strong>the</strong>di rect sl ot denitionmetaobj ect duringinitialization.<br />
slot-denition-readers ri mar et hod<br />
di rect -sl ot -de nition s a ar irec slo e i i io<br />
slot-denition-wri ters ri mar et hod<br />
di rect -sl ot -de nition s a ar irec slo e i i io<br />
obehavior is speci ed for <strong>the</strong>se methods beyond what i s speci ed for <strong>the</strong>i r generi c<br />
functi ons.<br />
E S D M<br />
<strong>The</strong> followingreader generi c functi on i s dened for eecti ve slotdenitionmetaobj ects.<br />
slot-denition-location eneri c unct i on<br />
e ect i e- sl ot - de nition<br />
Returns<strong>the</strong> l ocati on <strong>of</strong> e ect i e- sl ot - de nition. <strong>The</strong> meaning<strong>and</strong>interpretation <strong>of</strong> this<br />
val ue isdescri bed i n <strong>the</strong> sectioncalled\Instance Structure <strong>Protocol</strong>."<br />
slot-denition-location ri mar et hod<br />
e ect i e- sl ot - de nition s a ar e ec i e slo e i i io<br />
This method returns <strong>the</strong>val ue stored by compute-slots : around (st<strong>and</strong>ard-class)<br />
<strong>and</strong> compute-slots : around(funcallable-st<strong>and</strong>ard-class).<br />
rea er et o class eneri c unct i on<br />
S<br />
reader- method-class<br />
class direct-slot res ini t args<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> di rect -sl ot argument isadi rect sl ot denitionmetaobj ect.<br />
<strong>The</strong> ini t args argument consists <strong>of</strong> alternati ng initializationargument names <strong>and</strong>val ues.
Generi c Functi ons <strong>and</strong>Methods remove-dependent 87<br />
<strong>The</strong> val ue returnedis aclass metaobj ect.<br />
P<br />
Thi s generi c function is called to determine <strong>the</strong> class <strong>of</strong> reader methods created during<br />
cl ass i nitialization<strong>and</strong>reinitialization. <strong>The</strong> result must beasubcl ass <strong>of</strong> st<strong>and</strong>ard-readermethod.<br />
<strong>The</strong> ini t args argument must be<strong>the</strong>sameaswill bepassed to ma e- i nstance to create<br />
<strong>the</strong>reader method. <strong>The</strong> ini t args must incl ude :slot-denition with sl ot - de nition as i ts<br />
val ue.<br />
M<br />
reader- method-class ri mar et hod<br />
cl ass s a ar class<br />
di rect -sl ot s a ar irec slo e i i io<br />
res ini t args<br />
reader- method-class ri mar et hod<br />
cl ass calla le s a ar class<br />
di rect -sl ot s a ar irec slo e i i io<br />
res ini t args<br />
<strong>The</strong>se methods return <strong>the</strong> class st<strong>and</strong>ard-reader-method.<br />
overridden.<br />
<strong>The</strong>se methods can be<br />
re o e e en ent eneri c unct i on<br />
S<br />
remove- dependent<br />
met aobj ect de endent<br />
A<br />
<strong>The</strong> met aobj ect argument isaclassorgeneri c functi on metaobj ect.<br />
<strong>The</strong> de endent argument i s an obj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s unspeci ed.<br />
P<br />
Thi s generi c functi on removes de endent from<strong>the</strong>dependents <strong>of</strong> met aobj ect. If de endent<br />
is not one <strong>of</strong><strong>the</strong>dependents <strong>of</strong> met aobj ect, noerrorissignal ed.<br />
<strong>The</strong> generi c functi on map-dependents can be cal l ed to access <strong>the</strong> set <strong>of</strong> dependents<br />
<strong>of</strong> a cl ass or generi c functi on. <strong>The</strong> generi c functi on add-dependent can be calledto add<br />
an obj ect f rom<strong>the</strong> set <strong>of</strong> dependents <strong>of</strong> a cl ass or generi c functi on. <strong>The</strong> eect <strong>of</strong> calling
88 remove-dependent Chapter 6<br />
add-dependent or remove-dependent while a call to map-dependents on <strong>the</strong> same<br />
classorgeneri c functionis inprogress i s unspeci ed.<br />
<strong>The</strong> situati ons inwhichremove- dependent is calledare not speci ed.<br />
M<br />
remove- dependent ri mar et hod<br />
cl ass s a ar class de endent<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-dependent (st<strong>and</strong>ard-class t)<br />
map-dependents (st<strong>and</strong>ard-class t)<br />
remove- dependent ri mar et hod<br />
cl ass calla le s a ar class de endent<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-dependent (funcallable-st<strong>and</strong>ard-class t)<br />
map-dependents (funcallable-st<strong>and</strong>ard-class t)<br />
remove- dependent ri mar et hod<br />
generi c- unct i on s a ar e eric c io de endent<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-dependent (st<strong>and</strong>ard-generi c- f uncti ont)<br />
map-dependents (st<strong>and</strong>ard-generic-functi ont)<br />
R<br />
See <strong>the</strong>\Dependent Mai ntenance <strong>Protocol</strong>" sectionfor remarks about <strong>the</strong>use <strong>of</strong> this facility.
Generi c Functi ons <strong>and</strong>Methods remove-di rect-method 89<br />
re o e irect et o eneri c unct i on<br />
S<br />
remove- di rect- method<br />
s eci al i er met hod<br />
A<br />
<strong>The</strong> s eci al i er argument isaspeci al i zer metaobj ect.<br />
<strong>The</strong> met hod argument isamethod metaobj ect.<br />
<strong>The</strong> val ue returned by remove-di rect- method is unspeci ed.<br />
P<br />
Thi s generi c functionis calledto mai ntai n a set <strong>of</strong> backpoi nters froma speci al i zer to <strong>the</strong><br />
set <strong>of</strong> methods speci al i zed to i t. If met hod is in<strong>the</strong> set it is removed. If it is not, no error<br />
is signal ed.<br />
Thi s set can be accessed as a list by calling<strong>the</strong>generi c functi on speci alizer-directmethods.<br />
Methods areadded to <strong>the</strong>setby add-di rect- method.<br />
<strong>The</strong> generi c functi on remove- di rect- method is calledby remove- method whenever<br />
amethod i s removed fromageneri c functi on. Itiscalledonce f or each <strong>of</strong> <strong>the</strong> speci al i zers <strong>of</strong><br />
<strong>the</strong>method. ote that i n cases where a speci al i zer appears more than once i n<strong>the</strong>speci al i zers<br />
<strong>of</strong> a method, thi s generi c functi on will be calledmore than once with<strong>the</strong>samespeci al i zer<br />
as argument.<br />
<strong>The</strong> results are undened i f <strong>the</strong> s eci al i er argument isnot one <strong>of</strong><strong>the</strong>speci al i zers <strong>of</strong> <strong>the</strong><br />
met hod argument.<br />
M<br />
remove- di rect- method ri mar et hod<br />
s eci al i er class<br />
met hod me o<br />
This method i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functi on f or cl ass speci al i zers. o<br />
behavior is speci ed for this method beyond that which is speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-di rect- method(class method)<br />
speci alizer-di rect- generi c- f uncti ons (class)<br />
speci alizer-di rect- methods (class)
90 remove-di rect-subcl ass Chapter 6<br />
remove- di rect- method ri mar et hod<br />
s eci al i er e l speciali er<br />
met hod me o<br />
This method i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong>generi c functi on for eql speci al i zers. o<br />
behavior is speci ed for this method beyond that which is speci ed for <strong>the</strong> generi c<br />
functi on.<br />
re o e irect su class eneri c unct i on<br />
S<br />
remove- direct-subcl ass<br />
su ercl ass subcl ass<br />
A<br />
<strong>The</strong> su ercl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> subcl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s unspeci ed.<br />
P<br />
Thi s generi c functionis calledto mai ntai n a set <strong>of</strong> backpoi nters froma class to its di rect<br />
subclasses. It removes subcl ass from<strong>the</strong> set <strong>of</strong> di rect subclasses <strong>of</strong> su ercl ass. o error is<br />
signal ed i f subcl ass is not i n this set.<br />
Whenever a class is reinitialized, thi s generi c functionis calledonce wi<strong>the</strong>achdel eted<br />
di rect supercl ass <strong>of</strong> <strong>the</strong> class.<br />
M<br />
remove- direct-subcl ass ri mar et hod<br />
su ercl ass class<br />
subcl ass class<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-direct-subcl ass (class class)<br />
cl ass-direct-subcl asses (class)
Generi c Functi ons <strong>and</strong>Methods remove-method 91<br />
re o e et o eneri c unct i on<br />
S<br />
remove- method<br />
generi c- unct i on met hod<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> met hod argument isamethod metaobj ect.<br />
<strong>The</strong> generi c- unct i on argument isreturned.<br />
P<br />
Thi s generi c functionbreaks<strong>the</strong> associationbetween a generi c functi on <strong>and</strong>one<strong>of</strong>itsmethods.<br />
o error is signal ed i f <strong>the</strong> method i s not among <strong>the</strong>methods <strong>of</strong><strong>the</strong>generi c functi on.<br />
Breaking<strong>the</strong> association between <strong>the</strong> method <strong>and</strong> <strong>the</strong>generi c functi on proceeds infour<br />
steps: (i) remove met hod from<strong>the</strong> set returned by generic-functi on-methods <strong>and</strong>arrange<br />
for method-generic-functi on to return nil; (ii) call remove-di rect- method f or each<br />
<strong>of</strong> <strong>the</strong> method's specializers; (iii) call compute-di scri minating-functi on <strong>and</strong> install its<br />
result with set-funcallable-instance-f uncti on; <strong>and</strong>(iv) update <strong>the</strong> dependents <strong>of</strong> <strong>the</strong><br />
generi c functi on.<br />
<strong>The</strong> generi c functi on remove- methodcan be calledby<strong>the</strong>user or <strong>the</strong>implementation.<br />
M<br />
remove- method ri mar et hod<br />
generi c- unct i on s a ar e eric c io<br />
met hod s a ar me o<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
set uncalla le instance uncti on unct i on<br />
S<br />
set-funcallable-instance-f uncti on<br />
uncal l abl e- i nstance unct i on<br />
A<br />
<strong>The</strong> uncal l abl e- i nstance argument isafuncallable instance (i t must have been returned by<br />
allocate-instance (f uncallable-st<strong>and</strong>ard-class)).<br />
<strong>The</strong> unct i on argument isafuncti on.
92 (setf generi c-functi on-name) Chapter 6<br />
<strong>The</strong> val ue returned bythis functi on i s unspeci ed.<br />
P<br />
This functi on i s cal l ed to set or to change <strong>the</strong> functi on <strong>of</strong> a funcallable instance. After<br />
set-funcallable-instance-f uncti on is called, anysubsequent calls to uncal l abl e- i nstance<br />
will run<strong>the</strong>newfuncti on.<br />
set class na e unct i on<br />
S<br />
(setf class-name) eneri c unct i on<br />
ne -name class<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> ne -name argument isanyLi sp obj ect.<br />
R<br />
This functi on returnsits ne<br />
-name argument.<br />
P<br />
This functi on changes <strong>the</strong> name <strong>of</strong> cl ass to ne -name. This val ue isusuallya symbol , or<br />
nil if <strong>the</strong>classhas no name.<br />
This functi on works bycalling rei nitialize-instance with cl ass as i ts rst argument,<br />
<strong>the</strong>symbol :name as i ts secondargument <strong>and</strong> ne -name as i ts thirdargument.<br />
set eneric uncti on na e unct i on<br />
S<br />
(setf generi c- f uncti on-name) eneri c unct i on<br />
ne -name generi c- unct i on<br />
A<br />
<strong>The</strong> generi c- unct i on argument i s a generi c functi on metaobj ect.<br />
<strong>The</strong> ne -name argument isafuncti on name ornil.<br />
R<br />
This functi on returnsits ne<br />
-name argument.
Generi c Functi ons <strong>and</strong>Methods (setf slot-val ue-using- cl ass) 93<br />
P<br />
This functi on changes <strong>the</strong> name <strong>of</strong> generi c- unct i on to ne -name. This val ue isusually<br />
afuncti on name (i.e., a symbol or a l i st <strong>of</strong> <strong>the</strong> f orm(setf s mbol )) ornil, if <strong>the</strong>generi c<br />
functi on i s to have noname.<br />
This functi on works bycalling rei nitialize-instance withgeneri c- unct i on as i ts rst<br />
argument, <strong>the</strong>symbol :name as i ts secondargument <strong>and</strong> ne -name as i ts thirdargument.<br />
set sl ot alue usi n class eneri c unct i on<br />
S<br />
(setf slot-value- usi ng-class)<br />
ne - al ue cl ass object sl ot<br />
A<br />
<strong>The</strong> ne<br />
- al ue argument i s an obj ect.<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect. I t i s <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument.<br />
<strong>The</strong> obj ect argument i s an obj ect.<br />
<strong>The</strong> sl ot argument isaneecti ve slotdenitionmetaobj ect.<br />
Thi s generi c functi on returns<strong>the</strong> ne<br />
- al ue argument.<br />
P<br />
<strong>The</strong> generi c functi on (setf slot-value-using-class) implements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong> (setf<br />
slot-value) functi on. It is calledby (setf slot-value) with<strong>the</strong>class<strong>of</strong>obj ect as i ts second<br />
argument <strong>and</strong><strong>the</strong>pertinent eecti ve slotdenitionmetaobj ect as i ts f ourth argument.<br />
<strong>The</strong> generi c functi on(setf slot-value- using-class) sets <strong>the</strong>val ue containedi n<strong>the</strong>given<br />
sl ot <strong>of</strong> <strong>the</strong> given object to <strong>the</strong> given newval ue; anypreviousval ue is lost.<br />
<strong>The</strong> results are undened i f <strong>the</strong> cl ass argument isnot <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument,<br />
or i f <strong>the</strong> sl ot argument does not appear among <strong>the</strong> set <strong>of</strong> eecti ve slots associated with<strong>the</strong><br />
cl ass argument.
94 slot-boundp-using- cl ass Chapter 6<br />
M<br />
(setf slot-value- usi ng-class) ri mar et hod<br />
ne - al ue<br />
cl ass s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
(setf slot-value- usi ng-class) ri mar et hod<br />
ne - al ue<br />
cl ass calla le s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
<strong>The</strong>se methods implement<strong>the</strong>full behavior <strong>of</strong> thi s generi c functi on f or sl ots withallocation<br />
:instance <strong>and</strong> :class. If <strong>the</strong>suppliedslot has an al l ocati on o<strong>the</strong>r than :instance<br />
or :class an error is signal ed.<br />
Overriding<strong>the</strong>se methods ispermitted,but mayrequire overridingo<strong>the</strong>r methods in<br />
<strong>the</strong> st<strong>and</strong>ard i mplementation<strong>of</strong> <strong>the</strong> sl ot access protocol.<br />
(setf slot-value- usi ng-class) ri mar et hod<br />
ne - al ue<br />
cl ass il i class<br />
obj ect<br />
sl ot<br />
This method si gnals an error.<br />
sl ot oun usi n class eneri c unct i on<br />
S<br />
slot-boundp-usi ng-class<br />
cl ass obj ect sl ot<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect. I t i s <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument.<br />
<strong>The</strong> obj ect argument i s an obj ect.<br />
<strong>The</strong> sl ot argument isaneecti ve slotdenitionmetaobj ect.<br />
Thi s generi c functi on returns true or f al se.
Generi c Functi ons <strong>and</strong>Methods slot-denition- ::: 95<br />
P<br />
Thi s generi c functi on i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong> slot-boundpfuncti on. It is calledby<br />
slot-boundp with<strong>the</strong>class<strong>of</strong> obj ect as i ts rst argument <strong>and</strong><strong>the</strong>pertinent eecti ve slot<br />
denitionmetaobj ect as i ts thirdargument.<br />
<strong>The</strong> generi c functi on slot-boundp-using-class tests whe<strong>the</strong>r a speci c slotinaninstance<br />
i s bound.<br />
<strong>The</strong> results are undened i f <strong>the</strong> cl ass argument isnot <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument,<br />
or i f <strong>the</strong> sl ot argument does not appear among <strong>the</strong> set <strong>of</strong> eecti ve slots associated with<strong>the</strong><br />
cl ass argument.<br />
M<br />
slot-boundp-usi ng-class ri mar et hod<br />
cl ass s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
slot-boundp-usi ng-class ri mar et hod<br />
cl ass calla le s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
<strong>The</strong>se methods implement<strong>the</strong>full behavior <strong>of</strong> thi s generi c functi on f or sl ots withallocation<br />
:instance <strong>and</strong> :class. If <strong>the</strong>suppliedslot has an al l ocati on o<strong>the</strong>r than :instance<br />
or :class an error is signal ed.<br />
Overriding<strong>the</strong>se methods ispermitted,but mayrequire overridingo<strong>the</strong>r methods in<br />
<strong>the</strong> st<strong>and</strong>ard i mplementation<strong>of</strong> <strong>the</strong> sl ot access protocol.<br />
slot-boundp-usi ng-class ri mar et hod<br />
cl ass il i class<br />
obj ect<br />
sl ot<br />
This method si gnals an error.<br />
R<br />
In cases where <strong>the</strong> classmetaobj ect cl ass does not distinguishunbound slots, trueshould<br />
be returned.<br />
sl ot e nition eneri c unct i on<br />
<strong>The</strong> following generi c functi ons are descri bed toge<strong>the</strong>r under \Readers f or Slot Definition<br />
Metaobj ects" (page 83): slot-denition-allocation, slot-denition-initargs,
96 slot-makunbound-using- cl ass Chapter 6<br />
slot-denition-initform, slot-denition-initfuncti on, slot-denition-location, slotdenition-name,<br />
slot-denition-readers, slot-denition-writers <strong>and</strong> slot-denitiontype.<br />
sl ot a un oun usi n class eneri c unct i on<br />
S<br />
slot-ma unbound-using-class<br />
cl ass obj ect sl ot<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect. I t i s <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument.<br />
<strong>The</strong> obj ect argument i s an obj ect.<br />
<strong>The</strong> sl ot argument isaneecti ve slotdenitionmetaobj ect.<br />
Thi s generi c functi on returnsits obj ect argument.<br />
P<br />
Thi s generi c functi on i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong> slot-ma unbound functi on. It is<br />
calledby slot-ma unboundwith<strong>the</strong>class<strong>of</strong>obj ect as i ts rst argument<strong>and</strong><strong>the</strong>pertinent<br />
eecti ve slotdenitionmetaobj ect as i ts thirdargument.<br />
<strong>The</strong> generi c functi on slot-ma unbound-usi ng-class restores a slot in an object to its<br />
unboundstate. <strong>The</strong> interpretation<strong>of</strong> \restoringaslottoitsunboundstate" depends on<strong>the</strong><br />
cl ass metaobj ect cl ass.<br />
<strong>The</strong> results are undened i f <strong>the</strong> cl ass argument isnot <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument,<br />
or i f <strong>the</strong> sl ot argument does not appear among <strong>the</strong> set <strong>of</strong> eecti ve slots associated with<strong>the</strong><br />
cl ass argument.<br />
M<br />
slot-ma unbound-using-class ri mar et hod<br />
cl ass s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
slot-ma unbound-using-class ri mar et hod<br />
cl ass calla le s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
<strong>The</strong>se methods implement<strong>the</strong>full behavior <strong>of</strong> thi s generi c functi on f or sl ots withallocation<br />
:instance <strong>and</strong> :class. If <strong>the</strong>suppliedslot has an al l ocati on o<strong>the</strong>r than :instance<br />
or :class an error is signal ed.
Generi c Functi ons <strong>and</strong>Methods slot-val ue-using- cl ass 97<br />
Overriding<strong>the</strong>se methods ispermitted,but mayrequire overridingo<strong>the</strong>r methods in<br />
<strong>the</strong> st<strong>and</strong>ard i mplementation<strong>of</strong> <strong>the</strong> sl ot access protocol.<br />
slot-ma unbound-using-class ri mar et hod<br />
cl ass il i class<br />
obj ect<br />
sl ot<br />
This method si gnals an error.<br />
sl ot alue usi n class eneri c unct i on<br />
S<br />
slot-value- using-class<br />
cl ass obj ect sl ot<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect. I t i s <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument.<br />
<strong>The</strong> obj ect argument i s an obj ect.<br />
<strong>The</strong> sl ot argument isaneecti ve slotdenitionmetaobj ect.<br />
<strong>The</strong> val ue returned bythi s generi c functi on i s an object.<br />
P<br />
Thi s generi c functi on i mplements <strong>the</strong>behavior <strong>of</strong> <strong>the</strong> slot-value functi on. It is calledby<br />
slot-value with <strong>the</strong> class <strong>of</strong> obj ect as i ts rst argument <strong>and</strong><strong>the</strong> pertinent eecti ve slot<br />
denitionmetaobj ect as i ts thirdargument.<br />
<strong>The</strong> generi c functi on slot-value- using-class returns <strong>the</strong>val ue contained i n <strong>the</strong> given<br />
sl ot <strong>of</strong> <strong>the</strong> given object. If <strong>the</strong> slotisunbound slot-unbound is called.<br />
<strong>The</strong> results are undened i f <strong>the</strong> cl ass argument isnot <strong>the</strong> class <strong>of</strong> <strong>the</strong> obj ect argument,<br />
or i f <strong>the</strong> sl ot argument does not appear among <strong>the</strong> set <strong>of</strong> eecti ve slots associated with<strong>the</strong><br />
cl ass argument.
98 speci al i zer-di rect-generi c-functi ons Chapter 6<br />
M<br />
slot-value- using-class ri mar et hod<br />
cl ass s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
slot-value- using-class ri mar et hod<br />
cl ass calla le s a ar class<br />
obj ect<br />
sl ot s a ar e ec i e slo e i i io<br />
<strong>The</strong>se methods implement<strong>the</strong>full behavior <strong>of</strong> thi s generi c functi on f or sl ots withallocation<br />
:instance <strong>and</strong> :class. If <strong>the</strong>suppliedslot has an al l ocati on o<strong>the</strong>r than :instance<br />
or :class an error is signal ed.<br />
Overriding<strong>the</strong>se methods ispermitted,but mayrequire overridingo<strong>the</strong>r methods in<br />
<strong>the</strong> st<strong>and</strong>ard i mplementation<strong>of</strong> <strong>the</strong> sl ot access protocol.<br />
slot-value- using-class ri mar et hod<br />
cl ass il i class<br />
obj ect<br />
sl ot<br />
This method si gnals an error.<br />
s ecializer irect eneric uncti ons eneri c unct i on<br />
S<br />
speci alizer-di rect-generi c- f uncti ons<br />
s eci al i er<br />
A<br />
<strong>The</strong> s eci al i er argument isaspeci al i zer metaobj ect.<br />
<strong>The</strong> result <strong>of</strong> thi s generi c functi on i s a possiblyemptylist <strong>of</strong> generi c functi on metaobj ects.<br />
P<br />
Thi s generi c functi on returns<strong>the</strong>possiblyempty set <strong>of</strong> those generi c functi ons whichhave<br />
amethod with s eci al i er as a speci al i zer. <strong>The</strong> elements <strong>of</strong> this set are generi c functi on<br />
metaobj ects. This val ue ismai ntained by<strong>the</strong>generi c functi ons add-di rect- method <strong>and</strong><br />
remove- di rect- method.
Generi c Functi ons <strong>and</strong>Methods speci al i zer-di rect-methods 99<br />
M<br />
speci alizer-di rect-generi c- f uncti ons ri mar et hod<br />
s eci al i er class<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:<br />
add-di rect- method(class method)<br />
remove-di rect- method(class method)<br />
speci alizer-di rect- methods (class)<br />
speci alizer-di rect-generi c- f uncti ons ri mar et hod<br />
s eci al i er e l speciali er<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
s ecializer irect et o s eneri c unct i on<br />
S<br />
speci alizer-di rect-methods<br />
s eci al i er<br />
A<br />
<strong>The</strong> s eci al i er argument isaspeci al i zer metaobj ect.<br />
<strong>The</strong> result <strong>of</strong> thi s generi c functi on i s a possiblyemptylist <strong>of</strong> method metaobj ects.<br />
P<br />
Thi s generi c functi on returns<strong>the</strong>possiblyemptyset <strong>of</strong> those methods, connected to generi c<br />
functi ons, which have s eci al i er as a speci al i zer. <strong>The</strong> elements <strong>of</strong> this set are method<br />
metaobj ects. This val ue ismai ntained by<strong>the</strong>generi c functi ons add-di rect- method <strong>and</strong><br />
remove- di rect- method.<br />
M<br />
speci alizer-di rect-methods ri mar et hod<br />
s eci al i er class<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
This method cannot be overridden unless <strong>the</strong> followingmethods are overridden as<br />
well:
100 st<strong>and</strong>ard-instance-access Chapter 6<br />
add-di rect- method(class method)<br />
remove-di rect- method(class method)<br />
speci alizer-di rect- generi c- f uncti ons (class)<br />
speci alizer-di rect-methods ri mar et hod<br />
s eci al i er e l speciali er<br />
obehavior is speci ed for this method beyond that whichis speci ed for <strong>the</strong> generi c<br />
functi on.<br />
stan ar instance access unct i on<br />
S<br />
st<strong>and</strong>ard-instance-access<br />
instance l ocation<br />
A<br />
<strong>The</strong> instance argument i s an obj ect.<br />
<strong>The</strong> locat i on argument is a slot location.<br />
<strong>The</strong> result <strong>of</strong> this functi on i s an object.<br />
P<br />
This functionis calledto providedi rect access to a sl ot i n an i nstance. By usurping<strong>the</strong><br />
normal sl ot l ookupprotocol, this functi on i s i ntended to providehighlyoptimi zed access to<br />
<strong>the</strong> slots associated withaninstance.<br />
<strong>The</strong> following restrictionsapply to <strong>the</strong>use <strong>of</strong> this functi on:<br />
<strong>The</strong> instance argument must be a st<strong>and</strong>ard i nstance (i t must have been returned by<br />
allocate-instance (st<strong>and</strong>ard-class)).<br />
<strong>The</strong> instance argument cannot be annon-updated obsolete instance.<br />
<strong>The</strong> locat i on argument must be a l ocati on <strong>of</strong> one <strong>of</strong><strong>the</strong>di rectl y accessi bl e sl ots <strong>of</strong> <strong>the</strong><br />
instance' s cl ass.<br />
<strong>The</strong> slotmust bebound.<br />
<strong>The</strong> results are undened i f any<strong>of</strong> <strong>the</strong>se restrictionsarenot met.
Generi c Functi ons <strong>and</strong>Methods update- dependent 101<br />
u ate e en ent eneri c unct i on<br />
S<br />
update-dependent<br />
met aobj ect de endent res ini t args<br />
A<br />
<strong>The</strong> met aobj ect argument is a class or generi c functi on metaobj ect. It is <strong>the</strong>metaobj ect<br />
bei ngreinitializedor o<strong>the</strong>rwise modied.<br />
<strong>The</strong> de endent argument isanobject. Itis<strong>the</strong>dependent bei ngupdated.<br />
<strong>The</strong> ini t args argument isalist<strong>of</strong><strong>the</strong>initializationarguments for <strong>the</strong>metaobj ect redenition.<br />
<strong>The</strong> val ue returned by update-dependent is unspeci ed.<br />
P<br />
Thi s generi c functionis calledtoupdate a dependent <strong>of</strong> met aobj ect.<br />
When a cl ass or a generi c functi on i s rei nitializedeach<strong>of</strong> its dependents is updated. <strong>The</strong><br />
ini t args argument toupdate-dependent is <strong>the</strong>set<strong>of</strong>initializationarguments recei ved by<br />
rei nitialize-instance.<br />
When a method i s added to a generi c functi on, each<strong>of</strong><strong>the</strong>generi c functi on's dependents<br />
is updated. <strong>The</strong> ini t args argument isalist<strong>of</strong>twoelements: <strong>the</strong>symbol add-method, <strong>and</strong><br />
<strong>the</strong>method that was added.<br />
When a method i s removed f roma generi c functi on, each <strong>of</strong> <strong>the</strong> generi c functi on's dependents<br />
is updated. <strong>The</strong> ini t args argument isalist<strong>of</strong>twoelements: <strong>the</strong>symbol removemethod,<br />
<strong>and</strong><strong>the</strong>method that was removed.<br />
In each case, map-dependents is used to cal l update-dependent on each <strong>of</strong> <strong>the</strong><br />
dependents. So, f or example, <strong>the</strong>update <strong>of</strong> a generi c functi on's dependents when a method<br />
is added couldbeperformed by<strong>the</strong> followingcode:<br />
map epe e s generi c- unct i on<br />
lam a ep<br />
p a e epe e generi c- unct i on<br />
ep<br />
a me o<br />
ne -met hod<br />
M<br />
<strong>The</strong>re are nospeci ed methods onthi s generi c functi on.<br />
R<br />
See <strong>the</strong>\Dependent Mai ntenance <strong>Protocol</strong>" sectionfor remarks about <strong>the</strong>use <strong>of</strong> this facility.
102 validate- supercl ass Chapter 6<br />
ali ate su erclass eneri c unct i on<br />
S<br />
validate-supercl ass<br />
cl ass su ercl ass<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> su ercl ass argument isaclassmetaobj ect.<br />
Thi s generi c functi on returns true or f al se.<br />
P<br />
Thi s generi c functionis calledtodeterminewhe<strong>the</strong>r <strong>the</strong> classsu ercl ass is suitable for use<br />
as a supercl ass <strong>of</strong> cl ass.<br />
Thi s generi c functi on can be be calledby<strong>the</strong>implementationor user code. It is called<br />
duringclass metaobj ect i nitialization<strong>and</strong>reinitialization,bef ore <strong>the</strong> di rect superclasses are<br />
stored. If thi s generi c functi on returns f al se, <strong>the</strong> initializationor reinitializationwill signal<br />
an error.<br />
M<br />
validate-supercl ass ri mar et hod<br />
cl ass class<br />
su ercl ass class<br />
This method returns trueinthree situati ons:<br />
(i) If <strong>the</strong> su ercl ass argument is<strong>the</strong>classnamed ,<br />
(ii) if <strong>the</strong> class <strong>of</strong> <strong>the</strong> cl ass argument is<strong>the</strong>sameas<strong>the</strong> class <strong>of</strong> <strong>the</strong> su ercl ass<br />
argument or<br />
(iii) if <strong>the</strong> classes one<strong>of</strong><strong>the</strong>arguments is st<strong>and</strong>ard-class <strong>and</strong><strong>the</strong> class <strong>of</strong> <strong>the</strong><br />
o<strong>the</strong>r i s funcallable-st<strong>and</strong>ard-class.<br />
In all o<strong>the</strong>r cases, this method returns f al se.<br />
This method can be overridden.<br />
R<br />
Deningamethod on validate-supercl ass requires detailedknowledge <strong>of</strong> <strong>of</strong> <strong>the</strong> internal<br />
protocol followed by each <strong>of</strong> <strong>the</strong> twoclass metaobj ect cl asses. Amethod on validatesupercl<br />
ass whichreturns truefortwodierent classmetaobj ect cl asses decl ares that <strong>the</strong>y<br />
are compati ble.
Generi c Functi ons <strong>and</strong>Methods writer-method-class 103<br />
riter et o class eneri c unct i on<br />
S<br />
wri ter-method-class<br />
class direct-slot res ini t args<br />
A<br />
<strong>The</strong> cl ass argument isaclassmetaobj ect.<br />
<strong>The</strong> di rect -sl ot argument isadi rect sl ot denitionmetaobj ect.<br />
<strong>The</strong> ini t args argument isalist<strong>of</strong>initializationarguments <strong>and</strong>val ues.<br />
<strong>The</strong> val ue returnedis aclass metaobj ect.<br />
P<br />
Thi s generi c function is called to determine <strong>the</strong> cl ass <strong>of</strong> writer methods created during<br />
cl ass i nitialization<strong>and</strong>reinitialization. <strong>The</strong> result must beasubcl ass <strong>of</strong> st<strong>and</strong>ard-writermethod.<br />
<strong>The</strong> ini t args argument must be<strong>the</strong>sameaswill bepassed to ma e- i nstance to create<br />
<strong>the</strong>reader method. <strong>The</strong> ini t args must incl ude :slot-denition with sl ot - de nition as i ts<br />
val ue.<br />
M<br />
wri ter-method-class ri mar et hod<br />
cl ass s a ar class<br />
di rect -sl ot s a ar irec slo e i i io<br />
res ini t args<br />
wri ter-method-class ri mar et hod<br />
cl ass calla le s a ar class<br />
di rect -sl ot s a ar irec slo e i i io<br />
res ini t args<br />
<strong>The</strong>se methods returns <strong>the</strong> class st<strong>and</strong>ard-writer-method.<br />
overridden.<br />
<strong>The</strong>se methods can be
104
o<br />
[CLtLII] Steel e, Guy ommon is he anguage SecondEdition,Digital Press, 1990.<br />
[X3J13] Bobrow, Daniel G. Linda G. Demichiel, Richard P. Gabriel, Sonya E. Keene,<br />
Gregor Ki czal es, <strong>and</strong>DavidA. Moon ommon is bj ect stem eci cat i on<br />
X3J13 Document 88- 002R, June 1988; appears i n is <strong>and</strong> mbol i c om utation<br />
1, 3 4, January 1989, 245 394, <strong>and</strong> as Chapter 28 <strong>of</strong> [CLtLII ] , 770 864.<br />
105