My various dotfiles

chap-7.texi 224KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988
  1. @node Objects, Structures, Iteration, Top
  2. @chapter Objects
  3. @menu
  4. * Object Creation and Initialization::
  5. * Changing the Class of an Instance::
  6. * Reinitializing an Instance::
  7. * Meta-Objects::
  8. * Slots::
  9. * Generic Functions and Methods::
  10. * Objects Dictionary::
  11. @end menu
  12. @node Object Creation and Initialization, Changing the Class of an Instance, Objects, Objects
  13. @section Object Creation and Initialization
  14. @c including concept-objects
  15. The @i{generic function} @b{make-instance} creates and returns a new
  16. @i{instance} of a @i{class}. The first argument is a @i{class} or
  17. the @i{name} of a @i{class}, and the remaining arguments form an
  18. @i{initialization argument list}
  19. @IGindex{initialization argument list}
  20. .
  21. The initialization of a new @i{instance} consists of several distinct
  22. steps, including the following: combining the explicitly supplied initialization
  23. arguments with default values for the unsupplied initialization arguments,
  24. checking the validity of the initialization arguments, allocating storage
  25. for the @i{instance}, filling @i{slots} with
  26. values, and executing user-supplied @i{methods} that perform additional
  27. initialization. Each step of @b{make-instance} is implemented by a
  28. @i{generic function} to provide a mechanism for customizing that step.
  29. In addition, @b{make-instance} is itself a @i{generic function}
  30. and thus also can be customized.
  31. The object system specifies system-supplied primary @i{methods} for each step
  32. and thus specifies a well-defined standard behavior for the entire
  33. initialization process. The standard behavior provides four simple
  34. mechanisms for controlling initialization:
  35. @table @asis
  36. @item @t{*}
  37. Declaring a @i{symbol} to be an initialization argument
  38. for a @i{slot}. An initialization argument is declared by using the
  39. @t{:initarg} slot option to @b{defclass}. This provides a mechanism
  40. for supplying a value for a @i{slot} in a call to @b{make-instance}.
  41. @item @t{*}
  42. Supplying a default value form for an initialization argument.
  43. Default value forms for initialization arguments are defined by using the
  44. @t{:default-initargs} class option to @b{defclass}. If an
  45. initialization argument is not explicitly provided
  46. as an argument to @b{make-instance}, the default value form is
  47. evaluated in the lexical environment of the @b{defclass} form that
  48. defined it, and the resulting value is used as the value of the
  49. initialization argument.
  50. @item @t{*}
  51. Supplying a default initial value form for a @i{slot}.
  52. A default initial value form for a @i{slot} is defined by using the
  53. @t{:initform} slot option to @b{defclass}. If no initialization
  54. argument associated with that @i{slot} is given as an argument to
  55. @b{make-instance} or is defaulted by @t{:default-initargs}, this
  56. default initial value form is evaluated in the lexical environment of
  57. the @b{defclass} form that defined it, and the resulting value is
  58. stored in the @i{slot}. The @t{:initform} form for a
  59. @i{local slot} may be used when creating an @i{instance}, when
  60. updating an @i{instance} to conform to a redefined @i{class},
  61. or when updating an @i{instance} to conform to the definition of a
  62. different @i{class}. The @t{:initform} form for a
  63. @i{shared slot} may be used when defining or re-defining the @i{class}.
  64. @item @t{*}
  65. Defining @i{methods} for @b{initialize-instance} and
  66. @b{shared-initialize}. The slot-filling behavior described above is
  67. implemented by a system-supplied primary @i{method} for
  68. @b{initialize-instance} which invokes @b{shared-initialize}. The
  69. @i{generic function} @b{shared-initialize} implements the parts of
  70. initialization shared by these four situations: when making an @i{instance},
  71. when re-initializing an @i{instance}, when updating an @i{instance}
  72. to conform to a redefined @i{class}, and when updating an @i{instance}
  73. to conform to the definition of a different @i{class}. The system-supplied
  74. primary @i{method} for @b{shared-initialize} directly implements the
  75. slot-filling behavior described above, and @b{initialize-instance}
  76. simply invokes @b{shared-initialize}.
  77. @end table
  78. @menu
  79. * Initialization Arguments::
  80. * Declaring the Validity of Initialization Arguments::
  81. * Defaulting of Initialization Arguments::
  82. * Rules for Initialization Arguments::
  83. * Shared-Initialize::
  84. * Initialize-Instance::
  85. * Definitions of Make-Instance and Initialize-Instance::
  86. @end menu
  87. @node Initialization Arguments, Declaring the Validity of Initialization Arguments, Object Creation and Initialization, Object Creation and Initialization
  88. @subsection Initialization Arguments
  89. An initialization argument controls @i{object} creation and
  90. initialization. It is often convenient to use keyword @i{symbols}
  91. to name initialization arguments, but the @i{name} of an
  92. initialization argument can be any @i{symbol}, including @b{nil}. An
  93. initialization argument can be used in two ways: to fill a @i{slot}
  94. with a value or to provide an argument for an initialization
  95. @i{method}. A single initialization argument can be used for both
  96. purposes.
  97. An @i{initialization argument list} is a
  98. @i{property list} of
  99. initialization argument names and values.
  100. Its structure is identical
  101. to a @i{property list} and also
  102. to the portion of an argument list
  103. processed for @b{&key} parameters.
  104. As in those lists,
  105. if an initialization
  106. argument name appears more than once in an initialization argument list,
  107. the leftmost occurrence supplies the value and the remaining occurrences
  108. are ignored. The arguments to @b{make-instance} (after the first
  109. argument) form an @i{initialization argument list}.
  110. An initialization argument can be associated with a @i{slot}. If
  111. the initialization argument has a value in the @i{initialization
  112. argument list}, the value is stored into the @i{slot} of the newly
  113. created @i{object}, overriding any @t{:initform} form associated
  114. with the @i{slot}. A single initialization argument can initialize
  115. more than one @i{slot}. An initialization argument that initializes
  116. a @i{shared slot} stores its value into the @i{shared slot},
  117. replacing any previous value.
  118. An initialization argument can be associated with a @i{method}. When
  119. an @i{object} is created and a particular initialization argument is
  120. supplied, the @i{generic functions} @b{initialize-instance},
  121. @b{shared-initialize}, and @b{allocate-instance} are called
  122. with that initialization argument's name and value as a keyword argument
  123. pair. If a value for the initialization argument is not supplied in the
  124. @i{initialization argument list}, the @i{method}'s
  125. @i{lambda list} supplies a default value.
  126. Initialization arguments are used in four situations: when making an
  127. @i{instance}, when re-initializing an @i{instance}, when updating
  128. an @i{instance} to conform to a redefined @i{class}, and when
  129. updating an @i{instance} to conform to the definition of a different
  130. @i{class}.
  131. Because initialization arguments are used to control the creation and
  132. initialization of an @i{instance} of some particular @i{class},
  133. we say that an initialization argument is
  134. ``an initialization argument for'' that @i{class}.
  135. @node Declaring the Validity of Initialization Arguments, Defaulting of Initialization Arguments, Initialization Arguments, Object Creation and Initialization
  136. @subsection Declaring the Validity of Initialization Arguments
  137. Initialization arguments are checked for validity in each of the four
  138. situations that use them. An initialization argument may be valid in
  139. one situation and not another. For example, the system-supplied
  140. primary @i{method} for @b{make-instance} defined for
  141. the @i{class} @b{standard-class} checks the validity of its initialization arguments
  142. and signals an error if an initialization argument is supplied that is
  143. not declared as valid in that situation.
  144. There are two means for declaring initialization arguments valid.
  145. @table @asis
  146. @item @t{*}
  147. Initialization arguments that fill @i{slots} are declared as valid
  148. by the @t{:initarg} slot option to @b{defclass}. The
  149. @t{:initarg} slot option is inherited from @i{superclasses}. Thus
  150. the set of valid initialization arguments that fill @i{slots} for a
  151. @i{class} is the union of the initialization arguments that fill
  152. @i{slots} declared as valid by that @i{class} and its
  153. @i{superclasses}. Initialization arguments that fill @i{slots}
  154. are valid in all four contexts.
  155. @item @t{*}
  156. Initialization arguments that supply arguments to @i{methods} are
  157. declared as valid by defining those @i{methods}. The keyword name of
  158. each keyword parameter specified in the @i{method}'s
  159. @i{lambda list} becomes an initialization argument for all @i{classes}
  160. for which the @i{method} is applicable.
  161. The presence of {&allow-other-keys} in the
  162. @i{lambda list} of an applicable method disables validity checking of
  163. initialization arguments.
  164. Thus @i{method} inheritance
  165. controls the set of valid initialization arguments that supply arguments
  166. to @i{methods}. The @i{generic functions} for which @i{method}
  167. definitions serve to declare initialization arguments valid are as
  168. follows:
  169. @table @asis
  170. @item --
  171. Making an @i{instance} of a @i{class}:
  172. @b{allocate-instance}, @b{initialize-instance}, and
  173. @b{shared-initialize}. Initialization arguments declared as valid
  174. by these @i{methods} are valid when making
  175. an @i{instance} of a @i{class}.
  176. @item --
  177. Re-initializing an @i{instance}:
  178. @b{reinitialize-instance} and @b{shared-initialize}.
  179. Initialization arguments declared as valid by these @i{methods} are
  180. valid when re-initializing an @i{instance}.
  181. @item --
  182. Updating an @i{instance} to conform to a redefined @i{class}:
  183. @b{update-instance-for-redefined-class} and @b{shared-initialize}.
  184. Initialization arguments declared as valid by these @i{methods} are
  185. valid when updating an @i{instance} to conform to a redefined @i{class}.
  186. @item --
  187. Updating an @i{instance} to conform to the definition of a
  188. different @i{class}:
  189. @b{update-instance-for-different-class} and @b{shared-initialize}.
  190. Initialization arguments declared as valid by these @i{methods} are
  191. valid when updating an @i{instance} to conform to the definition
  192. of a different @i{class}.
  193. @end table
  194. @end table
  195. The set of valid initialization arguments for a @i{class} is the set of
  196. valid initialization arguments that either fill @i{slots} or supply
  197. arguments to @i{methods}, along with the predefined initialization
  198. argument @t{:allow-other-keys}. The default value for
  199. @t{:allow-other-keys} is @b{nil}.
  200. Validity checking of initialization arguments is disabled if the value of
  201. the initialization argument @t{:allow-other-keys} is @i{true}.
  202. @node Defaulting of Initialization Arguments, Rules for Initialization Arguments, Declaring the Validity of Initialization Arguments, Object Creation and Initialization
  203. @subsection Defaulting of Initialization Arguments
  204. A default value @i{form} can be supplied for an initialization
  205. argument by using the @t{:default-initargs} @i{class} option. If an
  206. initialization argument is declared valid by some particular @i{class},
  207. its default value form might be specified by a different @i{class}.
  208. In this case @t{:default-initargs} is used to supply a default value
  209. for an inherited initialization argument.
  210. The @t{:default-initargs} option is used only to provide default
  211. values for initialization arguments; it does not declare a @i{symbol}
  212. as a valid initialization argument name. Furthermore,
  213. the @t{:default-initargs} option is used only to provide default values for
  214. initialization arguments when making an @i{instance}.
  215. The argument to the @t{:default-initargs} class
  216. option is a list of
  217. alternating initialization argument names and @i{forms}.
  218. Each @i{form} is the
  219. default value form for the corresponding initialization
  220. argument. The default value @i{form} of an initialization
  221. argument is used and evaluated only if that initialization argument
  222. does not appear in the arguments to @b{make-instance} and is not
  223. defaulted by a more specific @i{class}. The default value @i{form} is
  224. evaluated in the lexical environment of the @b{defclass} form that
  225. supplied it; the resulting value is used as the initialization
  226. argument's value.
  227. The initialization arguments supplied to @b{make-instance} are combined
  228. with defaulted initialization arguments to produce a
  229. @i{defaulted initialization argument list}. A
  230. @i{defaulted initialization argument list}
  231. is a list of alternating initialization argument names and
  232. values in which unsupplied initialization arguments are defaulted and in
  233. which the explicitly supplied initialization arguments appear earlier in
  234. the list than the defaulted initialization arguments. Defaulted
  235. initialization arguments are ordered according to the order in the
  236. @i{class precedence list} of the @i{classes} that supplied the default values.
  237. There is a distinction between the purposes of the
  238. @t{:default-initargs} and the @t{:initform} options with respect to the
  239. initialization of @i{slots}. The @t{:default-initargs}
  240. class option
  241. provides a mechanism for the user to give a default value @i{form}
  242. for an initialization argument without knowing whether the
  243. initialization argument initializes a @i{slot}
  244. or is passed to a @i{method}.
  245. If that initialization argument is not explicitly supplied in a call
  246. to @b{make-instance}, the default value @i{form} is used, just
  247. as if it had been supplied in the call. In contrast, the
  248. @t{:initform} slot option provides a mechanism for the user to give a
  249. default initial value form for a @i{slot}. An @t{:initform} form is
  250. used to initialize a @i{slot} only if no initialization argument
  251. associated with that @i{slot} is given as an argument to
  252. @b{make-instance} or is defaulted by @t{:default-initargs}.
  253. @ITindex{order of evaluation}
  254. @ITindex{evaluation order}
  255. The order of evaluation of default value @i{forms} for initialization
  256. arguments and the order of evaluation of @t{:initform} forms are
  257. undefined. If the order of evaluation is important,
  258. @b{initialize-instance} or @b{shared-initialize} @i{methods}
  259. should be used
  260. instead.
  261. @node Rules for Initialization Arguments, Shared-Initialize, Defaulting of Initialization Arguments, Object Creation and Initialization
  262. @subsection Rules for Initialization Arguments
  263. The @t{:initarg} slot option may be specified more than
  264. once for a given @i{slot}.
  265. The following rules specify when initialization arguments may be
  266. multiply defined:
  267. @table @asis
  268. @item @t{*}
  269. A given initialization argument can be used to
  270. initialize more than one @i{slot} if the same initialization argument name
  271. appears in more than one @t{:initarg} slot option.
  272. @item @t{*}
  273. A given initialization argument name can appear
  274. in the @i{lambda list} of more than one initialization @i{method}.
  275. @item @t{*}
  276. A given initialization argument name can
  277. appear both in an @t{:initarg} slot option and
  278. in the @i{lambda list}
  279. of an initialization @i{method}.
  280. @end table
  281. [Reviewer Note by The next three paragraphs could be replaced by ``If two or more
  282. initialization arguments that initialize the same slot appear in the
  283. @i{defaulted initialization argument list}, the leftmost of these supplies
  284. the value, even if they have different names.'' And the rest would follow
  285. from the rules above.]
  286. If two or more initialization arguments that initialize the same
  287. @i{slot} are given in the arguments to @b{make-instance}, the
  288. leftmost of these initialization arguments in the @i{initialization
  289. argument list} supplies the value, even if the initialization arguments
  290. have different names.
  291. If two or more different initialization arguments that initialize the
  292. same @i{slot} have default values and none is given explicitly in the
  293. arguments to @b{make-instance}, the initialization argument that
  294. appears in a @t{:default-initargs} class option in the most specific
  295. of the @i{classes} supplies the value. If a single
  296. @t{:default-initargs} class option specifies two or more initialization
  297. arguments that initialize the same @i{slot} and none is given
  298. explicitly in the arguments to @b{make-instance}, the leftmost in
  299. the @t{:default-initargs} class option supplies the value, and the
  300. values of the remaining default value @i{forms} are ignored.
  301. Initialization arguments given explicitly in the arguments to
  302. @b{make-instance} appear to the left of defaulted initialization
  303. arguments. Suppose that the classes C_1 and C_2 supply the
  304. values of defaulted initialization arguments for different @i{slots},
  305. and suppose that C_1 is more specific than C_2; then the
  306. defaulted initialization argument whose value is supplied by C_1
  307. is to the left of the defaulted initialization argument whose value is
  308. supplied by C_2 in the @i{defaulted initialization argument
  309. list}. If a single @t{:default-initargs} class option supplies the
  310. values of initialization arguments for two different @i{slots}, the
  311. initialization argument whose value is specified farther to the left in
  312. the @t{:default-initargs} class option appears farther to the left in
  313. the @i{defaulted initialization argument list}.
  314. [Reviewer Note by Barmar: End of claim made three paragraphs back.]
  315. If a @i{slot} has both an @t{:initform} form and an
  316. @t{:initarg} slot option, and the initialization argument is defaulted
  317. using @t{:default-initargs} or is supplied to @b{make-instance},
  318. the captured @t{:initform} form is neither used nor evaluated.
  319. The following is an example of the above rules:
  320. @example
  321. (defclass q () ((x :initarg a)))
  322. (defclass r (q) ((x :initarg b))
  323. (:default-initargs a 1 b 2))
  324. @end example
  325. @center
  326. @example
  327. @group
  328. @noindent
  329. @w{ {} Defaulted {} }
  330. @w{ Form Initialization Argument List Contents of Slot X }
  331. @w{ _____________________________________________________________________________}
  332. @w{ @t{(make-instance 'r)} @t{(a 1 b 2)} @t{1} }
  333. @w{ @t{(make-instance 'r 'a 3)} @t{(a 3 b 2)} @t{3} }
  334. @w{ @t{(make-instance 'r 'b 4)} @t{(b 4 a 1)} @t{4} }
  335. @w{ @t{(make-instance 'r 'a 1 'a 2)} @t{(a 1 a 2 b 2)} @t{1} }
  336. @end group
  337. @end example
  338. @node Shared-Initialize, Initialize-Instance, Rules for Initialization Arguments, Object Creation and Initialization
  339. @subsection Shared-Initialize
  340. The @i{generic function} @b{shared-initialize} is used to fill the
  341. @i{slots}
  342. of an @i{instance}
  343. using initialization arguments and @t{:initform}
  344. forms when an @i{instance} is created, when an
  345. @i{instance} is re-initialized,
  346. when an @i{instance}
  347. is updated to conform to a redefined @i{class}, and when
  348. an @i{instance} is updated to conform to a different @i{class}.
  349. It uses
  350. standard @i{method} combination. It takes the following arguments: the
  351. @i{instance} to be initialized, a
  352. specification of a set of @i{names} of @i{slots}
  353. @i{accessible} in that @i{instance}, and any number of initialization
  354. arguments. The arguments after the first two must form an
  355. @i{initialization argument list}.
  356. The second argument to @b{shared-initialize} may be one of the following:
  357. @table @asis
  358. @item @t{*}
  359. It can be a (possibly empty) @i{list} of @i{slot} names,
  360. which specifies the set of those @i{slot} names.
  361. @item @t{*}
  362. It can be the symbol @b{t}, which specifies the set of all of the @i{slots}.
  363. @end table
  364. There is a system-supplied primary @i{method} for @b{shared-initialize}
  365. whose first @i{parameter specializer} is the @i{class} @b{standard-object}.
  366. This @i{method} behaves as follows on each @i{slot},
  367. whether shared or local:
  368. @table @asis
  369. @item @t{*}
  370. If an initialization argument in the
  371. @i{initialization argument list} specifies a value for that @i{slot},
  372. that value is stored
  373. into the @i{slot}, even if a value has already been stored in the @i{slot}
  374. before the @i{method} is run.
  375. The affected @i{slots} are independent of which
  376. @i{slots} are indicated by the second argument to @b{shared-initialize}.
  377. @item @t{*}
  378. Any @i{slots}
  379. indicated by the second argument that are still
  380. unbound at this point are initialized according to their
  381. @t{:initform} forms. For any such @i{slot}
  382. that has an @t{:initform} form,
  383. that @i{form} is evaluated in the
  384. lexical environment of its defining
  385. @b{defclass} form and the result is stored into the @i{slot}.
  386. For example,
  387. if a @i{before method} stores a value in the
  388. @i{slot}, the @t{:initform} form will not be used to supply a value
  389. for the @i{slot}. If
  390. the second argument specifies a @i{name} that does not correspond to any
  391. @i{slots} @i{accessible}
  392. in the @i{instance}, the results are unspecified.
  393. @item @t{*}
  394. The rules mentioned in @ref{Rules for Initialization Arguments} are obeyed.
  395. @end table
  396. The generic function @b{shared-initialize} is called by the
  397. system-supplied primary @i{methods}
  398. for @b{reinitialize-instance},
  399. @b{update-instance-for-different-class},
  400. @b{update-instance-for-redefined-class}, and
  401. @b{initialize-instance}. Thus, @i{methods} can be written for
  402. @b{shared-initialize} to specify actions that should be taken in all of
  403. these contexts.
  404. @node Initialize-Instance, Definitions of Make-Instance and Initialize-Instance, Shared-Initialize, Object Creation and Initialization
  405. @subsection Initialize-Instance
  406. The @i{generic function} @b{initialize-instance} is called by
  407. @b{make-instance} to initialize a newly created @i{instance}.
  408. It uses @i{standard method combination}. @i{Methods} for
  409. @b{initialize-instance} can be defined in order to perform any
  410. initialization that cannot be achieved
  411. simply by supplying initial values for @i{slots}.
  412. During initialization, @b{initialize-instance} is invoked
  413. after the following actions have been taken:
  414. @table @asis
  415. @item @t{*}
  416. The @i{defaulted initialization argument list}
  417. has been computed by combining the supplied @i{initialization argument list}
  418. with any default initialization arguments for the @i{class}.
  419. @item @t{*}
  420. The validity of the @i{defaulted initialization argument list}
  421. has been checked. If any of the initialization arguments has not
  422. been declared as valid, an error is signaled.
  423. @item @t{*}
  424. A new @i{instance} whose @i{slots}
  425. are unbound has been created.
  426. @end table
  427. The generic function @b{initialize-instance} is called with the
  428. new @i{instance} and the defaulted initialization arguments. There is
  429. a system-supplied primary @i{method} for @b{initialize-instance}
  430. whose @i{parameter specializer} is the @i{class} @b{standard-object}. This
  431. @i{method} calls the generic function
  432. @b{shared-initialize} to fill in
  433. the @i{slots} according to the initialization arguments and the
  434. @t{:initform} forms for the @i{slots}; the generic function
  435. @b{shared-initialize} is called with the following arguments: the @i{instance},
  436. @b{t}, and the defaulted initialization arguments.
  437. Note that @b{initialize-instance} provides the
  438. @i{defaulted initialization argument list} in its call to @b{shared-initialize},
  439. so the first step performed by the system-supplied primary @i{method} for
  440. @b{shared-initialize} takes into account both the initialization
  441. arguments provided in the call to @b{make-instance} and the
  442. @i{defaulted initialization argument list}.
  443. @i{Methods} for @b{initialize-instance} can be defined to specify
  444. actions to be taken when an @i{instance} is initialized.
  445. If only @i{after methods} for @b{initialize-instance} are defined, they will be
  446. run after the system-supplied primary @i{method} for initialization and
  447. therefore will not interfere with the default behavior of
  448. @b{initialize-instance}.
  449. The object system provides two @i{functions} that are useful in the bodies of
  450. @b{initialize-instance} methods. The @i{function} @b{slot-boundp}
  451. returns a @i{generic boolean} value that indicates whether a specified @i{slot} has a
  452. value; this provides a mechanism for writing @i{after methods} for
  453. @b{initialize-instance} that initialize @i{slots} only if they have
  454. not already been initialized. The @i{function} @b{slot-makunbound}
  455. causes the @i{slot} to have no value.
  456. @node Definitions of Make-Instance and Initialize-Instance, , Initialize-Instance, Object Creation and Initialization
  457. @subsection Definitions of Make-Instance and Initialize-Instance
  458. The generic function @b{make-instance} behaves as if it were defined as
  459. follows, except that certain optimizations are permitted:
  460. @example
  461. (defmethod make-instance ((class standard-class) &rest initargs)
  462. ...
  463. (let ((instance (apply #'allocate-instance class initargs)))
  464. (apply #'initialize-instance instance initargs)
  465. instance))
  466. (defmethod make-instance ((class-name symbol) &rest initargs)
  467. (apply #'make-instance (find-class class-name) initargs))
  468. @end example
  469. The elided code in the definition of @b{make-instance}
  470. augments the @t{initargs} with any @i{defaulted initialization arguments} and
  471. checks the
  472. resulting
  473. initialization arguments to determine whether an initialization
  474. argument was supplied that neither filled a @i{slot} nor supplied an argument
  475. to an applicable @i{method}.
  476. The generic function @b{initialize-instance} behaves as if it were
  477. defined as follows, except that certain optimizations are permitted:
  478. @example
  479. (defmethod initialize-instance ((instance standard-object) &rest initargs)
  480. (apply #'shared-initialize instance t initargs)))
  481. @end example
  482. These procedures can be customized.
  483. Customizing at the Programmer Interface level includes using the
  484. @t{:initform}, @t{:initarg}, and @t{:default-initargs} options to
  485. @b{defclass}, as well as defining @i{methods}
  486. for @b{make-instance},
  487. @b{allocate-instance},
  488. and @b{initialize-instance}. It is also possible to define
  489. @i{methods} for @b{shared-initialize}, which would be invoked by the
  490. generic functions @b{reinitialize-instance},
  491. @b{update-instance-for-redefined-class},
  492. @b{update-instance-for-different-class}, and
  493. @b{initialize-instance}.
  494. The meta-object level supports additional
  495. customization.
  496. Implementations are permitted to make certain optimizations to
  497. @b{initialize-instance} and @b{shared-initialize}.
  498. The description of @b{shared-initialize} in Chapter~7 mentions the
  499. possible optimizations.
  500. @c end of including concept-objects
  501. @node Changing the Class of an Instance, Reinitializing an Instance, Object Creation and Initialization, Objects
  502. @section Changing the Class of an Instance
  503. @c including concept-change-class
  504. The @i{function} @b{change-class} can be used to change the @i{class}
  505. of an @i{instance} from its current class, C_@{{from}@},
  506. to a different class, C_@{{to}@}; it changes the
  507. structure of the @i{instance} to conform to the definition of the class
  508. C_@{{to}@}.
  509. Note that changing the @i{class} of an @i{instance} may cause
  510. @i{slots} to be added or deleted. Changing the @i{class} of an
  511. @i{instance} does not change its identity as defined by the
  512. @b{eq} function.
  513. When @b{change-class} is invoked on an @i{instance}, a two-step
  514. updating process takes place. The first step modifies the structure of
  515. the @i{instance} by adding new @i{local slots} and discarding
  516. @i{local slots} that are not specified in the new version of the @i{instance}.
  517. The second step initializes the newly added @i{local slots} and performs
  518. any other user-defined actions. These two steps are further described in the
  519. two following sections.
  520. @menu
  521. * Modifying the Structure of the Instance::
  522. * Initializing Newly Added Local Slots (Changing the Class of an Instance)::
  523. * Customizing the Change of Class of an Instance::
  524. @end menu
  525. @node Modifying the Structure of the Instance, Initializing Newly Added Local Slots (Changing the Class of an Instance), Changing the Class of an Instance, Changing the Class of an Instance
  526. @subsection Modifying the Structure of the Instance
  527. In order to make the @i{instance} conform to the class C_@{{to}@}, @i{local slots} specified by the class C_@{{to}@} that are not specified by the class C_@{{from}@} are added, and @i{local slots} not specified by
  528. the class C_@{{to}@} that are specified by the
  529. class C_@{{from}@} are discarded.
  530. The values of @i{local slots} specified by both the class C_@{{to}@} and the class C_@{{from}@} are retained. If such a @i{local slot} was unbound, it remains
  531. unbound.
  532. The values of @i{slots} specified as shared in the class C_@{{from}@} and as local in the class C_@{{to}@} are retained.
  533. This first step of the update does not affect the values of any
  534. @i{shared slots}.
  535. @node Initializing Newly Added Local Slots (Changing the Class of an Instance), Customizing the Change of Class of an Instance, Modifying the Structure of the Instance, Changing the Class of an Instance
  536. @subsection Initializing Newly Added Local Slots
  537. The second step of the update initializes the newly added @i{slots} and
  538. performs any other user-defined actions. This step is implemented by
  539. the generic function @b{update-instance-for-different-class}. The
  540. generic function @b{update-instance-for-different-class} is invoked
  541. by @b{change-class} after the first step of the update has been
  542. completed.
  543. The generic function @b{update-instance-for-different-class} is
  544. invoked on arguments computed by @b{change-class}.
  545. The first argument passed is a copy of the @i{instance} being updated
  546. and is an @i{instance} of the class C_@{{from}@};
  547. this copy has @i{dynamic extent} within the generic function @b{change-class}.
  548. The second argument is the @i{instance} as updated so far by @b{change-class}
  549. and is an @i{instance} of the class C_@{{to}@}.
  550. The remaining arguments are an @i{initialization argument list}.
  551. There is a system-supplied primary @i{method} for
  552. @b{update-instance-for-different-class} that has two parameter
  553. specializers, each of which is the @i{class} @b{standard-object}. First
  554. this @i{method} checks the validity of initialization arguments and
  555. signals an error if an initialization argument is supplied that is not
  556. declared as valid. (For more information, see @ref{Declaring the Validity of Initialization Arguments}.)
  557. Then it calls the
  558. generic function @b{shared-initialize} with the following arguments:
  559. the
  560. new
  561. @i{instance}, a list of @i{names} of the newly added
  562. @i{slots}, and the
  563. initialization arguments it received.
  564. @node Customizing the Change of Class of an Instance, , Initializing Newly Added Local Slots (Changing the Class of an Instance), Changing the Class of an Instance
  565. @subsection Customizing the Change of Class of an Instance
  566. @i{Methods} for @b{update-instance-for-different-class} may be defined
  567. to specify actions to be taken when an @i{instance} is updated. If only
  568. @i{after methods} for @b{update-instance-for-different-class} are
  569. defined, they will be run after the system-supplied primary @i{method} for
  570. initialization and will not interfere with the default behavior of
  571. @b{update-instance-for-different-class}.
  572. @i{Methods}
  573. for @b{shared-initialize} may be defined to customize @i{class}
  574. redefinition. For more information, see @ref{Shared-Initialize}.
  575. @c end of including concept-change-class
  576. @node Reinitializing an Instance, Meta-Objects, Changing the Class of an Instance, Objects
  577. @section Reinitializing an Instance
  578. @c including concept-reinit
  579. The generic function @b{reinitialize-instance} may be used to change
  580. the values of @i{slots} according to initialization arguments.
  581. The process of reinitialization changes the values of some @i{slots} and
  582. performs any user-defined actions. It does not modify the structure
  583. of an @i{instance} to add or delete @i{slots},
  584. and it does not use any @t{:initform} forms to initialize @i{slots}.
  585. The generic function @b{reinitialize-instance} may be called
  586. directly. It takes one required argument, the @i{instance}. It also
  587. takes any number of initialization arguments to be used by @i{methods} for
  588. @b{reinitialize-instance} or for @b{shared-initialize}. The
  589. arguments after the required @i{instance} must form an
  590. @i{initialization argument list}.
  591. There is a system-supplied primary @i{method} for
  592. @b{reinitialize-instance} whose @i{parameter specializer} is
  593. the @i{class} @b{standard-object}. First this @i{method} checks the validity of
  594. initialization arguments and signals an error if an initialization
  595. argument is supplied that is not declared as valid.
  596. (For more information, see @ref{Declaring the Validity of Initialization Arguments}.)
  597. Then it calls the generic function
  598. @b{shared-initialize} with the following arguments: the @i{instance},
  599. @b{nil}, and the initialization arguments it received.
  600. @menu
  601. * Customizing Reinitialization::
  602. @end menu
  603. @node Customizing Reinitialization, , Reinitializing an Instance, Reinitializing an Instance
  604. @subsection Customizing Reinitialization
  605. @i{Methods} for @b{reinitialize-instance} may be defined to specify
  606. actions to be taken when an @i{instance} is updated. If only
  607. @i{after methods} for @b{reinitialize-instance} are defined,
  608. they will be run after the system-supplied primary @i{method} for
  609. initialization and therefore will not interfere with the default behavior of
  610. @b{reinitialize-instance}.
  611. @i{Methods} for @b{shared-initialize} may be defined to customize
  612. @i{class} redefinition. For more information, see @ref{Shared-Initialize}.
  613. @c end of including concept-reinit
  614. @node Meta-Objects, Slots, Reinitializing an Instance, Objects
  615. @section Meta-Objects
  616. @c including concept-meta-objects
  617. The implementation of the object system manipulates @i{classes}, @i{methods},
  618. and @i{generic functions}. The object system contains a set of
  619. @i{generic functions} defined by @i{methods} on @i{classes};
  620. the behavior of those @i{generic functions} defines the behavior of
  621. the object system. The @i{instances} of the @i{classes} on which those
  622. @i{methods} are defined are called meta-objects.
  623. @menu
  624. * Standard Meta-objects::
  625. @end menu
  626. @node Standard Meta-objects, , Meta-Objects, Meta-Objects
  627. @subsection Standard Meta-objects
  628. The object system supplies a set of meta-objects, called standard meta-objects.
  629. These include the @i{class} @b{standard-object} and
  630. @i{instances} of the classes @b{standard-method},
  631. @b{standard-generic-function}, and @b{method-combination}.
  632. @table @asis
  633. [Editorial Note by KMP: This is said redundantly in the definition of STANDARD-METHOD.]
  634. @item @t{*}
  635. The @i{class} @b{standard-method} is the default @i{class} of
  636. @i{methods} defined by the
  637. @b{defmethod} and
  638. @b{defgeneric} @i{forms}.
  639. @item @t{*}
  640. The @i{class} @b{standard-generic-function} is the default @i{class} of
  641. @i{generic functions} defined by the forms
  642. @b{defmethod},
  643. @b{defgeneric},
  644. and
  645. @b{defclass}.
  646. @item @t{*}
  647. The @i{class} named @b{standard-object}
  648. is an @i{instance} of the @i{class} @b{standard-class}
  649. and is a @i{superclass} of every @i{class} that is an
  650. @i{instance} of @b{standard-class} except itself and
  651. @b{structure-class}.
  652. @item @t{*}
  653. Every @i{method} combination object is
  654. an @i{instance} of a @i{subclass} of @i{class} @b{method-combination}.
  655. @end table
  656. @c end of including concept-meta-objects
  657. @node Slots, Generic Functions and Methods, Meta-Objects, Objects
  658. @section Slots
  659. @c including concept-slots
  660. @menu
  661. * Introduction to Slots::
  662. * Accessing Slots::
  663. * Inheritance of Slots and Slot Options::
  664. @end menu
  665. @node Introduction to Slots, Accessing Slots, Slots, Slots
  666. @subsection Introduction to Slots
  667. An @i{object} of @i{metaclass} @b{standard-class} has zero or more named
  668. @i{slots}. The @i{slots} of an @i{object} are determined
  669. by the @i{class} of the @i{object}. Each @i{slot} can hold
  670. one value.
  671. [Reviewer Note by Barmar: All symbols are valid variable names. Perhaps this means
  672. to preclude the use of named constants? We have a terminology
  673. problem to solve.]
  674. The @i{name} of a @i{slot} is a @i{symbol} that is syntactically
  675. valid for use as a variable name.
  676. When a @i{slot} does not have a value, the @i{slot} is said to be
  677. @i{unbound}. When an unbound @i{slot} is read,
  678. [Reviewer Note by Barmar: from an object whose metaclass is standard-class?]
  679. the @i{generic function} @b{slot-unbound} is invoked. The
  680. system-supplied primary @i{method}
  681. for @b{slot-unbound}
  682. on @i{class} @b{t} signals an error.
  683. If @b{slot-unbound} returns, its @i{primary value}
  684. is used that time as the @i{value} of the @i{slot}.
  685. The default initial value form for a @i{slot} is defined by
  686. the @t{:initform} slot option. When the @t{:initform} form is used to
  687. supply a value, it is evaluated in the lexical environment in which
  688. the @b{defclass} form was evaluated. The @t{:initform} along with
  689. the lexical environment in which the @b{defclass} form was evaluated
  690. is called a @i{captured initialization form}.
  691. For more details, see @ref{Object Creation and Initialization}.
  692. A @i{local slot} is defined to be a @i{slot} that is
  693. @i{accessible}
  694. to exactly one @i{instance},
  695. namely the one in which the @i{slot} is allocated.
  696. A @i{shared slot} is defined to be a @i{slot} that is visible to more than one
  697. @i{instance} of a given @i{class} and its @i{subclasses}.
  698. A @i{class} is said to define a @i{slot} with a given @i{name} when
  699. the @b{defclass} form for that @i{class} contains a @i{slot specifier} with
  700. that @i{name}. Defining a @i{local slot} does not immediately create
  701. a @i{slot}; it causes a @i{slot} to be created each time
  702. an @i{instance} of the @i{class} is created.
  703. Defining a @i{shared slot} immediately creates a @i{slot}.
  704. The @t{:allocation} slot option to @b{defclass} controls the kind
  705. of @i{slot} that is defined. If the value of the @t{:allocation} slot
  706. option is @t{:instance}, a @i{local slot} is created. If the value of
  707. @t{:allocation} is @t{:class}, a @i{shared slot} is created.
  708. A @i{slot} is said to be @i{accessible} in an @i{instance}
  709. of a @i{class} if
  710. the @i{slot} is defined by the @i{class}
  711. of the @i{instance} or is inherited from
  712. a @i{superclass} of that @i{class}.
  713. At most one @i{slot} of a given @i{name} can be
  714. @i{accessible} in an @i{instance}.
  715. A @i{shared slot} defined by a @i{class} is
  716. @i{accessible} in all @i{instances}
  717. of that @i{class}.
  718. A detailed explanation of the inheritance of @i{slots} is given in
  719. @ref{Inheritance of Slots and Slot Options}.
  720. @node Accessing Slots, Inheritance of Slots and Slot Options, Introduction to Slots, Slots
  721. @subsection Accessing Slots
  722. @i{Slots} can be @i{accessed} in two ways: by use of the primitive function
  723. @b{slot-value} and by use of @i{generic functions} generated by
  724. the @b{defclass} form.
  725. The @i{function} @b{slot-value} can be used with any of the @i{slot}
  726. names specified in the @b{defclass} form to @i{access} a specific
  727. @i{slot} @i{accessible} in an @i{instance} of the given @i{class}.
  728. The macro @b{defclass} provides syntax for generating @i{methods} to
  729. read and write @i{slots}. If a reader @i{method} is requested,
  730. a @i{method} is automatically generated for reading the value of the
  731. @i{slot}, but no @i{method} for storing a value into it is generated.
  732. If a writer @i{method} is requested, a @i{method} is automatically
  733. generated for storing a value into the @i{slot}, but no @i{method}
  734. for reading its value is generated. If an accessor @i{method} is
  735. requested, a @i{method} for reading the value of the @i{slot} and a
  736. @i{method} for storing a value into the @i{slot} are automatically
  737. generated. Reader and writer @i{methods} are implemented using
  738. @b{slot-value}.
  739. When a reader or writer @i{method} is specified for a @i{slot}, the
  740. name of the @i{generic function} to which the generated @i{method}
  741. belongs is directly specified. If the @i{name} specified for the writer
  742. @i{method} is the symbol @t{name}, the @i{name} of the
  743. @i{generic function} for writing the @i{slot} is the symbol
  744. @t{name}, and the @i{generic function} takes two arguments: the new
  745. value and the @i{instance}, in that order. If the @i{name} specified
  746. for the accessor @i{method} is the symbol @t{name}, the @i{name} of
  747. the @i{generic function} for reading the @i{slot} is the symbol
  748. @t{name}, and the @i{name} of the @i{generic function} for writing
  749. the @i{slot} is the list @t{(setf name)}.
  750. A @i{generic function} created or modified by supplying @t{:reader},
  751. @t{:writer}, or @t{:accessor} @i{slot} options can be treated exactly
  752. as an ordinary @i{generic function}.
  753. Note that @b{slot-value} can be used to read or write the value of a
  754. @i{slot} whether or not reader or writer @i{methods} exist for that
  755. @i{slot}. When @b{slot-value} is used, no reader or writer
  756. @i{methods} are invoked.
  757. The macro @b{with-slots} can be used to establish a
  758. @i{lexical environment} in which specified @i{slots} are lexically
  759. available as if they were variables. The macro @b{with-slots}
  760. invokes the @i{function} @b{slot-value} to @i{access} the specified @i{slots}.
  761. The macro @b{with-accessors} can be used to establish a lexical
  762. environment in which specified @i{slots} are lexically available through
  763. their accessors as if they were variables. The macro @b{with-accessors}
  764. invokes the appropriate accessors to @i{access} the specified @i{slots}.
  765. @node Inheritance of Slots and Slot Options, , Accessing Slots, Slots
  766. @subsection Inheritance of Slots and Slot Options
  767. The set of the @i{names} of all @i{slots} @i{accessible}
  768. in an @i{instance} of a @i{class} C is the union of
  769. the sets of @i{names} of @i{slots} defined by C and its
  770. @i{superclasses}. The structure of an @i{instance} is
  771. the set of @i{names} of @i{local slots} in that @i{instance}.
  772. In the simplest case, only one @i{class} among C and its @i{superclasses}
  773. defines a @i{slot} with a given @i{slot} name.
  774. If a @i{slot} is defined by a @i{superclass} of C,
  775. the @i{slot} is said to be inherited. The characteristics
  776. of the @i{slot} are determined by the @i{slot specifier}
  777. of the defining @i{class}.
  778. Consider the defining @i{class} for
  779. a slot S. If the value of the @t{:allocation}
  780. slot
  781. option is @t{:instance}, then S is a @i{local slot} and each
  782. @i{instance}
  783. of C has its own @i{slot} named S that stores its own value. If the
  784. value of the @t{:allocation} slot
  785. option is @t{:class}, then S
  786. is a @i{shared slot}, the @i{class}
  787. that defined S stores the value, and all
  788. @i{instances} of C can @i{access} that single @i{slot}.
  789. If the @t{:allocation} slot option is omitted, @t{:instance} is used.
  790. In general, more than one @i{class} among C and its
  791. @i{superclasses} can
  792. define a @i{slot} with a given @i{name}.
  793. In such cases, only one @i{slot} with
  794. the given name is @i{accessible} in an @i{instance}
  795. of C, and
  796. the characteristics of that @i{slot} are
  797. a combination of the several @i{slot}
  798. specifiers, computed as follows:
  799. @table @asis
  800. @item @t{*}
  801. All the @i{slot specifiers} for a given @i{slot} name
  802. are ordered from most specific to least specific, according to the order in C's
  803. @i{class precedence list} of the @i{classes} that define them. All references
  804. to the specificity of @i{slot specifiers} immediately below refers to this
  805. ordering.
  806. @item @t{*}
  807. The allocation of a @i{slot} is controlled by the most
  808. specific @i{slot specifier}. If the most specific @i{slot specifier}
  809. does not contain an @t{:allocation} slot option, @t{:instance} is used.
  810. Less specific @i{slot specifiers} do not affect the allocation.
  811. @item @t{*}
  812. The default initial value form for a @i{slot}
  813. is the value of the @t{:initform} slot option in the most specific
  814. @i{slot specifier} that contains one. If no @i{slot specifier}
  815. contains an @t{:initform} slot option, the @i{slot}
  816. has no default initial value form.
  817. @item @t{*}
  818. The contents of a @i{slot} will always be of type
  819. @t{(and T_1 ... T_n)} where T_1 ... T_n are
  820. the values of the @t{:type} slot options contained in all of the
  821. @i{slot specifiers}. If no @i{slot specifier} contains the
  822. @t{:type} slot option, the contents of the @i{slot} will always be
  823. of @i{type} @b{t}. The consequences of attempting to store in a @i{slot}
  824. a value that does not satisfy the @i{type} of the @i{slot} are undefined.
  825. @item @t{*}
  826. The set of initialization arguments that initialize a
  827. given @i{slot} is the union of the initialization arguments declared in
  828. the @t{:initarg} slot options in all the @i{slot specifiers}.
  829. @item @t{*}
  830. The @i{documentation string} for a @i{slot} is the value of
  831. the @t{:documentation} slot option in the most specific @i{slot}
  832. specifier that contains one. If no @i{slot specifier} contains a
  833. @t{:documentation} slot option, the @i{slot} has no @i{documentation string}.
  834. @end table
  835. A consequence of the allocation rule is that a @i{shared slot} can be
  836. @i{shadowed}. For example, if a class C_1 defines
  837. a @i{slot} named S
  838. whose value for the @t{:allocation} slot option is @t{:class},
  839. that @i{slot} is @i{accessible}
  840. in @i{instances} of C_1 and all of its
  841. @i{subclasses}. However, if C_2 is a @i{subclass}
  842. of C_1 and also
  843. defines a @i{slot} named S, C_1's
  844. @i{slot} is not shared
  845. by @i{instances} of C_2 and its @i{subclasses}. When a class
  846. C_1 defines a @i{shared slot}, any subclass C_2 of C_1 will share this single @i{slot}
  847. unless the @b{defclass} form for
  848. C_2 specifies a @i{slot} of the same
  849. @i{name} or there is a @i{superclass}
  850. of C_2 that precedes C_1 in the @i{class precedence list} of
  851. C_2 that defines a @i{slot} of the same name.
  852. A consequence of the type rule is that the value of a @i{slot}
  853. satisfies the type constraint of each @i{slot specifier} that
  854. contributes to that @i{slot}. Because the result of attempting to
  855. store in a @i{slot} a value that does not satisfy the type
  856. constraint for the @i{slot} is undefined, the value in a @i{slot}
  857. might fail to satisfy its type constraint.
  858. The @t{:reader}, @t{:writer}, and @t{:accessor} slot options
  859. create @i{methods} rather than define the characteristics of a @i{slot}.
  860. Reader and writer @i{methods} are inherited in the sense described in
  861. @ref{Inheritance of Methods}.
  862. @i{Methods} that @i{access} @i{slots} use only the name of the
  863. @i{slot} and the @i{type} of the @i{slot}'s value. Suppose
  864. a @i{superclass} provides a @i{method} that expects to @i{access} a
  865. @i{shared slot} of a given @i{name}, and a @i{subclass} defines
  866. a @i{local slot} with the same @i{name}. If the @i{method} provided
  867. by the @i{superclass} is used on an @i{instance} of the @i{subclass},
  868. the @i{method} @i{accesses} the @i{local slot}.
  869. @c end of including concept-slots
  870. @node Generic Functions and Methods, Objects Dictionary, Slots, Objects
  871. @section Generic Functions and Methods
  872. @c including concept-gfs-and-methods
  873. @menu
  874. * Introduction to Generic Functions::
  875. * Introduction to Methods::
  876. * Agreement on Parameter Specializers and Qualifiers::
  877. * Congruent Lambda-lists for all Methods of a Generic Function::
  878. * Keyword Arguments in Generic Functions and Methods::
  879. * Method Selection and Combination::
  880. * Inheritance of Methods::
  881. @end menu
  882. @node Introduction to Generic Functions, Introduction to Methods, Generic Functions and Methods, Generic Functions and Methods
  883. @subsection Introduction to Generic Functions
  884. A @i{generic function}
  885. @IGindex{generic function}
  886. is a function whose behavior depends on
  887. the @i{classes} or identities of the @i{arguments} supplied to it.
  888. A @i{generic function} @i{object}
  889. is associated with
  890. a set of @i{methods},
  891. a @i{lambda list},
  892. a @i{method combination}_2,
  893. and other information.
  894. Like an @i{ordinary function}, a @i{generic function} takes @i{arguments},
  895. performs a series of operations, and perhaps returns useful @i{values}.
  896. An @i{ordinary function} has a single body of @i{code} that is always @i{executed}
  897. when the @i{function} is called. A @i{generic function} has a set of bodies
  898. of @i{code} of which a subset is selected for @i{execution}. The selected
  899. bodies of @i{code} and the manner of their combination are determined by
  900. the @i{classes} or identities of one or more of the @i{arguments} to the
  901. @i{generic function} and by its @i{method combination}.
  902. @i{Ordinary functions} and @i{generic functions} are called with identical syntax.
  903. @i{Generic functions} are true @i{functions} that can be passed as @i{arguments}
  904. and used as the first @i{argument} to @b{funcall} and @b{apply}.
  905. A @i{binding} of a @i{function name} to a @i{generic function}
  906. can be @i{established} in one of several ways. It can be
  907. @i{established} in the @i{global environment} by
  908. @b{ensure-generic-function},
  909. @b{defmethod} (implicitly, due to @b{ensure-generic-function})
  910. or
  911. @b{defgeneric} (also implicitly, due to @b{ensure-generic-function}).
  912. No @i{standardized} mechanism is provided for @i{establishing} a
  913. @i{binding} of a @i{function name} to a @i{generic function}
  914. in the @i{lexical environment}.
  915. When a @b{defgeneric} form is evaluated, one of three actions
  916. is taken (due to @b{ensure-generic-function}):
  917. @table @asis
  918. @item @t{*}
  919. If a generic function of the given name already exists,
  920. the existing generic function object is modified. Methods specified
  921. by the current @b{defgeneric} form are added, and any methods in the
  922. existing generic function that were defined by a previous @b{defgeneric}
  923. form are removed. Methods added by the current @b{defgeneric}
  924. form might replace methods defined by @b{defmethod},
  925. @b{defclass}, @b{define-condition}, or @b{defstruct}.
  926. No other methods in the generic function are affected
  927. or replaced.
  928. @item @t{*}
  929. If the given name names
  930. an @i{ordinary function},
  931. a @i{macro},
  932. or a @i{special operator},
  933. an error is signaled.
  934. @item @t{*}
  935. Otherwise a generic function is created with the
  936. methods specified by the method definitions in the @b{defgeneric}
  937. form.
  938. @end table
  939. Some @i{operators} permit specification of the options of a
  940. @i{generic function}, such as
  941. the @i{type} of @i{method combination} it uses
  942. or its @i{argument precedence order}.
  943. These @i{operators} will be referred to as
  944. ``operators that specify generic function options.''
  945. The only @i{standardized} @i{operator} in this category is @b{defgeneric}.
  946. Some @i{operators} define @i{methods} for a @i{generic function}.
  947. These @i{operators} will be referred to as
  948. @i{method-defining operators}
  949. @IGindex{method-defining operator}
  950. ;
  951. their associated @i{forms} are called @i{method-defining forms}.
  952. The @i{standardized} @i{method-defining operators} are listed in Figure 7--2.
  953. @group
  954. @noindent
  955. @w{ defgeneric defmethod defclass }
  956. @w{ define-condition defstruct }
  957. @noindent
  958. @w{ Figure 7--2: Standardized Method-Defining Operators}
  959. @end group
  960. Note that of the @i{standardized} @i{method-defining operators}
  961. only @b{defgeneric}
  962. can specify @i{generic function} options.
  963. @b{defgeneric} and any @i{implementation-defined} @i{operators}
  964. that can specify @i{generic function} options
  965. are also referred to as ``operators that specify generic function options.''
  966. @node Introduction to Methods, Agreement on Parameter Specializers and Qualifiers, Introduction to Generic Functions, Generic Functions and Methods
  967. @subsection Introduction to Methods
  968. @i{Methods} define the class-specific or identity-specific behavior
  969. and operations of a @i{generic function}.
  970. A @i{method} @i{object}
  971. is associated with
  972. @i{code} that implements the method's behavior,
  973. a sequence of @i{parameter specializers}
  974. that specify when the given @i{method} is applicable,
  975. a @i{lambda list},
  976. and a sequence of @i{qualifiers} that are used by the method combination
  977. facility to distinguish among @i{methods}.
  978. A method object is not a function and cannot be invoked as a function.
  979. Various mechanisms in the object system take a method object and invoke its method
  980. function, as is the case when a generic function is invoked. When this
  981. occurs it is said that the method is invoked or called.
  982. A method-defining form contains the @i{code} that is to be run when the
  983. arguments to the generic function cause the method that it defines to
  984. be invoked. When a method-defining form is evaluated, a method object
  985. is created and one of four actions is taken:
  986. @table @asis
  987. @item @t{*}
  988. If a @i{generic function} of the given name already exists
  989. and if a @i{method object} already exists that agrees with the new one on
  990. @i{parameter specializers} and @i{qualifiers}, the new @i{method object} replaces
  991. the old one. For a definition of one method agreeing with another on
  992. @i{parameter specializers} and @i{qualifiers},
  993. see @ref{Agreement on Parameter Specializers and Qualifiers}.
  994. @item @t{*}
  995. If a @i{generic function} of the given name already exists
  996. and if there is no @i{method object} that agrees with the new one on
  997. @i{parameter specializers} and @i{qualifiers}, the existing @i{generic function}
  998. @i{object} is modified to contain the new @i{method} @i{object}.
  999. @item @t{*}
  1000. If the given @i{name} names an @i{ordinary function}, a @i{macro},
  1001. or a @i{special operator}, an error is signaled.
  1002. @item @t{*}
  1003. Otherwise a @i{generic function} is created with the @i{method}
  1004. specified by the @i{method-defining form}.
  1005. @end table
  1006. If the @i{lambda list} of a new @i{method} is not
  1007. @i{congruent} with the @i{lambda list} of the @i{generic function},
  1008. an error is signaled. If a @i{method-defining operator} that cannot specify
  1009. @i{generic function} options creates a new @i{generic function},
  1010. a @i{lambda list} for that @i{generic function} is derived from the
  1011. @i{lambda list} of the @i{method} in the @i{method-defining form} in such a way
  1012. as to be @i{congruent} with it. For a discussion of @i{congruence}
  1013. @IGindex{congruence}
  1014. ,
  1015. see @ref{Congruent Lambda-lists for all Methods of a Generic Function}.
  1016. Each method has a @i{specialized lambda list}, which determines
  1017. when that method can be applied. A @i{specialized lambda list} is like
  1018. an @i{ordinary lambda list} except that a specialized parameter
  1019. may occur instead of the name of a required parameter. A specialized parameter
  1020. is a list @t{(@i{variable-name} @i{parameter-specializer-name})},
  1021. where @i{parameter-specializer-name} is one of the following:
  1022. @table @asis
  1023. @item a @i{symbol}
  1024. denotes a @i{parameter specializer} which is the @i{class}
  1025. named by that @i{symbol}.
  1026. @item a @i{class}
  1027. denotes a @i{parameter specializer} which is the @i{class} itself.
  1028. @item @t{(eql @i{form})}
  1029. denotes a @i{parameter specializer} which satisfies the @i{type specifier}
  1030. @t{(eql @i{object})}, where @i{object} is the
  1031. result of evaluating @i{form}. The form @i{form} is evaluated in
  1032. the lexical environment in which the method-defining form is evaluated.
  1033. Note that @i{form} is evaluated only once, at the time the method is
  1034. defined, not each time the generic function is called.
  1035. @end table
  1036. @i{Parameter specializer names} are used in macros intended as the
  1037. user-level interface (@b{defmethod}), while @i{parameter specializers}
  1038. are used in the functional interface.
  1039. Only required parameters may be specialized, and there must be a
  1040. @i{parameter specializer} for each required parameter. For notational
  1041. simplicity, if some required parameter in a @i{specialized lambda list} in
  1042. a method-defining form is simply a variable name, its
  1043. @i{parameter specializer} defaults to the @i{class} @b{t}.
  1044. Given a generic function and a set of arguments, an applicable
  1045. method is a method for that generic function whose parameter
  1046. specializers are satisfied by their corresponding arguments. The
  1047. following definition specifies what it means for a method to be
  1048. applicable and for an argument to satisfy a @i{parameter specializer}.
  1049. Let < A_1, ..., A_n> be the required
  1050. arguments to a generic function in order. Let < P_1,
  1051. ..., P_n> be the @i{parameter specializers} corresponding to
  1052. the required parameters of the method M in order. The method M is
  1053. applicable when each A_i is of the @i{type} specified by
  1054. the @i{type specifier} P_i.
  1055. Because every valid @i{parameter specializer} is
  1056. also a valid @i{type specifier}, the @i{function} @b{typep} can be used during method
  1057. selection to determine whether an argument satisfies a @i{parameter specializer}.
  1058. A method all of whose @i{parameter specializers} are
  1059. the @i{class} @b{t} is called a @i{default method}
  1060. @IGindex{default method}
  1061. ; it is always applicable but
  1062. may be shadowed by a more specific method.
  1063. Methods can have @i{qualifiers}, which give the method combination
  1064. procedure a way to distinguish among methods. A method that has one
  1065. or more @i{qualifiers} is called a @i{qualified method}.
  1066. A method with no @i{qualifiers} is called an @i{unqualified method}.
  1067. A @i{qualifier} is any @i{non-list}.
  1068. The @i{qualifiers} defined by the @i{standardized} method combination types
  1069. are @i{symbols}.
  1070. In this specification, the terms ``@i{primary method}'' and
  1071. ``@i{auxiliary method}'' are used to partition @i{methods}
  1072. within a method combination type according to their intended use.
  1073. In standard method combination, @i{primary methods} are
  1074. @i{unqualified methods}
  1075. and @i{auxiliary methods} are methods with a single @i{qualifier}
  1076. that is one of @t{:around}, @t{:before}, or @t{:after}.
  1077. @i{Methods} with these @i{qualifiers} are called @i{around methods},
  1078. @i{before methods}, and @i{after methods}, respectively.
  1079. When a method combination type is defined using the short form of
  1080. @b{define-method-combination}, @i{primary methods} are
  1081. methods qualified with the name of the type of method combination,
  1082. and auxiliary methods have the @i{qualifier} @t{:around}.
  1083. Thus the terms ``@i{primary method}'' and ``@i{auxiliary method}''
  1084. have only a relative definition within a given method combination type.
  1085. @node Agreement on Parameter Specializers and Qualifiers, Congruent Lambda-lists for all Methods of a Generic Function, Introduction to Methods, Generic Functions and Methods
  1086. @subsection Agreement on Parameter Specializers and Qualifiers
  1087. Two @i{methods} are said to agree with each other on @i{parameter specializers}
  1088. and @i{qualifiers} if the following conditions hold:
  1089. @table @asis
  1090. @item 1.
  1091. Both methods have the same number of required parameters.
  1092. Suppose the @i{parameter specializers} of the two methods are
  1093. P_@{1,1@}... P_@{1,n@} and P_@{2,1@}... P_@{2,n@}.
  1094. @item 2.
  1095. For each 1<= i<= n, P_@{1,i@} agrees with P_@{2,i@}.
  1096. The @i{parameter specializer} P_@{1,i@} agrees with P_@{2,i@} if
  1097. P_@{1,i@} and P_@{2,i@} are the same class or if
  1098. P_@{1,i@}=@t{(@b{eql} @i{object}_1)},
  1099. P_@{2,i@}=@t{(@b{eql} @i{object}_2)}, and
  1100. @t{(@b{eql} @i{object}_1 @i{object}_2)}.
  1101. Otherwise P_@{1,i@} and P_@{2,i@} do not agree.
  1102. @item 3.
  1103. The two @i{lists} of @i{qualifiers} are the @i{same}
  1104. under @b{equal}.
  1105. @end table
  1106. @node Congruent Lambda-lists for all Methods of a Generic Function, Keyword Arguments in Generic Functions and Methods, Agreement on Parameter Specializers and Qualifiers, Generic Functions and Methods
  1107. @subsection Congruent Lambda-lists for all Methods of a Generic Function
  1108. These rules define the congruence of a set of @i{lambda lists}, including the
  1109. @i{lambda list} of each method for a given generic function and the
  1110. @i{lambda list} specified for the generic function itself, if given.
  1111. @table @asis
  1112. @item 1.
  1113. Each @i{lambda list} must have the same number of required
  1114. parameters.
  1115. @item 2.
  1116. Each @i{lambda list} must have the same number of optional
  1117. parameters. Each method can supply its own default for an optional
  1118. parameter.
  1119. @item 3.
  1120. If any @i{lambda list} mentions @b{&rest} or @b{&key}, each
  1121. @i{lambda list} must mention one or both of them.
  1122. @item 4.
  1123. If the @i{generic function} @i{lambda list}
  1124. mentions @b{&key}, each
  1125. method must accept all of the keyword names mentioned after @b{&key},
  1126. either by accepting them explicitly, by specifying @b{&allow-other-keys},
  1127. or by specifying @b{&rest} but not @b{&key}.
  1128. Each method can accept additional keyword arguments of its own. The
  1129. checking of the validity of keyword names is done in the generic
  1130. function, not in each method.
  1131. A method is invoked as if the keyword
  1132. argument pair whose name is @t{:allow-other-keys} and whose value
  1133. is @i{true} were supplied, though no such argument pair will be passed.
  1134. @item 5.
  1135. The use of @b{&allow-other-keys} need not be consistent
  1136. across @i{lambda lists}. If @b{&allow-other-keys} is mentioned in
  1137. the @i{lambda list} of any applicable @i{method} or of the @i{generic function},
  1138. any keyword arguments may be mentioned in the call to the @i{generic function}.
  1139. @item 6.
  1140. The use of @b{&aux} need not be consistent across methods.
  1141. If a @i{method-defining operator} that cannot specify @i{generic function} options
  1142. creates a @i{generic function}, and if the @i{lambda list} for the method
  1143. mentions keyword arguments, the @i{lambda list} of the generic function
  1144. will mention @b{&key} (but no keyword arguments).
  1145. @end table
  1146. @node Keyword Arguments in Generic Functions and Methods, Method Selection and Combination, Congruent Lambda-lists for all Methods of a Generic Function, Generic Functions and Methods
  1147. @subsection Keyword Arguments in Generic Functions and Methods
  1148. When a generic function or any of its methods mentions
  1149. @b{&key} in a @i{lambda list}, the specific set of keyword
  1150. arguments accepted by the generic function varies according to the
  1151. applicable methods. The set of keyword arguments accepted by the
  1152. generic function for a particular call is the union of the keyword
  1153. arguments accepted by all applicable methods and the keyword arguments
  1154. mentioned after @b{&key} in the generic function definition,
  1155. if any. A method that has @b{&rest} but not @b{&key} does not affect the
  1156. set of acceptable keyword arguments. If
  1157. the @i{lambda list} of any applicable method or of the generic
  1158. function definition contains @b{&allow-other-keys}, all
  1159. keyword arguments are accepted by the generic function.
  1160. The @i{lambda list} congruence rules require that each method
  1161. accept all of the keyword arguments mentioned after @b{&key} in the
  1162. generic function definition, by accepting them explicitly, by
  1163. specifying @b{&allow-other-keys}, or by specifying @b{&rest} but
  1164. not @b{&key}. Each method can accept additional keyword arguments
  1165. of its own, in addition to the keyword arguments mentioned in the
  1166. generic function definition.
  1167. If a @i{generic function} is passed a keyword argument that no applicable
  1168. method accepts, an error should be signaled; see @ref{Error Checking in Function Calls}.
  1169. @menu
  1170. * Examples of Keyword Arguments in Generic Functions and Methods::
  1171. @end menu
  1172. @node Examples of Keyword Arguments in Generic Functions and Methods, , Keyword Arguments in Generic Functions and Methods, Keyword Arguments in Generic Functions and Methods
  1173. @subsubsection Examples of Keyword Arguments in Generic Functions and Methods
  1174. For example, suppose there are two methods defined for @t{width}
  1175. as follows:
  1176. @example
  1177. (defmethod width ((c character-class) &key font) ...)
  1178. (defmethod width ((p picture-class) &key pixel-size) ...)
  1179. @end example
  1180. @noindent
  1181. Assume that there are no other methods and no generic
  1182. function definition for @t{width}. The evaluation of the
  1183. following form should signal an error because
  1184. the keyword argument @t{:pixel-size} is not accepted by the applicable method.
  1185. @example
  1186. (width (make-instance `character-class :char #\Q)
  1187. :font 'baskerville :pixel-size 10)
  1188. @end example
  1189. The evaluation of the following form should signal an error.
  1190. @example
  1191. (width (make-instance `picture-class :glyph (glyph #\Q))
  1192. :font 'baskerville :pixel-size 10)
  1193. @end example
  1194. The evaluation of the following form will not signal an error
  1195. if the class named @t{character-picture-class} is a subclass of
  1196. both @t{picture-class} and @t{character-class}.
  1197. @example
  1198. (width (make-instance `character-picture-class :char #\Q)
  1199. :font 'baskerville :pixel-size 10)
  1200. @end example
  1201. @node Method Selection and Combination, Inheritance of Methods, Keyword Arguments in Generic Functions and Methods, Generic Functions and Methods
  1202. @subsection Method Selection and Combination
  1203. When a @i{generic function} is called with particular arguments, it must
  1204. determine the code to execute. This code is called the
  1205. @i{effective method}
  1206. @IGindex{effective method}
  1207. for those @i{arguments}.
  1208. The @i{effective method} is a
  1209. combination of the @i{applicable methods} in the @i{generic function}
  1210. that @i{calls} some or all of the @i{methods}.
  1211. If a @i{generic function} is called and no @i{methods} are
  1212. @i{applicable}, the @i{generic function} @b{no-applicable-method}
  1213. is invoked, with the @i{results} from that call being used as the
  1214. @i{results} of the call to the original @i{generic function}. Calling
  1215. @b{no-applicable-method} takes precedence over checking for acceptable
  1216. keyword arguments; see @ref{Keyword Arguments in Generic Functions and Methods}.
  1217. When the @i{effective method} has been determined,
  1218. it is invoked with the same @i{arguments} as were passed to the @i{generic function}.
  1219. Whatever @i{values} it returns are returned as the @i{values}
  1220. of the @i{generic function}.
  1221. @menu
  1222. * Determining the Effective Method::
  1223. * Selecting the Applicable Methods::
  1224. * Sorting the Applicable Methods by Precedence Order::
  1225. * Applying method combination to the sorted list of applicable methods::
  1226. * Standard Method Combination::
  1227. * Declarative Method Combination::
  1228. * Built-in Method Combination Types::
  1229. @end menu
  1230. @node Determining the Effective Method, Selecting the Applicable Methods, Method Selection and Combination, Method Selection and Combination
  1231. @subsubsection Determining the Effective Method
  1232. The effective method is determined by the following three-step procedure:
  1233. @table @asis
  1234. @item 1.
  1235. {Select the applicable methods.}
  1236. @item 2.
  1237. {Sort the applicable methods by precedence order, putting
  1238. the most specific method first.}
  1239. @item 3.
  1240. {Apply method combination to the sorted list of
  1241. applicable methods, producing the effective method.}
  1242. @end table
  1243. @node Selecting the Applicable Methods, Sorting the Applicable Methods by Precedence Order, Determining the Effective Method, Method Selection and Combination
  1244. @subsubsection Selecting the Applicable Methods
  1245. This step is described in @ref{Introduction to Methods}.
  1246. @node Sorting the Applicable Methods by Precedence Order, Applying method combination to the sorted list of applicable methods, Selecting the Applicable Methods, Method Selection and Combination
  1247. @subsubsection Sorting the Applicable Methods by Precedence Order
  1248. To compare the precedence of two methods, their @i{parameter specializers}
  1249. are examined in order. The default examination order is from left to
  1250. right, but an alternative order may be specified by the
  1251. @t{:argument-precedence-order} option to @b{defgeneric} or to any of
  1252. the other operators that specify generic function options.
  1253. The corresponding @i{parameter specializers} from each method are
  1254. compared. When a pair of @i{parameter specializers} agree, the next
  1255. pair are compared for agreement. If all corresponding parameter
  1256. specializers agree, the two methods must have different
  1257. @i{qualifiers}; in this case, either method can be selected to precede the
  1258. other. For information about agreement, see @ref{Agreement on Parameter Specializers and Qualifiers}.
  1259. If some corresponding @i{parameter specializers} do not agree, the first
  1260. pair of @i{parameter specializers} that do not agree determines the
  1261. precedence. If both @i{parameter specializers} are classes, the more
  1262. specific of the two methods is the method whose @i{parameter specializer}
  1263. appears earlier in the @i{class precedence list} of the corresponding
  1264. argument. Because of the way in which the set of applicable methods
  1265. is chosen, the @i{parameter specializers} are guaranteed to be present in
  1266. the class precedence list of the class of the argument.
  1267. If just one of a pair of corresponding @i{parameter specializers} is @t{(eql @i{object})},
  1268. the @i{method} with that @i{parameter specializer} precedes the
  1269. other @i{method}. If both @i{parameter specializers} are @b{eql}
  1270. @i{expressions}, the
  1271. specializers must agree (otherwise the two @i{methods} would
  1272. not both have been applicable to this argument).
  1273. The resulting list of @i{applicable methods} has the most specific
  1274. @i{method} first and the least specific @i{method} last.
  1275. @node Applying method combination to the sorted list of applicable methods, Standard Method Combination, Sorting the Applicable Methods by Precedence Order, Method Selection and Combination
  1276. @subsubsection Applying method combination to the sorted list of applicable methods
  1277. In the simple case---if standard method combination is used and all
  1278. applicable methods are primary methods---the
  1279. effective method is the most specific method.
  1280. That method can call the next most specific
  1281. method by using the @i{function} @b{call-next-method}. The method that
  1282. @b{call-next-method} will call is referred to as the
  1283. @i{next method}
  1284. @IGindex{next method}
  1285. . The predicate @b{next-method-p} tests whether a next
  1286. method exists. If @b{call-next-method} is called and there is no
  1287. next most specific method, the generic function @b{no-next-method}
  1288. is invoked.
  1289. In general, the effective method is some combination of the applicable
  1290. methods. It is described by a @i{form} that contains calls to some or
  1291. all of the applicable methods, returns the value or values that will
  1292. be returned as the value or values of the generic function, and
  1293. optionally makes some of the methods accessible by means of
  1294. @b{call-next-method}.
  1295. The role of each method in the effective method is determined by its
  1296. @i{qualifiers} and the specificity of the method. A @i{qualifier}
  1297. serves to mark a method, and the meaning of a @i{qualifier} is
  1298. determined by the way that these marks are used by this step
  1299. of the procedure. If an applicable method has an unrecognized
  1300. @i{qualifier}, this step signals an error and does not include that method
  1301. in the effective method.
  1302. When standard method combination is used together with qualified methods,
  1303. the effective method is produced as described in @ref{Standard Method Combination}.
  1304. Another type of method combination can be specified by using the
  1305. @t{:method-combination} option of @b{defgeneric} or
  1306. of any of the other operators that specify generic function options. In
  1307. this way this step of the procedure can be customized.
  1308. New types of method combination can be defined by using
  1309. the @b{define-method-combination} @i{macro}.
  1310. @node Standard Method Combination, Declarative Method Combination, Applying method combination to the sorted list of applicable methods, Method Selection and Combination
  1311. @subsubsection Standard Method Combination
  1312. @IRindex{standard}
  1313. Standard method combination is supported by the @i{class} @b{standard-generic-function}.
  1314. It is used if no other type of method
  1315. combination is specified or if the built-in method combination type
  1316. @b{standard} is specified.
  1317. Primary methods define the main action of the effective method,
  1318. while auxiliary methods modify that action in one of three ways.
  1319. A primary method has no method @i{qualifiers}.
  1320. An auxiliary method is a method whose
  1321. @i{qualifier} is @t{:before}, @t{:after}, or @t{:around}.
  1322. Standard method combination
  1323. allows no more than one @i{qualifier} per method; if a method definition
  1324. specifies more than one @i{qualifier} per method, an error is signaled.
  1325. @table @asis
  1326. @item @t{*}
  1327. A @i{before method} has the keyword @t{:before} as its only @i{qualifier}.
  1328. A @i{before method} specifies @i{code} that is to be run before any
  1329. @i{primary methods}.
  1330. @item @t{*}
  1331. An @i{after method} has the keyword @t{:after} as its only @i{qualifier}.
  1332. An @i{after method} specifies @i{code} that is to be run after
  1333. @i{primary methods}.
  1334. @item @t{*}
  1335. An @i{around method} has the keyword @t{:around} as its only @i{qualifier}.
  1336. An @i{around method} specifies @i{code} that is to be run instead of other
  1337. @i{applicable methods},
  1338. but which might contain explicit @i{code}
  1339. which calls some of those @i{shadowed} @i{methods}
  1340. (via @b{call-next-method}).
  1341. @end table
  1342. The semantics of standard method combination is as follows:
  1343. @table @asis
  1344. @item @t{*}
  1345. If there are any @i{around methods}, the most specific
  1346. @i{around method} is called. It supplies the value or values of the
  1347. generic function.
  1348. @item @t{*}
  1349. Inside the body of an @i{around method},
  1350. @b{call-next-method} can be used to call the @i{next method}. When the next
  1351. method returns, the @i{around method} can execute more code,
  1352. perhaps based on the returned value or values.
  1353. The @i{generic function} @b{no-next-method} is invoked if @b{call-next-method} is used and
  1354. there is no @i{applicable method} to call. The @i{function} @b{next-method-p}
  1355. may be used to determine whether a @i{next method} exists.
  1356. @item @t{*}
  1357. If an @i{around method} invokes @b{call-next-method},
  1358. the next most specific @i{around method}
  1359. is called, if one is applicable. If there are no @i{around methods}
  1360. or if @b{call-next-method} is called by the least
  1361. specific @i{around method}, the other methods are called as
  1362. follows:
  1363. @table @asis
  1364. @item --
  1365. All the @i{before methods} are called, in
  1366. most-specific-first order. Their values are ignored.
  1367. An error is signaled if @b{call-next-method} is used in a
  1368. @i{before method}.
  1369. @item --
  1370. The most specific primary method is called. Inside the
  1371. body of a primary method, @b{call-next-method} may be used to call
  1372. the next most specific primary method. When that method returns, the
  1373. previous primary method can execute more code, perhaps based on the
  1374. returned value or values. The generic function @b{no-next-method}
  1375. is invoked if @b{call-next-method} is used and there are no more
  1376. applicable primary methods. The @i{function} @b{next-method-p} may be
  1377. used to determine whether a @i{next method} exists. If @b{call-next-method}
  1378. is not used, only the most specific @i{primary method} is called.
  1379. @item --
  1380. All the @i{after methods} are called in
  1381. most-specific-last order. Their values are ignored.
  1382. An error is signaled if @b{call-next-method} is used in an
  1383. @i{after method}.
  1384. @end table
  1385. @item @t{*}
  1386. If no @i{around methods} were invoked, the most
  1387. specific primary method supplies the value or values returned by the
  1388. generic function. The value or values returned by the invocation of
  1389. @b{call-next-method} in the least specific @i{around method} are
  1390. those returned by the most specific primary method.
  1391. @end table
  1392. In standard method combination, if there is an applicable method
  1393. but no applicable primary method, an error is signaled.
  1394. The @i{before methods} are run in most-specific-first order while
  1395. the @i{after methods} are run in least-specific-first order. The
  1396. design rationale for this difference can be illustrated with an
  1397. example. Suppose class C_1 modifies the behavior of its
  1398. superclass, C_2, by adding @i{before methods} and @i{after methods}.
  1399. Whether the behavior of the class C_2 is defined
  1400. directly by methods on C_2 or is inherited from its superclasses
  1401. does not affect the relative order of invocation of methods on
  1402. instances of the class C_1. Class C_1's
  1403. @i{before method} runs before all of class C_2's methods.
  1404. Class C_1's @i{after method} runs after all of class C_2's methods.
  1405. By contrast, all @i{around methods} run before any other methods
  1406. run. Thus a less specific @i{around method} runs before a more
  1407. specific primary method.
  1408. If only primary methods are used and if @b{call-next-method} is not
  1409. used, only the most specific method is invoked; that is, more specific
  1410. methods shadow more general ones.
  1411. @node Declarative Method Combination, Built-in Method Combination Types, Standard Method Combination, Method Selection and Combination
  1412. @subsubsection Declarative Method Combination
  1413. The macro @b{define-method-combination} defines new forms of method
  1414. combination. It provides a mechanism for customizing the production
  1415. of the effective method. The default procedure for producing an
  1416. effective method is described in @ref{Determining the Effective Method}.
  1417. There are two forms of
  1418. @b{define-method-combination}. The short form is a simple facility while
  1419. the long form is more powerful and more verbose. The long form
  1420. resembles @b{defmacro} in that the body is an expression that
  1421. computes a Lisp form; it provides mechanisms for implementing
  1422. arbitrary control structures within method combination and for
  1423. arbitrary processing of method @i{qualifiers}.
  1424. @node Built-in Method Combination Types, , Declarative Method Combination, Method Selection and Combination
  1425. @subsubsection Built-in Method Combination Types
  1426. The object system provides a set of built-in method combination types. To
  1427. specify that a generic function is to use one of these method
  1428. combination types, the name of the method combination type is given as
  1429. the argument to the @t{:method-combination} option to
  1430. @b{defgeneric} or to the @t{:method-combination} option to any of the
  1431. other operators that specify generic function options.
  1432. The names of the built-in method combination types are listed in Figure 7--3.
  1433. @IRindex{+}
  1434. @IRindex{and}
  1435. @IRindex{append}
  1436. @IRindex{list}
  1437. @IRindex{max}
  1438. @IRindex{min}
  1439. @IRindex{nconc}
  1440. @IRindex{or}
  1441. @IRindex{progn}
  1442. @IRindex{standard}
  1443. @group
  1444. @noindent
  1445. @w{ + append max nconc progn }
  1446. @w{ and list min or standard }
  1447. @noindent
  1448. @w{ Figure 7--3: Built-in Method Combination Types}
  1449. @end group
  1450. The semantics of the @b{standard} built-in method combination type is
  1451. described in @ref{Standard Method Combination}. The other
  1452. built-in method combination types are called simple built-in method
  1453. combination types.
  1454. The simple built-in method combination types act as though they were
  1455. defined by the short form of @b{define-method-combination}.
  1456. They recognize two roles for @i{methods}:
  1457. @table @asis
  1458. @item @t{*}
  1459. An @i{around method} has the keyword symbol
  1460. @t{:around} as its sole @i{qualifier}. The meaning of
  1461. @t{:around} @i{methods} is the same as in standard method combination.
  1462. Use of the functions @b{call-next-method} and @b{next-method-p}
  1463. is supported in @i{around methods}.
  1464. @item @t{*}
  1465. A primary method has the name of the method combination
  1466. type as its sole @i{qualifier}. For example, the built-in method
  1467. combination type @t{and} recognizes methods whose sole @i{qualifier} is
  1468. @t{and}; these are primary methods. Use of the functions
  1469. @b{call-next-method} and @b{next-method-p} is not supported
  1470. in @i{primary methods}.
  1471. @end table
  1472. The semantics of the simple built-in method combination types is as
  1473. follows:
  1474. @table @asis
  1475. @item @t{*}
  1476. If there are any @i{around methods}, the most specific @i{around method}
  1477. is called. It supplies the value or values of the @i{generic function}.
  1478. @item @t{*}
  1479. Inside the body of an @i{around method}, the function
  1480. @b{call-next-method} can be used to call the @i{next method}.
  1481. The @i{generic function} @b{no-next-method} is invoked if
  1482. @b{call-next-method} is used and there is no applicable method to call.
  1483. The @i{function} @b{next-method-p} may be used to determine whether a
  1484. @i{next method} exists. When the @i{next method} returns,
  1485. the @i{around method} can execute more code,
  1486. perhaps based on the returned value or values.
  1487. @item @t{*}
  1488. If an @i{around method} invokes @b{call-next-method},
  1489. the next most specific @i{around method} is
  1490. called, if one is applicable. If there are no @i{around methods}
  1491. or if @b{call-next-method} is called by the least specific
  1492. @i{around method}, a Lisp form derived from the name of the built-in
  1493. method combination type and from the list of applicable primary
  1494. methods is evaluated to produce the value of the generic function.
  1495. Suppose the name of the method combination type is @i{operator}
  1496. and the call to the generic function is of the form
  1497. @center (@i{generic-function} a_1... a_n)
  1498. @item @t{}
  1499. Let M_1,...,M_k be the applicable primary methods
  1500. in order; then the derived Lisp form is
  1501. @center (@i{operator} < M_1
  1502. a_1... a_n>...<
  1503. M_k a_1... a_n>)
  1504. @item @t{}
  1505. If the expression < M_i a_1... a_n> is
  1506. evaluated, the method M_i will be applied to the arguments
  1507. a_1... a_n.
  1508. For example,
  1509. if @i{operator} is @t{or},
  1510. the expression < M_i a_1... a_n> is
  1511. evaluated only if < M_j a_1... a_n>,
  1512. 1<= j<i, returned @t{nil}.
  1513. @item @t{}
  1514. The default order for the primary methods is
  1515. @t{:most-specific-first}. However, the order can be reversed by supplying
  1516. @t{:most-specific-last} as the second argument to the @t{:method-combination} option.
  1517. @end table
  1518. The simple built-in method combination types require exactly one
  1519. @i{qualifier} per method. An error is signaled if there are applicable
  1520. methods with no @i{qualifiers} or with @i{qualifiers} that are not supported
  1521. by the method combination type. An error is signaled if there are
  1522. applicable @i{around methods} and no applicable primary
  1523. methods.
  1524. @node Inheritance of Methods, , Method Selection and Combination, Generic Functions and Methods
  1525. @subsection Inheritance of Methods
  1526. A subclass inherits methods in the sense that any method applicable to
  1527. all instances of a class is also applicable to all instances of any
  1528. subclass of that class.
  1529. The inheritance of methods acts the same way regardless of
  1530. which of the @i{method-defining operators} created the methods.
  1531. The inheritance of methods is described in detail in
  1532. @ref{Method Selection and Combination}.
  1533. @c end of including concept-gfs-and-methods
  1534. @node Objects Dictionary, , Generic Functions and Methods, Objects
  1535. @section Objects Dictionary
  1536. @c including dict-objects
  1537. @menu
  1538. * function-keywords::
  1539. * ensure-generic-function::
  1540. * allocate-instance::
  1541. * reinitialize-instance::
  1542. * shared-initialize::
  1543. * update-instance-for-different-class::
  1544. * update-instance-for-redefined-class::
  1545. * change-class::
  1546. * slot-boundp::
  1547. * slot-exists-p::
  1548. * slot-makunbound::
  1549. * slot-missing::
  1550. * slot-unbound::
  1551. * slot-value::
  1552. * method-qualifiers::
  1553. * no-applicable-method::
  1554. * no-next-method::
  1555. * remove-method::
  1556. * make-instance::
  1557. * make-instances-obsolete::
  1558. * make-load-form::
  1559. * make-load-form-saving-slots::
  1560. * with-accessors::
  1561. * with-slots::
  1562. * defclass::
  1563. * defgeneric::
  1564. * defmethod::
  1565. * find-class::
  1566. * next-method-p::
  1567. * call-method::
  1568. * call-next-method::
  1569. * compute-applicable-methods::
  1570. * define-method-combination::
  1571. * find-method::
  1572. * add-method::
  1573. * initialize-instance::
  1574. * class-name::
  1575. * (setf class-name)::
  1576. * class-of::
  1577. * unbound-slot::
  1578. * unbound-slot-instance::
  1579. @end menu
  1580. @node function-keywords, ensure-generic-function, Objects Dictionary, Objects Dictionary
  1581. @subsection function-keywords [Standard Generic Function]
  1582. @subsubheading Syntax::
  1583. @code{function-keywords} @i{method} @result{} @i{keys, allow-other-keys-p}
  1584. @subsubheading Method Signatures::
  1585. @code{function-keywords} @i{@r{(}@i{method} @b{standard-method}@r{)}}
  1586. @subsubheading Arguments and Values::
  1587. @i{method}---a @i{method}.
  1588. @i{keys}---a @i{list}.
  1589. @i{allow-other-keys-p}---a @i{generalized boolean}.
  1590. @subsubheading Description::
  1591. Returns the keyword parameter specifiers for a @i{method}.
  1592. Two values are returned:
  1593. a @i{list} of the explicitly named keywords
  1594. and a @i{generalized boolean} that states whether @b{&allow-other-keys}
  1595. had been specified in the @i{method} definition.
  1596. @subsubheading Examples::
  1597. @example
  1598. (defmethod gf1 ((a integer) &optional (b 2)
  1599. &key (c 3) ((:dee d) 4) e ((eff f)))
  1600. (list a b c d e f))
  1601. @result{} #<STANDARD-METHOD GF1 (INTEGER) 36324653>
  1602. (find-method #'gf1 '() (list (find-class 'integer)))
  1603. @result{} #<STANDARD-METHOD GF1 (INTEGER) 36324653>
  1604. (function-keywords *)
  1605. @result{} (:C :DEE :E EFF), @i{false}
  1606. (defmethod gf2 ((a integer))
  1607. (list a b c d e f))
  1608. @result{} #<STANDARD-METHOD GF2 (INTEGER) 42701775>
  1609. (function-keywords (find-method #'gf1 '() (list (find-class 'integer))))
  1610. @result{} (), @i{false}
  1611. (defmethod gf3 ((a integer) &key b c d &allow-other-keys)
  1612. (list a b c d e f))
  1613. (function-keywords *)
  1614. @result{} (:B :C :D), @i{true}
  1615. @end example
  1616. @subsubheading Affected By::
  1617. @b{defmethod}
  1618. @subsubheading See Also::
  1619. @ref{defmethod}
  1620. @node ensure-generic-function, allocate-instance, function-keywords, Objects Dictionary
  1621. @subsection ensure-generic-function [Function]
  1622. @code{ensure-generic-function} @i{function-name {&key}
  1623. argument-precedence-order declare
  1624. documentation environment
  1625. generic-function-class lambda-list
  1626. method-class method-combination}@*
  1627. @result{} @i{generic-function}
  1628. @subsubheading Arguments and Values::
  1629. @i{function-name}---a @i{function name}.
  1630. The keyword arguments correspond to the @i{option} arguments of
  1631. @b{defgeneric}, except that the @t{:method-class} and
  1632. @t{:generic-function-class} arguments can be @i{class} @i{object}s
  1633. as well as names.
  1634. @t{Method-combination} -- method combination object.
  1635. @t{Environment} -- the same as the @b{&environment} argument
  1636. to macro expansion functions and is used to distinguish between compile-time
  1637. and run-time environments.
  1638. [Editorial Note by KMP: What about documentation. Missing from this arguments enumeration,
  1639. and confusing in description below.]
  1640. @i{generic-function}---a @i{generic function} @i{object}.
  1641. @subsubheading Description::
  1642. The @i{function} @b{ensure-generic-function} is used to define
  1643. a globally named @i{generic function} with no @i{methods}
  1644. or to specify or modify options and declarations that pertain to
  1645. a globally named @i{generic function} as a whole.
  1646. If @i{function-name} is not @i{fbound} in the @i{global environment},
  1647. a new
  1648. @i{generic function} is created.
  1649. If
  1650. @t{(fdefinition @i{function-name})}
  1651. is an @i{ordinary function},
  1652. a @i{macro},
  1653. or a @i{special operator},
  1654. an error is signaled.
  1655. If @i{function-name}
  1656. is a @i{list}, it must be of the
  1657. form @t{(setf @i{symbol})}.
  1658. If @i{function-name} specifies a @i{generic function} that has a
  1659. different value for any of the following arguments,
  1660. the @i{generic function} is modified to have the new value:
  1661. @t{:argument-precedence-order}, @t{:declare}, @t{:documentation},
  1662. @t{:method-combination}.
  1663. If @i{function-name} specifies a @i{generic function} that has a
  1664. different value for the @t{:lambda-list} argument, and the new value
  1665. is congruent with the @i{lambda lists} of all existing
  1666. @i{methods} or there
  1667. are no @i{methods}, the value is changed; otherwise an error is signaled.
  1668. If @i{function-name} specifies a @i{generic function} that has a
  1669. different value for the @t{:generic-function-class} argument and if
  1670. the new generic function class is compatible with the old,
  1671. @b{change-class} is called to change the @i{class} of the
  1672. @i{generic function};
  1673. otherwise an error is signaled.
  1674. If @i{function-name} specifies a @i{generic function} that has a
  1675. different value for the @t{:method-class} argument, the value is
  1676. changed, but any existing @i{methods} are not changed.
  1677. @subsubheading Affected By::
  1678. Existing function binding of @i{function-name}.
  1679. @subsubheading Exceptional Situations::
  1680. If
  1681. @t{(fdefinition @i{function-name})}
  1682. is an @i{ordinary function}, a @i{macro}, or a @i{special operator},
  1683. an error of @i{type} @b{error} is signaled.
  1684. If @i{function-name} specifies a
  1685. @i{generic function} that has a
  1686. different value for the @t{:lambda-list} argument, and the new value
  1687. is not congruent with the @i{lambda list} of any existing
  1688. @i{method},
  1689. an error of @i{type} @b{error} is signaled.
  1690. If @i{function-name} specifies a
  1691. @i{generic function} that has a
  1692. different value for the @t{:generic-function-class} argument and if
  1693. the new generic function class not is compatible with the old,
  1694. an error of @i{type} @b{error} is signaled.
  1695. @subsubheading See Also::
  1696. @ref{defgeneric}
  1697. @node allocate-instance, reinitialize-instance, ensure-generic-function, Objects Dictionary
  1698. @subsection allocate-instance [Standard Generic Function]
  1699. @subsubheading Syntax::
  1700. @code{allocate-instance} @i{class {&rest} initargs {&key} {&allow-other-keys}} @result{} @i{new-instance}
  1701. @subsubheading Method Signatures::
  1702. @code{allocate-instance} @i{@r{(}@i{class} @b{standard-class}@r{)} {&rest} initargs}
  1703. @code{allocate-instance} @i{@r{(}@i{class} @b{structure-class}@r{)} {&rest} initargs}
  1704. @subsubheading Arguments and Values::
  1705. @i{class}---a @i{class}.
  1706. @i{initargs}---a @i{list} of @i{keyword/value pairs}
  1707. (initialization argument @i{names} and @i{values}).
  1708. @i{new-instance}---an @i{object} whose @i{class} is @i{class}.
  1709. @subsubheading Description::
  1710. The generic function @b{allocate-instance} creates and returns
  1711. a new instance of the @i{class}, without initializing it.
  1712. When the @i{class} is a @i{standard class}, this means that
  1713. the @i{slots} are @i{unbound}; when the @i{class} is a
  1714. @i{structure class}, this means the @i{slots}' @i{values}
  1715. are unspecified.
  1716. The caller of @b{allocate-instance} is expected to have
  1717. already checked the initialization arguments.
  1718. The @i{generic function} @b{allocate-instance} is called by
  1719. @b{make-instance}, as described in
  1720. @ref{Object Creation and Initialization}.
  1721. @subsubheading See Also::
  1722. @ref{defclass}
  1723. ,
  1724. @ref{make-instance}
  1725. ,
  1726. @ref{class-of}
  1727. ,
  1728. @ref{Object Creation and Initialization}
  1729. @subsubheading Notes::
  1730. The consequences of adding @i{methods} to @b{allocate-instance} is unspecified.
  1731. This capability might be added by the @i{Metaobject Protocol}.
  1732. @node reinitialize-instance, shared-initialize, allocate-instance, Objects Dictionary
  1733. @subsection reinitialize-instance [Standard Generic Function]
  1734. @subsubheading Syntax::
  1735. @code{reinitialize-instance} @i{instance {&rest} initargs {&key} {&allow-other-keys}} @result{} @i{instance}
  1736. @subsubheading Method Signatures::
  1737. @code{reinitialize-instance} @i{@r{(}@i{instance} @b{standard-object}@r{)} {&rest} initargs}
  1738. @subsubheading Arguments and Values::
  1739. @i{instance}---an @i{object}.
  1740. @i{initargs}---an @i{initialization argument list}.
  1741. @subsubheading Description::
  1742. The @i{generic function} @b{reinitialize-instance} can be used to change
  1743. the values of @i{local slots} of an @i{instance} according to
  1744. @i{initargs}.
  1745. This @i{generic function} can be called by users.
  1746. The system-supplied primary @i{method} for @b{reinitialize-instance}
  1747. checks the validity of @i{initargs} and signals an error if
  1748. an @i{initarg} is supplied that is not declared as valid.
  1749. The @i{method} then calls the generic function @b{shared-initialize}
  1750. with the following arguments: the @i{instance},
  1751. @b{nil} (which means no @i{slots}
  1752. should be initialized according to their initforms), and the
  1753. @i{initargs} it received.
  1754. @subsubheading Side Effects::
  1755. The @i{generic function} @b{reinitialize-instance} changes the values of @i{local slots}.
  1756. @subsubheading Exceptional Situations::
  1757. The system-supplied primary @i{method} for @b{reinitialize-instance}
  1758. signals an error if an @i{initarg} is supplied that is not declared as valid.
  1759. @subsubheading See Also::
  1760. @ref{Initialize-Instance}
  1761. ,
  1762. @ref{Shared-Initialize}
  1763. ,
  1764. @ref{update-instance-for-redefined-class}
  1765. ,
  1766. @ref{update-instance-for-different-class}
  1767. ,
  1768. @ref{slot-boundp}
  1769. ,
  1770. @ref{slot-makunbound}
  1771. ,
  1772. @ref{Reinitializing an Instance},
  1773. @ref{Rules for Initialization Arguments},
  1774. @ref{Declaring the Validity of Initialization Arguments}
  1775. @subsubheading Notes::
  1776. @i{Initargs} are declared as valid by using the
  1777. @t{:initarg} option to @b{defclass}, or by defining
  1778. @i{methods} for @b{reinitialize-instance}
  1779. or @b{shared-initialize}. The keyword name
  1780. of each keyword parameter specifier in the @i{lambda list} of any
  1781. @i{method}
  1782. defined on @b{reinitialize-instance} or @b{shared-initialize} is
  1783. declared as a valid initialization argument name for all
  1784. @i{classes} for
  1785. which that @i{method} is applicable.
  1786. @node shared-initialize, update-instance-for-different-class, reinitialize-instance, Objects Dictionary
  1787. @subsection shared-initialize [Standard Generic Function]
  1788. @subsubheading Syntax::
  1789. @code{shared-initialize} @i{instance slot-names {&rest} initargs {&key} {&allow-other-keys}} @result{} @i{instance}
  1790. @subsubheading Method Signatures::
  1791. @code{shared-initialize} @i{@r{(}@i{instance} @b{standard-object}@r{)} slot-names {&rest} initargs}
  1792. @subsubheading Arguments and Values::
  1793. @i{instance}---an @i{object}.
  1794. @i{slot-names}---a @i{list} or @b{t}.
  1795. @i{initargs}---a @i{list} of @i{keyword/value pairs}
  1796. (of initialization argument @i{names} and @i{values}).
  1797. @subsubheading Description::
  1798. The generic function @b{shared-initialize} is used to fill the
  1799. @i{slots}
  1800. of an @i{instance}
  1801. using @i{initargs} and @t{:initform}
  1802. forms. It is called when an instance is created, when an instance is
  1803. re-initialized, when an instance is updated to conform to a redefined
  1804. @i{class}, and when an instance is updated to conform to a different
  1805. @i{class}. The generic function @b{shared-initialize} is called by the
  1806. system-supplied primary @i{method} for @b{initialize-instance},
  1807. @b{reinitialize-instance}, @b{update-instance-for-redefined-class}, and
  1808. @b{update-instance-for-different-class}.
  1809. The generic function @b{shared-initialize} takes the following
  1810. arguments: the @i{instance} to be initialized, a specification of a set of
  1811. @i{slot-names} @i{accessible} in that @i{instance},
  1812. and any number of @i{initargs}.
  1813. The arguments after the first two must form an
  1814. @i{initialization argument list}. The system-supplied primary @i{method} on
  1815. @b{shared-initialize} initializes the @i{slots} with values according to the
  1816. @i{initargs} and supplied @t{:initform} forms. @i{Slot-names}
  1817. indicates which @i{slots} should be initialized according
  1818. to their @t{:initform} forms if no @i{initargs} are
  1819. provided for those @i{slots}.
  1820. The system-supplied primary @i{method} behaves as follows,
  1821. regardless of whether the @i{slots} are local or shared:
  1822. @table @asis
  1823. @item @t{*}
  1824. If an @i{initarg} in the @i{initialization argument list}
  1825. specifies a value for that @i{slot}, that
  1826. value is stored into the @i{slot}, even if a value has
  1827. already been stored in the @i{slot} before the @i{method} is run.
  1828. @item @t{*}
  1829. Any @i{slots} indicated by @i{slot-names} that are still unbound
  1830. at this point are initialized according to their @t{:initform} forms.
  1831. For any such @i{slot} that has an @t{:initform} form,
  1832. that @i{form} is evaluated in the lexical environment of its defining
  1833. @b{defclass} @i{form} and the result is stored into the @i{slot}.
  1834. For example, if a @i{before method} stores a value in the @i{slot},
  1835. the @t{:initform} form will not be used to supply a value for the @i{slot}.
  1836. @item @t{*}
  1837. The rules mentioned in @ref{Rules for Initialization Arguments} are obeyed.
  1838. @end table
  1839. The @i{slots-names} argument specifies the @i{slots} that are to be
  1840. initialized according to their @t{:initform} forms if no
  1841. initialization arguments apply. It can be a @i{list} of slot @i{names},
  1842. which specifies the set of those slot @i{names}; or it can be the @i{symbol} @b{t},
  1843. which specifies the set of all of the @i{slots}.
  1844. @subsubheading See Also::
  1845. @ref{Initialize-Instance}
  1846. ,
  1847. @ref{reinitialize-instance}
  1848. ,
  1849. @ref{update-instance-for-redefined-class}
  1850. ,
  1851. @ref{update-instance-for-different-class}
  1852. ,
  1853. @ref{slot-boundp}
  1854. ,
  1855. @ref{slot-makunbound}
  1856. ,
  1857. @ref{Object Creation and Initialization},
  1858. @ref{Rules for Initialization Arguments},
  1859. @ref{Declaring the Validity of Initialization Arguments}
  1860. @subsubheading Notes::
  1861. @i{Initargs} are declared as valid by using the @t{:initarg}
  1862. option to @b{defclass}, or by defining
  1863. @i{methods} for @b{shared-initialize}.
  1864. The keyword name of each keyword parameter
  1865. specifier in the @i{lambda list} of any @i{method} defined on
  1866. @b{shared-initialize} is declared as a valid @i{initarg}
  1867. name for all @i{classes} for which that @i{method} is applicable.
  1868. Implementations are permitted to optimize @t{:initform} forms that
  1869. neither produce nor depend on side effects, by evaluating these @i{forms}
  1870. and storing them into slots before running any
  1871. @b{initialize-instance} methods, rather than by handling them in the
  1872. primary @b{initialize-instance} method. (This optimization might
  1873. be implemented by having the @b{allocate-instance} method copy a
  1874. prototype instance.)
  1875. Implementations are permitted to optimize default initial value forms
  1876. for @i{initargs} associated with slots by not actually
  1877. creating the complete initialization argument
  1878. @i{list} when the only @i{method}
  1879. that would receive the complete @i{list} is the
  1880. @i{method} on @b{standard-object}.
  1881. In this case default initial value forms can be
  1882. treated like @t{:initform} forms. This optimization has no visible
  1883. effects other than a performance improvement.
  1884. @node update-instance-for-different-class, update-instance-for-redefined-class, shared-initialize, Objects Dictionary
  1885. @subsection update-instance-for-different-class [Standard Generic Function]
  1886. @subsubheading Syntax::
  1887. @code{update-instance-for-different-class} @i{previous current
  1888. {&rest} initargs
  1889. {&key} {&allow-other-keys}} @result{} @i{@i{implementation-dependent}}
  1890. @subsubheading Method Signatures::
  1891. @code{update-instance-for-different-class} @i{@r{(}@i{previous} @b{standard-object}@r{)}
  1892. @r{(}@i{current} @b{standard-object}@r{)}
  1893. {&rest} initargs}
  1894. @subsubheading Arguments and Values::
  1895. @i{previous}---a copy of the original @i{instance}.
  1896. @i{current}---the original @i{instance} (altered).
  1897. @i{initargs}---an @i{initialization argument list}.
  1898. @subsubheading Description::
  1899. The generic function @b{update-instance-for-different-class} is not
  1900. intended to be called by programmers. Programmers may write
  1901. @i{methods} for it. The @i{function} @b{update-instance-for-different-class}
  1902. is called only by the @i{function} @b{change-class}.
  1903. The system-supplied primary @i{method} on
  1904. @b{update-instance-for-different-class} checks the validity of
  1905. @i{initargs} and signals an error if an @i{initarg}
  1906. is supplied that is not declared as valid. This @i{method} then
  1907. initializes @i{slots} with values according to the @i{initargs},
  1908. and initializes the newly added @i{slots} with values according
  1909. to their @t{:initform} forms. It does this by calling the generic
  1910. function @b{shared-initialize} with the following arguments: the
  1911. instance (@i{current}),
  1912. a list of @i{names} of the newly added @i{slots}, and the @i{initargs}
  1913. it received. Newly added @i{slots} are those @i{local slots} for which
  1914. no @i{slot} of the same name exists in the @i{previous} class.
  1915. @i{Methods} for @b{update-instance-for-different-class} can be defined to
  1916. specify actions to be taken when an @i{instance} is updated. If only
  1917. @i{after methods} for @b{update-instance-for-different-class} are
  1918. defined, they will be run after the system-supplied primary @i{method} for
  1919. initialization and therefore will not interfere with the default
  1920. behavior of @b{update-instance-for-different-class}.
  1921. @i{Methods} on @b{update-instance-for-different-class} can be defined to
  1922. initialize @i{slots} differently from @b{change-class}. The default
  1923. behavior of @b{change-class} is described in
  1924. @ref{Changing the Class of an Instance}.
  1925. The arguments to @b{update-instance-for-different-class} are
  1926. computed by @b{change-class}. When @b{change-class} is invoked on
  1927. an @i{instance}, a copy of that @i{instance} is made; @b{change-class} then
  1928. destructively alters the original @i{instance}. The first argument to
  1929. @b{update-instance-for-different-class}, @i{previous}, is that
  1930. copy; it holds the old @i{slot} values temporarily. This argument has
  1931. dynamic extent within @b{change-class}; if it is referenced in any
  1932. way once @b{update-instance-for-different-class} returns, the
  1933. results are undefined. The second argument to
  1934. @b{update-instance-for-different-class}, @i{current}, is the altered
  1935. original @i{instance}.
  1936. The intended use of @i{previous} is to extract old @i{slot} values by using
  1937. @b{slot-value} or @b{with-slots} or by invoking
  1938. a reader generic function, or to run other @i{methods} that were applicable to
  1939. @i{instances} of
  1940. the original @i{class}.
  1941. @subsubheading Examples::
  1942. See the example for the @i{function} @b{change-class}.
  1943. @subsubheading Exceptional Situations::
  1944. The system-supplied primary @i{method} on
  1945. @b{update-instance-for-different-class} signals an error if an
  1946. initialization argument is supplied that is not declared as valid.
  1947. @subsubheading See Also::
  1948. @ref{change-class}
  1949. ,
  1950. @ref{Shared-Initialize}
  1951. ,
  1952. @ref{Changing the Class of an Instance},
  1953. @ref{Rules for Initialization Arguments},
  1954. @ref{Declaring the Validity of Initialization Arguments}
  1955. @subsubheading Notes::
  1956. @i{Initargs} are declared as valid by using the @t{:initarg}
  1957. option to @b{defclass}, or by defining @i{methods}
  1958. for @b{update-instance-for-different-class} or @b{shared-initialize}.
  1959. The keyword name of each keyword parameter specifier in the @i{lambda list} of
  1960. any @i{method} defined on @b{update-instance-for-different-class}
  1961. or @b{shared-initialize} is declared as a valid @i{initarg} name
  1962. for all @i{classes} for which that @i{method} is applicable.
  1963. The value returned by @b{update-instance-for-different-class} is
  1964. ignored by @b{change-class}.
  1965. @node update-instance-for-redefined-class, change-class, update-instance-for-different-class, Objects Dictionary
  1966. @subsection update-instance-for-redefined-class [Standard Generic Function]
  1967. @subsubheading Syntax::
  1968. @code{update-instance-for-redefined-class} @i{instance
  1969. added-slots discarded-slots
  1970. property-list
  1971. {&rest} initargs {&key} {&allow-other-keys}}@*
  1972. @result{} @i{@{@i{result}@}{*}}
  1973. @subsubheading Method Signatures::
  1974. @code{update-instance-for-redefined-class} @i{@r{(}@i{instance} @b{standard-object}@r{)}
  1975. added-slots discarded-slots
  1976. property-list
  1977. {&rest} initargs}
  1978. @subsubheading Arguments and Values::
  1979. @i{instance}---an @i{object}.
  1980. @i{added-slots}---a @i{list}.
  1981. @i{discarded-slots}---a @i{list}.
  1982. @i{property-list}---a @i{list}.
  1983. @i{initargs}---an @i{initialization argument list}.
  1984. @i{result}---an @i{object}.
  1985. @subsubheading Description::
  1986. The @i{generic function} @b{update-instance-for-redefined-class}
  1987. is not intended to be called by programmers. Programmers may write
  1988. @i{methods} for it. The @i{generic function}
  1989. @b{update-instance-for-redefined-class} is called by the mechanism
  1990. activated by @b{make-instances-obsolete}.
  1991. The system-supplied primary @i{method} on
  1992. @b{update-instance-for-redefined-class} checks the validity of
  1993. @i{initargs} and signals an error if an @i{initarg}
  1994. is supplied that is not declared as valid. This @i{method} then
  1995. initializes @i{slots} with values according to the @i{initargs},
  1996. and initializes the newly @i{added-slots} with values according
  1997. to their @t{:initform} forms. It does this by calling the generic
  1998. function @b{shared-initialize} with the following arguments:
  1999. the @i{instance},
  2000. a list of names of the newly @i{added-slots} to @i{instance},
  2001. and the @i{initargs}
  2002. it received. Newly @i{added-slots} are those @i{local slots} for which
  2003. no @i{slot} of the same name exists in the old version of the @i{class}.
  2004. When @b{make-instances-obsolete} is invoked or when a @i{class} has been
  2005. redefined and an @i{instance} is being updated, a @i{property-list} is created
  2006. that captures the slot names and values of all the @i{discarded-slots} with
  2007. values in the original @i{instance}. The structure of the
  2008. @i{instance} is
  2009. transformed so that it conforms to the current class definition. The
  2010. arguments to @b{update-instance-for-redefined-class} are this
  2011. transformed @i{instance}, a list of @i{added-slots} to the
  2012. @i{instance}, a list @i{discarded-slots} from the
  2013. @i{instance}, and the @i{property-list}
  2014. containing the slot names and values for
  2015. @i{slots} that were discarded and had values. Included in this list of
  2016. discarded @i{slots} are @i{slots} that were local in the old @i{class} and are
  2017. shared in the new @i{class}.
  2018. The value returned by @b{update-instance-for-redefined-class} is ignored.
  2019. @subsubheading Examples::
  2020. @example
  2021. (defclass position () ())
  2022. (defclass x-y-position (position)
  2023. ((x :initform 0 :accessor position-x)
  2024. (y :initform 0 :accessor position-y)))
  2025. ;;; It turns out polar coordinates are used more than Cartesian
  2026. ;;; coordinates, so the representation is altered and some new
  2027. ;;; accessor methods are added.
  2028. (defmethod update-instance-for-redefined-class :before
  2029. ((pos x-y-position) added deleted plist &key)
  2030. ;; Transform the x-y coordinates to polar coordinates
  2031. ;; and store into the new slots.
  2032. (let ((x (getf plist 'x))
  2033. (y (getf plist 'y)))
  2034. (setf (position-rho pos) (sqrt (+ (* x x) (* y y)))
  2035. (position-theta pos) (atan y x))))
  2036. (defclass x-y-position (position)
  2037. ((rho :initform 0 :accessor position-rho)
  2038. (theta :initform 0 :accessor position-theta)))
  2039. ;;; All instances of the old x-y-position class will be updated
  2040. ;;; automatically.
  2041. ;;; The new representation is given the look and feel of the old one.
  2042. (defmethod position-x ((pos x-y-position))
  2043. (with-slots (rho theta) pos (* rho (cos theta))))
  2044. (defmethod (setf position-x) (new-x (pos x-y-position))
  2045. (with-slots (rho theta) pos
  2046. (let ((y (position-y pos)))
  2047. (setq rho (sqrt (+ (* new-x new-x) (* y y)))
  2048. theta (atan y new-x))
  2049. new-x)))
  2050. (defmethod position-y ((pos x-y-position))
  2051. (with-slots (rho theta) pos (* rho (sin theta))))
  2052. (defmethod (setf position-y) (new-y (pos x-y-position))
  2053. (with-slots (rho theta) pos
  2054. (let ((x (position-x pos)))
  2055. (setq rho (sqrt (+ (* x x) (* new-y new-y)))
  2056. theta (atan new-y x))
  2057. new-y)))
  2058. @end example
  2059. @subsubheading Exceptional Situations::
  2060. The system-supplied primary @i{method} on
  2061. @b{update-instance-for-redefined-class} signals an error if an
  2062. @i{initarg} is supplied that is not declared as valid.
  2063. @subsubheading See Also::
  2064. @ref{make-instances-obsolete}
  2065. ,
  2066. @ref{Shared-Initialize}
  2067. ,
  2068. @ref{Redefining Classes},
  2069. @ref{Rules for Initialization Arguments},
  2070. @ref{Declaring the Validity of Initialization Arguments}
  2071. @subsubheading Notes::
  2072. @i{Initargs} are declared as valid by using the @t{:initarg}
  2073. option to @b{defclass}, or by defining @i{methods} for
  2074. @b{update-instance-for-redefined-class} or @b{shared-initialize}.
  2075. The keyword name of each keyword parameter specifier in the @i{lambda list} of
  2076. any @i{method} defined on
  2077. @b{update-instance-for-redefined-class} or
  2078. @b{shared-initialize} is declared as a valid @i{initarg} name
  2079. for all @i{classes} for which that @i{method} is applicable.
  2080. @node change-class, slot-boundp, update-instance-for-redefined-class, Objects Dictionary
  2081. @subsection change-class [Standard Generic Function]
  2082. @subsubheading Syntax::
  2083. @code{change-class} @i{instance new-class {&key} {&allow-other-keys}} @result{} @i{instance}
  2084. @subsubheading Method Signatures::
  2085. @code{change-class} @i{@r{(}@i{instance} @b{standard-object}@r{)}
  2086. @r{(}@i{new-class} @b{standard-class}@r{)}
  2087. {&rest} initargs}
  2088. @code{change-class} @i{@r{(}@i{instance} @b{t}@r{)}
  2089. @r{(}@i{new-class} @b{symbol}@r{)}
  2090. {&rest} initargs}
  2091. @subsubheading Arguments and Values::
  2092. @i{instance}---an @i{object}.
  2093. @i{new-class}---a @i{class designator}.
  2094. @i{initargs}---an @i{initialization argument list}.
  2095. @subsubheading Description::
  2096. The @i{generic function} @b{change-class} changes the
  2097. @i{class} of an @i{instance} to @i{new-class}.
  2098. It destructively modifies and returns the @i{instance}.
  2099. If in the old @i{class} there is any @i{slot} of the
  2100. same name as a local @i{slot} in the @i{new-class},
  2101. the value of that @i{slot} is retained. This means that if
  2102. the @i{slot} has a value, the value returned by @b{slot-value}
  2103. after @b{change-class} is invoked is @b{eql} to the
  2104. value returned by @b{slot-value} before @b{change-class} is
  2105. invoked. Similarly, if the @i{slot} was unbound, it remains
  2106. unbound. The other @i{slots} are initialized as described in
  2107. @ref{Changing the Class of an Instance}.
  2108. After completing all other actions, @b{change-class} invokes
  2109. @b{update-instance-for-different-class}. The
  2110. generic function @b{update-instance-for-different-class} can be used
  2111. to assign values to slots in the transformed instance.
  2112. See @ref{Initializing Newly Added Local Slots}.
  2113. If the second of the above @i{methods} is selected,
  2114. that @i{method} invokes @b{change-class}
  2115. on @i{instance}, @t{(find-class @i{new-class})},
  2116. and the @i{initargs}.
  2117. @subsubheading Examples::
  2118. @example
  2119. (defclass position () ())
  2120. (defclass x-y-position (position)
  2121. ((x :initform 0 :initarg :x)
  2122. (y :initform 0 :initarg :y)))
  2123. (defclass rho-theta-position (position)
  2124. ((rho :initform 0)
  2125. (theta :initform 0)))
  2126. (defmethod update-instance-for-different-class :before ((old x-y-position)
  2127. (new rho-theta-position)
  2128. &key)
  2129. ;; Copy the position information from old to new to make new
  2130. ;; be a rho-theta-position at the same position as old.
  2131. (let ((x (slot-value old 'x))
  2132. (y (slot-value old 'y)))
  2133. (setf (slot-value new 'rho) (sqrt (+ (* x x) (* y y)))
  2134. (slot-value new 'theta) (atan y x))))
  2135. ;;; At this point an instance of the class x-y-position can be
  2136. ;;; changed to be an instance of the class rho-theta-position using
  2137. ;;; change-class:
  2138. (setq p1 (make-instance 'x-y-position :x 2 :y 0))
  2139. (change-class p1 'rho-theta-position)
  2140. ;;; The result is that the instance bound to p1 is now an instance of
  2141. ;;; the class rho-theta-position. The update-instance-for-different-class
  2142. ;;; method performed the initialization of the rho and theta slots based
  2143. ;;; on the value of the x and y slots, which were maintained by
  2144. ;;; the old instance.
  2145. @end example
  2146. @subsubheading See Also::
  2147. @ref{update-instance-for-different-class}
  2148. ,
  2149. @ref{Changing the Class of an Instance}
  2150. @subsubheading Notes::
  2151. The generic function @b{change-class} has several semantic
  2152. difficulties. First, it performs a destructive operation that can be
  2153. invoked within a @i{method} on an @i{instance} that was used to select that
  2154. @i{method}.
  2155. When multiple @i{methods} are involved because @i{methods} are being
  2156. combined, the @i{methods} currently executing or about to be executed may
  2157. no longer be applicable. Second, some implementations might use
  2158. compiler optimizations of slot @i{access}, and when the @i{class} of an
  2159. @i{instance} is changed the assumptions the compiler made might be
  2160. violated. This implies that a programmer must not use
  2161. @b{change-class} inside a @i{method} if any
  2162. @i{methods} for that @i{generic function}
  2163. @i{access} any @i{slots}, or the results are undefined.
  2164. @node slot-boundp, slot-exists-p, change-class, Objects Dictionary
  2165. @subsection slot-boundp [Function]
  2166. @code{slot-boundp} @i{instance slot-name} @result{} @i{generalized-boolean}
  2167. @subsubheading Arguments and Values::
  2168. @i{instance}---an @i{object}.
  2169. @i{slot-name}---a @i{symbol} naming a @i{slot} of @i{instance}.
  2170. @i{generalized-boolean}---a @i{generalized boolean}.
  2171. @subsubheading Description::
  2172. Returns @i{true} if the @i{slot} named @i{slot-name} in @i{instance} is bound;
  2173. otherwise, returns @i{false}.
  2174. @subsubheading Exceptional Situations::
  2175. If no @i{slot} of the @i{name} @i{slot-name} exists in the
  2176. @i{instance}, @b{slot-missing} is called as follows:
  2177. @example
  2178. (slot-missing (class-of @i{instance})
  2179. @i{instance}
  2180. @i{slot-name}
  2181. 'slot-boundp)
  2182. @end example
  2183. (If @b{slot-missing} is invoked and returns a value,
  2184. a @i{boolean equivalent} to its @i{primary value}
  2185. is returned by @b{slot-boundp}.)
  2186. The specific behavior depends on @i{instance}'s @i{metaclass}.
  2187. An error is never signaled if @i{instance} has @i{metaclass} @b{standard-class}.
  2188. An error is always signaled if @i{instance} has @i{metaclass} @b{built-in-class}.
  2189. The consequences are undefined if @i{instance} has any other @i{metaclass}--an error
  2190. might or might not be signaled in this situation. Note in particular that the behavior
  2191. for @i{conditions} and @i{structures} is not specified.
  2192. @subsubheading See Also::
  2193. @ref{slot-makunbound}
  2194. ,
  2195. @ref{slot-missing}
  2196. @subsubheading Notes::
  2197. The @i{function} @b{slot-boundp} allows for writing
  2198. @i{after methods} on @b{initialize-instance} in order to initialize only
  2199. those @i{slots} that have not already been bound.
  2200. Although no @i{implementation} is required to do so,
  2201. implementors are strongly encouraged to implement the @i{function} @b{slot-boundp} using
  2202. the @i{function} @t{slot-boundp-using-class} described in the @i{Metaobject Protocol}.
  2203. @node slot-exists-p, slot-makunbound, slot-boundp, Objects Dictionary
  2204. @subsection slot-exists-p [Function]
  2205. @code{slot-exists-p} @i{object slot-name} @result{} @i{generalized-boolean}
  2206. @subsubheading Arguments and Values::
  2207. @i{object}---an @i{object}.
  2208. @i{slot-name}---a @i{symbol}.
  2209. @i{generalized-boolean}---a @i{generalized boolean}.
  2210. @subsubheading Description::
  2211. Returns @i{true} if the @i{object} has
  2212. a @i{slot} named @i{slot-name}.
  2213. @subsubheading Affected By::
  2214. @b{defclass},
  2215. @b{defstruct}
  2216. @subsubheading See Also::
  2217. @ref{defclass}
  2218. ,
  2219. @ref{slot-missing}
  2220. @subsubheading Notes::
  2221. Although no @i{implementation} is required to do so,
  2222. implementors are strongly encouraged to implement the @i{function} @b{slot-exists-p} using
  2223. the @i{function} @t{slot-exists-p-using-class} described in the @i{Metaobject Protocol}.
  2224. @node slot-makunbound, slot-missing, slot-exists-p, Objects Dictionary
  2225. @subsection slot-makunbound [Function]
  2226. @code{slot-makunbound} @i{instance slot-name} @result{} @i{instance}
  2227. @subsubheading Arguments and Values::
  2228. @i{instance} -- instance.
  2229. @i{Slot-name}---a @i{symbol}.
  2230. @subsubheading Description::
  2231. The @i{function} @b{slot-makunbound} restores a @i{slot}
  2232. of the name @i{slot-name} in an @i{instance} to
  2233. the unbound state.
  2234. @subsubheading Exceptional Situations::
  2235. If no @i{slot} of the name @i{slot-name} exists in the
  2236. @i{instance}, @b{slot-missing} is called as follows:
  2237. @example
  2238. (slot-missing (class-of @i{instance})
  2239. @i{instance}
  2240. @i{slot-name}
  2241. 'slot-makunbound)
  2242. @end example
  2243. (Any values returned by @b{slot-missing} in this case are
  2244. ignored by @b{slot-makunbound}.)
  2245. The specific behavior depends on @i{instance}'s @i{metaclass}.
  2246. An error is never signaled if @i{instance} has @i{metaclass} @b{standard-class}.
  2247. An error is always signaled if @i{instance} has @i{metaclass} @b{built-in-class}.
  2248. The consequences are undefined if @i{instance} has any other @i{metaclass}--an error
  2249. might or might not be signaled in this situation. Note in particular that the behavior
  2250. for @i{conditions} and @i{structures} is not specified.
  2251. @subsubheading See Also::
  2252. @ref{slot-boundp}
  2253. ,
  2254. @ref{slot-missing}
  2255. @subsubheading Notes::
  2256. Although no @i{implementation} is required to do so,
  2257. implementors are strongly encouraged to implement the @i{function} @b{slot-makunbound} using
  2258. the @i{function} @t{slot-makunbound-using-class} described in the @i{Metaobject Protocol}.
  2259. @node slot-missing, slot-unbound, slot-makunbound, Objects Dictionary
  2260. @subsection slot-missing [Standard Generic Function]
  2261. @subsubheading Syntax::
  2262. @code{slot-missing} @i{class object slot-name operation {&optional} new-value} @result{} @i{@{@i{result}@}{*}}
  2263. @subsubheading Method Signatures::
  2264. @code{slot-missing} @i{@r{(}@i{class} @b{t}@r{)}
  2265. object slot-name
  2266. operation {&optional} new-value}
  2267. @subsubheading Arguments and Values::
  2268. @i{class}---the @i{class} of @i{object}.
  2269. @i{object}---an @i{object}.
  2270. @i{slot-name}---a @i{symbol} (the @i{name} of a would-be @i{slot}).
  2271. @i{operation}---one of the @i{symbols}
  2272. @b{setf},
  2273. @b{slot-boundp},
  2274. @b{slot-makunbound},
  2275. or @b{slot-value}.
  2276. @i{new-value}---an @i{object}.
  2277. @i{result}---an @i{object}.
  2278. @subsubheading Description::
  2279. The generic function @b{slot-missing} is invoked when an attempt is
  2280. made to @i{access} a @i{slot} in an @i{object} whose
  2281. @i{metaclass} is @b{standard-class}
  2282. and the @i{slot} of the name @i{slot-name}
  2283. is not a @i{name} of a
  2284. @i{slot} in that @i{class}.
  2285. The default @i{method} signals an error.
  2286. The generic function @b{slot-missing} is not intended to be called by
  2287. programmers. Programmers may write @i{methods} for it.
  2288. The generic function @b{slot-missing} may be called during
  2289. evaluation of @b{slot-value}, @t{(setf slot-value)},
  2290. @b{slot-boundp}, and @b{slot-makunbound}. For each
  2291. of these operations the corresponding @i{symbol}
  2292. for the @i{operation}
  2293. argument is @b{slot-value}, @b{setf}, @b{slot-boundp},
  2294. and @b{slot-makunbound} respectively.
  2295. The optional @i{new-value} argument to @b{slot-missing} is used
  2296. when the operation is attempting to set the value of the @i{slot}.
  2297. If @b{slot-missing} returns, its values will be treated as follows:
  2298. @table @asis
  2299. @item @t{*}
  2300. If the @i{operation} is @b{setf} or @b{slot-makunbound},
  2301. any @i{values} will be ignored by the caller.
  2302. @item @t{*}
  2303. If the @i{operation} is @b{slot-value},
  2304. only the @i{primary value} will be used by the caller,
  2305. and all other values will be ignored.
  2306. @item @t{*}
  2307. If the @i{operation} is @b{slot-boundp},
  2308. any @i{boolean equivalent} of the @i{primary value}
  2309. of the @i{method} might be is used,
  2310. and all other values will be ignored.
  2311. @end table
  2312. @subsubheading Exceptional Situations::
  2313. The default @i{method} on @b{slot-missing}
  2314. signals an error of @i{type} @b{error}.
  2315. @subsubheading See Also::
  2316. @ref{defclass}
  2317. ,
  2318. @ref{slot-exists-p}
  2319. ,
  2320. @ref{slot-value}
  2321. @subsubheading Notes::
  2322. The set of arguments (including the @i{class} of the instance) facilitates
  2323. defining methods on the metaclass for @b{slot-missing}.
  2324. @node slot-unbound, slot-value, slot-missing, Objects Dictionary
  2325. @subsection slot-unbound [Standard Generic Function]
  2326. @subsubheading Syntax::
  2327. @code{slot-unbound} @i{class instance slot-name} @result{} @i{@{@i{result}@}{*}}
  2328. @subsubheading Method Signatures::
  2329. @code{slot-unbound} @i{@r{(}@i{class} @b{t}@r{)}
  2330. instance slot-name}
  2331. @subsubheading Arguments and Values::
  2332. @i{class}---the @i{class} of the @i{instance}.
  2333. @i{instance}---the @i{instance} in which an attempt
  2334. was made to @i{read} the @i{unbound} @i{slot}.
  2335. @i{slot-name}---the @i{name} of the @i{unbound} @i{slot}.
  2336. @i{result}---an @i{object}.
  2337. @subsubheading Description::
  2338. The generic function @b{slot-unbound} is called when an
  2339. unbound @i{slot} is read in
  2340. an @i{instance} whose metaclass is @b{standard-class}.
  2341. The default @i{method} signals an error
  2342. of @i{type} @b{unbound-slot}.
  2343. The name slot of the
  2344. @b{unbound-slot} @i{condition} is initialized
  2345. to the name of the offending variable, and the instance slot
  2346. of the @b{unbound-slot} @i{condition} is initialized to the offending instance.
  2347. The generic function @b{slot-unbound} is not intended to be called
  2348. by programmers. Programmers may write @i{methods} for it.
  2349. The @i{function} @b{slot-unbound} is called only
  2350. indirectly by @b{slot-value}.
  2351. If @b{slot-unbound} returns,
  2352. only the @i{primary value} will be used by the caller,
  2353. and all other values will be ignored.
  2354. @subsubheading Exceptional Situations::
  2355. The default @i{method} on @b{slot-unbound}
  2356. signals an error of @i{type} @b{unbound-slot}.
  2357. @subsubheading See Also::
  2358. @ref{slot-makunbound}
  2359. @subsubheading Notes::
  2360. An unbound @i{slot} may occur if no @t{:initform} form was
  2361. specified for the @i{slot} and the @i{slot} value has not been set,
  2362. or if @b{slot-makunbound} has been called on the @i{slot}.
  2363. @node slot-value, method-qualifiers, slot-unbound, Objects Dictionary
  2364. @subsection slot-value [Function]
  2365. @code{slot-value} @i{object slot-name} @result{} @i{value}
  2366. @subsubheading Arguments and Values::
  2367. @i{object}---an @i{object}.
  2368. @i{name}---a @i{symbol}.
  2369. @i{value}---an @i{object}.
  2370. @subsubheading Description::
  2371. The @i{function} @b{slot-value} returns the @i{value} of the @i{slot}
  2372. named @i{slot-name} in the @i{object}.
  2373. If there is no @i{slot} named @i{slot-name}, @b{slot-missing} is called.
  2374. If the @i{slot} is unbound, @b{slot-unbound} is called.
  2375. The macro @b{setf} can be used with @b{slot-value}
  2376. to change the value of a @i{slot}.
  2377. @subsubheading Examples::
  2378. @example
  2379. (defclass foo ()
  2380. ((a :accessor foo-a :initarg :a :initform 1)
  2381. (b :accessor foo-b :initarg :b)
  2382. (c :accessor foo-c :initform 3)))
  2383. @result{} #<STANDARD-CLASS FOO 244020371>
  2384. (setq foo1 (make-instance 'foo :a 'one :b 'two))
  2385. @result{} #<FOO 36325624>
  2386. (slot-value foo1 'a) @result{} ONE
  2387. (slot-value foo1 'b) @result{} TWO
  2388. (slot-value foo1 'c) @result{} 3
  2389. (setf (slot-value foo1 'a) 'uno) @result{} UNO
  2390. (slot-value foo1 'a) @result{} UNO
  2391. (defmethod foo-method ((x foo))
  2392. (slot-value x 'a))
  2393. @result{} #<STANDARD-METHOD FOO-METHOD (FOO) 42720573>
  2394. (foo-method foo1) @result{} UNO
  2395. @end example
  2396. @subsubheading Exceptional Situations::
  2397. If an attempt is made to read a @i{slot} and no @i{slot} of
  2398. the name @i{slot-name} exists in the @i{object},
  2399. @b{slot-missing} is called as follows:
  2400. @example
  2401. (slot-missing (class-of @i{instance})
  2402. @i{instance}
  2403. @i{slot-name}
  2404. 'slot-value)
  2405. @end example
  2406. (If @b{slot-missing} is invoked, its @i{primary value}
  2407. is returned by @b{slot-value}.)
  2408. If an attempt is made to write a @i{slot} and no @i{slot} of
  2409. the name @i{slot-name} exists in the @i{object},
  2410. @b{slot-missing} is called as follows:
  2411. @example
  2412. (slot-missing (class-of @i{instance})
  2413. @i{instance}
  2414. @i{slot-name}
  2415. 'setf
  2416. @i{new-value})
  2417. @end example
  2418. (If @b{slot-missing} returns in this case, any @i{values} are ignored.)
  2419. The specific behavior depends on @i{object}'s @i{metaclass}.
  2420. An error is never signaled if @i{object} has @i{metaclass} @b{standard-class}.
  2421. An error is always signaled if @i{object} has @i{metaclass} @b{built-in-class}.
  2422. The consequences are
  2423. unspecified
  2424. if @i{object} has any other @i{metaclass}--an error
  2425. might or might not be signaled in this situation. Note in particular that the behavior
  2426. for @i{conditions} and @i{structures} is not specified.
  2427. @subsubheading See Also::
  2428. @ref{slot-missing}
  2429. ,
  2430. @ref{slot-unbound}
  2431. ,
  2432. @ref{with-slots}
  2433. @subsubheading Notes::
  2434. Although no @i{implementation} is required to do so,
  2435. implementors are strongly encouraged to implement the @i{function} @b{slot-value} using
  2436. the @i{function} @t{slot-value-using-class} described in the @i{Metaobject Protocol}.
  2437. Implementations may optimize @b{slot-value} by compiling it inline.
  2438. @node method-qualifiers, no-applicable-method, slot-value, Objects Dictionary
  2439. @subsection method-qualifiers [Standard Generic Function]
  2440. @subsubheading Syntax::
  2441. @code{method-qualifiers} @i{method} @result{} @i{qualifiers}
  2442. @subsubheading Method Signatures::
  2443. @code{method-qualifiers} @i{@r{(}@i{method} @b{standard-method}@r{)}}
  2444. @subsubheading Arguments and Values::
  2445. @i{method}---a @i{method}.
  2446. @i{qualifiers}---a @i{proper list}.
  2447. @subsubheading Description::
  2448. Returns a @i{list} of the @i{qualifiers} of the @i{method}.
  2449. @subsubheading Examples::
  2450. @example
  2451. (defmethod some-gf :before ((a integer)) a)
  2452. @result{} #<STANDARD-METHOD SOME-GF (:BEFORE) (INTEGER) 42736540>
  2453. (method-qualifiers *) @result{} (:BEFORE)
  2454. @end example
  2455. @subsubheading See Also::
  2456. @ref{define-method-combination}
  2457. @node no-applicable-method, no-next-method, method-qualifiers, Objects Dictionary
  2458. @subsection no-applicable-method [Standard Generic Function]
  2459. @subsubheading Syntax::
  2460. @code{no-applicable-method} @i{generic-function {&rest} function-arguments} @result{} @i{@{@i{result}@}{*}}
  2461. @subsubheading Method Signatures::
  2462. @code{no-applicable-method} @i{@r{(}@i{generic-function} @b{t}@r{)}
  2463. {&rest} function-arguments}
  2464. @subsubheading Arguments and Values::
  2465. @i{generic-function}---a @i{generic function}
  2466. on which no @i{applicable method} was found.
  2467. @i{function-arguments}---@i{arguments} to the @i{generic-function}.
  2468. @i{result}---an @i{object}.
  2469. @subsubheading Description::
  2470. The generic function @b{no-applicable-method} is called when a
  2471. @i{generic function}
  2472. is invoked
  2473. and no @i{method} on that @i{generic function} is applicable.
  2474. The @i{default method} signals an error.
  2475. The generic function @b{no-applicable-method} is not intended
  2476. to be called by programmers. Programmers may write @i{methods} for it.
  2477. @subsubheading Exceptional Situations::
  2478. The default @i{method} signals an error of @i{type} @b{error}.
  2479. @subsubheading See Also::
  2480. @node no-next-method, remove-method, no-applicable-method, Objects Dictionary
  2481. @subsection no-next-method [Standard Generic Function]
  2482. @subsubheading Syntax::
  2483. @code{no-next-method} @i{generic-function method {&rest} args} @result{} @i{@{@i{result}@}{*}}
  2484. @subsubheading Method Signatures::
  2485. @code{no-next-method} @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
  2486. @r{(}@i{method} @b{standard-method}@r{)}
  2487. {&rest} args}
  2488. @subsubheading Arguments and Values::
  2489. @i{generic-function} -- @i{generic function} to which @i{method} belongs.
  2490. @i{method} -- @i{method} that contained the call to
  2491. @b{call-next-method} for which there is no next @i{method}.
  2492. @i{args} -- arguments to @b{call-next-method}.
  2493. @i{result}---an @i{object}.
  2494. @subsubheading Description::
  2495. The @i{generic function} @b{no-next-method} is called by @b{call-next-method}
  2496. when there is no @i{next method}.
  2497. The @i{generic function} @b{no-next-method} is not intended to be called by programmers.
  2498. Programmers may write @i{methods} for it.
  2499. @subsubheading Exceptional Situations::
  2500. The system-supplied @i{method} on @b{no-next-method}
  2501. signals an error of @i{type} @b{error}.
  2502. [Editorial Note by KMP: perhaps control-error??]
  2503. @subsubheading See Also::
  2504. @ref{call-next-method}
  2505. @node remove-method, make-instance, no-next-method, Objects Dictionary
  2506. @subsection remove-method [Standard Generic Function]
  2507. @subsubheading Syntax::
  2508. @code{remove-method} @i{generic-function method} @result{} @i{generic-function}
  2509. @subsubheading Method Signatures::
  2510. @code{remove-method} @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
  2511. method}
  2512. @subsubheading Arguments and Values::
  2513. @i{generic-function}---a @i{generic function}.
  2514. @i{method}---a @i{method}.
  2515. @subsubheading Description::
  2516. The @i{generic function} @b{remove-method} removes a @i{method} from @i{generic-function}
  2517. by modifying the @i{generic-function} (if necessary).
  2518. @b{remove-method} must not signal an error if the @i{method}
  2519. is not one of the @i{methods} on the @i{generic-function}.
  2520. @subsubheading See Also::
  2521. @ref{find-method}
  2522. @node make-instance, make-instances-obsolete, remove-method, Objects Dictionary
  2523. @subsection make-instance [Standard Generic Function]
  2524. @subsubheading Syntax::
  2525. @code{make-instance} @i{class {&rest} initargs {&key} {&allow-other-keys}} @result{} @i{instance}
  2526. @subsubheading Method Signatures::
  2527. @code{make-instance} @i{@r{(}@i{class} @b{standard-class}@r{)} {&rest} initargs}
  2528. @code{make-instance} @i{@r{(}@i{class} @b{symbol}@r{)} {&rest} initargs}
  2529. @subsubheading Arguments and Values::
  2530. @i{class}---a @i{class},
  2531. or a @i{symbol} that names a @i{class}.
  2532. @i{initargs}---an @i{initialization argument list}.
  2533. @i{instance}---a @i{fresh} @i{instance} of @i{class} @i{class}.
  2534. @subsubheading Description::
  2535. The @i{generic function} @b{make-instance}
  2536. creates and returns a new @i{instance} of the given @i{class}.
  2537. If the second of the above @i{methods} is selected,
  2538. that @i{method} invokes @b{make-instance} on the arguments
  2539. @t{(find-class @i{class})} and @i{initargs}.
  2540. The initialization arguments are checked within @b{make-instance}.
  2541. The @i{generic function} @b{make-instance}
  2542. may be used as described in @ref{Object Creation and Initialization}.
  2543. @subsubheading Exceptional Situations::
  2544. If any of the initialization arguments has not
  2545. been declared as valid, an error of @i{type} @b{error} is signaled.
  2546. @subsubheading See Also::
  2547. @ref{defclass}
  2548. ,
  2549. @ref{class-of}
  2550. ,
  2551. @ref{allocate-instance}
  2552. ,
  2553. @ref{Initialize-Instance}
  2554. ,
  2555. @ref{Object Creation and Initialization}
  2556. @node make-instances-obsolete, make-load-form, make-instance, Objects Dictionary
  2557. @subsection make-instances-obsolete [Standard Generic Function]
  2558. @subsubheading Syntax::
  2559. @code{make-instances-obsolete} @i{class} @result{} @i{class}
  2560. @subsubheading Method Signatures::
  2561. @code{make-instances-obsolete} @i{@r{(}@i{class} @b{standard-class}@r{)}}
  2562. @code{make-instances-obsolete} @i{@r{(}@i{class} @b{symbol}@r{)}}
  2563. @subsubheading Arguments and Values::
  2564. @i{class}---a @i{class designator}.
  2565. @subsubheading Description::
  2566. The @i{function} @b{make-instances-obsolete} has the effect of
  2567. initiating the process of updating the instances of the
  2568. @i{class}. During updating, the generic function
  2569. @b{update-instance-for-redefined-class} will be invoked.
  2570. The generic function @b{make-instances-obsolete} is invoked
  2571. automatically by the system when @b{defclass} has been used to
  2572. redefine an existing standard class and the set of local
  2573. @i{slots} @i{accessible} in an
  2574. instance is changed or the order of @i{slots} in storage is changed. It
  2575. can also be explicitly invoked by the user.
  2576. If the second of the above @i{methods} is selected, that
  2577. @i{method} invokes
  2578. @b{make-instances-obsolete} on @t{(find-class @i{class})}.
  2579. @subsubheading Examples::
  2580. @subsubheading See Also::
  2581. @ref{update-instance-for-redefined-class}
  2582. ,
  2583. @ref{Redefining Classes}
  2584. @node make-load-form, make-load-form-saving-slots, make-instances-obsolete, Objects Dictionary
  2585. @subsection make-load-form [Standard Generic Function]
  2586. @subsubheading Syntax::
  2587. @code{make-load-form} @i{object {&optional} environment} @result{} @i{creation-form@r{[}, initialization-form@r{]}}
  2588. @subsubheading Method Signatures::
  2589. @code{make-load-form} @i{@r{(}@i{object} @b{standard-object}@r{)} {&optional} environment}
  2590. @code{make-load-form} @i{@r{(}@i{object} @b{structure-object}@r{)} {&optional} environment}
  2591. @code{make-load-form} @i{@r{(}@i{object} @b{condition}@r{)} {&optional} environment}
  2592. @code{make-load-form} @i{@r{(}@i{object} @b{class}@r{)} {&optional} environment}
  2593. @subsubheading Arguments and Values::
  2594. @i{object}---an @i{object}.
  2595. @i{environment}---an @i{environment object}.
  2596. @i{creation-form}---a @i{form}.
  2597. @i{initialization-form}---a @i{form}.
  2598. @subsubheading Description::
  2599. The @i{generic function} @b{make-load-form} creates and returns
  2600. one or two @i{forms},
  2601. a @i{creation-form}
  2602. and an @i{initialization-form},
  2603. that enable @b{load} to construct an @i{object}
  2604. equivalent to @i{object}.
  2605. @i{Environment} is an @i{environment object}
  2606. corresponding to the @i{lexical environment}
  2607. in which the @i{forms} will be processed.
  2608. The @i{file compiler} calls @b{make-load-form} to process certain
  2609. @i{classes} of @i{literal objects}; see @ref{Additional Constraints on Externalizable Objects}.
  2610. @i{Conforming programs} may call @b{make-load-form} directly,
  2611. providing @i{object} is a @i{generalized instance} of
  2612. @b{standard-object}, @b{structure-object},
  2613. or @b{condition}.
  2614. The creation form is a @i{form} that, when evaluated at
  2615. @b{load} time, should return an @i{object} that
  2616. is equivalent to @i{object}. The exact meaning of
  2617. equivalent depends on the @i{type} of @i{object}
  2618. and is up to the programmer who defines a @i{method} for
  2619. @b{make-load-form};
  2620. see @ref{Literal Objects in Compiled Files}.
  2621. The initialization form is a @i{form} that, when evaluated at @b{load} time,
  2622. should perform further initialization of the @i{object}.
  2623. The value returned by the initialization form is ignored.
  2624. If @b{make-load-form}
  2625. returns only one value,
  2626. the initialization form is @b{nil}, which has no effect.
  2627. If @i{object} appears as a constant in the initialization form,
  2628. at @b{load} time it will be replaced by the equivalent @i{object}
  2629. constructed by the creation form;
  2630. this is how the further initialization gains access to the @i{object}.
  2631. Both the @i{creation-form} and the @i{initialization-form} may contain references
  2632. to any @i{externalizable object}.
  2633. However, there must not be any circular dependencies in creation forms.
  2634. An example of a circular dependency is when the creation form for the
  2635. object @t{X} contains a reference to the object @t{Y},
  2636. and the creation form for the object @t{Y} contains a reference to the object @t{X}.
  2637. Initialization forms are not subject to any restriction against circular dependencies,
  2638. which is the reason that initialization forms exist;
  2639. see the example of circular data structures below.
  2640. The creation form for an @i{object} is always @i{evaluated} before the
  2641. initialization form for that @i{object}. When either the creation form or
  2642. the initialization form references other @i{objects} that have not been
  2643. referenced earlier in the @i{file} being @i{compiled}, the @i{compiler} ensures
  2644. that all of the referenced @i{objects} have been created before @i{evaluating}
  2645. the referencing @i{form}. When the referenced @i{object} is of a @i{type} which
  2646. the @i{file compiler} processes using @b{make-load-form},
  2647. this involves @i{evaluating}
  2648. the creation form returned for it. (This is the reason for the
  2649. prohibition against circular references among creation forms).
  2650. Each initialization form is @i{evaluated} as soon as possible after its
  2651. associated creation form, as determined by data flow. If the
  2652. initialization form for an @i{object} does not reference any other @i{objects}
  2653. not referenced earlier in the @i{file} and processed by
  2654. the @i{file compiler}
  2655. using
  2656. @b{make-load-form}, the initialization form is evaluated immediately after
  2657. the creation form. If a creation or initialization form F does contain
  2658. references to such @i{objects}, the creation forms for those other objects
  2659. are evaluated before F, and the initialization forms for those other
  2660. @i{objects} are also evaluated before F whenever they do not depend on the
  2661. @i{object} created or initialized by F. Where these rules do not uniquely
  2662. determine an order of @i{evaluation} between two creation/initialization
  2663. forms, the order of @i{evaluation} is unspecified.
  2664. While these creation and initialization forms are being evaluated, the
  2665. @i{objects} are possibly in an uninitialized state,
  2666. analogous to the state
  2667. of an @i{object}
  2668. between the time it has been created by @b{allocate-instance}
  2669. and it has been processed fully by
  2670. @b{initialize-instance}. Programmers
  2671. writing @i{methods} for
  2672. @b{make-load-form} must take care in manipulating
  2673. @i{objects} not to depend on
  2674. @i{slots} that have not yet been initialized.
  2675. It is @i{implementation-dependent}
  2676. whether @b{load} calls @b{eval} on the
  2677. @i{forms} or does some
  2678. other operation that has an equivalent effect. For example, the
  2679. @i{forms} might be translated into different but equivalent
  2680. @i{forms} and
  2681. then evaluated, they might be compiled and the resulting functions
  2682. called by @b{load},
  2683. or they might be interpreted by a special-purpose
  2684. function different from @b{eval}.
  2685. All that is required is that the
  2686. effect be equivalent to evaluating the @i{forms}.
  2687. The @i{method} @i{specialized} on @b{class} returns a creation
  2688. @i{form} using the @i{name} of the @i{class} if the @i{class} has
  2689. a @i{proper name} in @i{environment}, signaling an error of @i{type} @b{error}
  2690. if it does not have a @i{proper name}. @i{Evaluation} of the creation
  2691. @i{form} uses the @i{name} to find the @i{class} with that
  2692. @i{name}, as if by @i{calling} @b{find-class}. If a @i{class}
  2693. with that @i{name} has not been defined, then a @i{class} may be
  2694. computed in an @i{implementation-defined} manner. If a @i{class}
  2695. cannot be returned as the result of @i{evaluating} the creation
  2696. @i{form}, then an error of @i{type} @b{error} is signaled.
  2697. Both @i{conforming implementations} and @i{conforming programs} may
  2698. further @i{specialize} @b{make-load-form}.
  2699. @subsubheading Examples::
  2700. @example
  2701. (defclass obj ()
  2702. ((x :initarg :x :reader obj-x)
  2703. (y :initarg :y :reader obj-y)
  2704. (dist :accessor obj-dist)))
  2705. @result{} #<STANDARD-CLASS OBJ 250020030>
  2706. (defmethod shared-initialize :after ((self obj) slot-names &rest keys)
  2707. (declare (ignore slot-names keys))
  2708. (unless (slot-boundp self 'dist)
  2709. (setf (obj-dist self)
  2710. (sqrt (+ (expt (obj-x self) 2) (expt (obj-y self) 2))))))
  2711. @result{} #<STANDARD-METHOD SHARED-INITIALIZE (:AFTER) (OBJ T) 26266714>
  2712. (defmethod make-load-form ((self obj) &optional environment)
  2713. (declare (ignore environment))
  2714. ;; Note that this definition only works because X and Y do not
  2715. ;; contain information which refers back to the object itself.
  2716. ;; For a more general solution to this problem, see revised example below.
  2717. `(make-instance ',(class-of self)
  2718. :x ',(obj-x self) :y ',(obj-y self)))
  2719. @result{} #<STANDARD-METHOD MAKE-LOAD-FORM (OBJ) 26267532>
  2720. (setq obj1 (make-instance 'obj :x 3.0 :y 4.0)) @result{} #<OBJ 26274136>
  2721. (obj-dist obj1) @result{} 5.0
  2722. (make-load-form obj1) @result{} (MAKE-INSTANCE 'OBJ :X '3.0 :Y '4.0)
  2723. @end example
  2724. In the above example, an equivalent @i{instance} of @t{obj} is
  2725. reconstructed by using the values of two of its @i{slots}.
  2726. The value of the third @i{slot} is derived from those two values.
  2727. Another way to write the @b{make-load-form} @i{method}
  2728. in that example is to use @b{make-load-form-saving-slots}.
  2729. The code it generates might yield a slightly different result
  2730. from the @b{make-load-form} @i{method} shown above,
  2731. but the operational effect will be the same. For example:
  2732. @example
  2733. ;; Redefine method defined above.
  2734. (defmethod make-load-form ((self obj) &optional environment)
  2735. (make-load-form-saving-slots self
  2736. :slot-names '(x y)
  2737. :environment environment))
  2738. @result{} #<STANDARD-METHOD MAKE-LOAD-FORM (OBJ) 42755655>
  2739. ;; Try MAKE-LOAD-FORM on object created above.
  2740. (make-load-form obj1)
  2741. @result{} (ALLOCATE-INSTANCE '#<STANDARD-CLASS OBJ 250020030>),
  2742. (PROGN
  2743. (SETF (SLOT-VALUE '#<OBJ 26274136> 'X) '3.0)
  2744. (SETF (SLOT-VALUE '#<OBJ 26274136> 'Y) '4.0)
  2745. (INITIALIZE-INSTANCE '#<OBJ 26274136>))
  2746. @end example
  2747. In the following example, @i{instances} of @t{my-frob} are ``interned''
  2748. in some way. An equivalent @i{instance} is reconstructed by using the
  2749. value of the name slot as a key for searching existing @i{objects}.
  2750. In this case the programmer has chosen to create a new @i{object}
  2751. if no existing @i{object} is found; alternatively an error could
  2752. have been signaled in that case.
  2753. @example
  2754. (defclass my-frob ()
  2755. ((name :initarg :name :reader my-name)))
  2756. (defmethod make-load-form ((self my-frob) &optional environment)
  2757. (declare (ignore environment))
  2758. `(find-my-frob ',(my-name self) :if-does-not-exist :create))
  2759. @end example
  2760. In the following example, the data structure to be dumped is circular,
  2761. because each parent has a list of its children and each child has a reference
  2762. back to its parent. If @b{make-load-form} is called on one
  2763. @i{object} in such a structure, the creation form creates an equivalent
  2764. @i{object} and fills in the children slot, which forces creation of equivalent
  2765. @i{objects} for all of its children, grandchildren, etc. At this point
  2766. none of the parent @i{slots} have been filled in.
  2767. The initialization form fills in the parent @i{slot}, which forces creation
  2768. of an equivalent @i{object} for the parent if it was not already created.
  2769. Thus the entire tree is recreated at @b{load} time.
  2770. At compile time, @b{make-load-form} is called once for each @i{object}
  2771. in the tree.
  2772. All of the creation forms are evaluated,
  2773. in @i{implementation-dependent} order,
  2774. and then all of the initialization forms are evaluated,
  2775. also in @i{implementation-dependent} order.
  2776. @example
  2777. (defclass tree-with-parent () ((parent :accessor tree-parent)
  2778. (children :initarg :children)))
  2779. (defmethod make-load-form ((x tree-with-parent) &optional environment)
  2780. (declare (ignore environment))
  2781. (values
  2782. ;; creation form
  2783. `(make-instance ',(class-of x) :children ',(slot-value x 'children))
  2784. ;; initialization form
  2785. `(setf (tree-parent ',x) ',(slot-value x 'parent))))
  2786. @end example
  2787. In the following example, the data structure to be dumped has no special
  2788. properties and an equivalent structure can be reconstructed
  2789. simply by reconstructing the @i{slots}' contents.
  2790. @example
  2791. (defstruct my-struct a b c)
  2792. (defmethod make-load-form ((s my-struct) &optional environment)
  2793. (make-load-form-saving-slots s :environment environment))
  2794. @end example
  2795. @subsubheading Exceptional Situations::
  2796. The @i{methods} @i{specialized} on
  2797. @b{standard-object},
  2798. @b{structure-object},
  2799. and @b{condition}
  2800. all signal an error of @i{type} @b{error}.
  2801. It is @i{implementation-dependent} whether @i{calling}
  2802. @b{make-load-form} on a @i{generalized instance} of a
  2803. @i{system class} signals an error or returns creation and
  2804. initialization @i{forms}.
  2805. @subsubheading See Also::
  2806. @ref{compile-file}
  2807. ,
  2808. @ref{make-load-form-saving-slots}
  2809. ,
  2810. @ref{Additional Constraints on Externalizable Objects}
  2811. @ref{Evaluation},
  2812. @ref{Compilation}
  2813. @subsubheading Notes::
  2814. The @i{file compiler}
  2815. calls @b{make-load-form} in specific circumstances
  2816. detailed in @ref{Additional Constraints on Externalizable Objects}.
  2817. Some @i{implementations} may provide facilities for defining new
  2818. @i{subclasses} of @i{classes} which are specified as
  2819. @i{system classes}. (Some likely candidates include
  2820. @b{generic-function}, @b{method}, and @b{stream}). Such
  2821. @i{implementations} should document how the @i{file compiler} processes
  2822. @i{instances} of such @i{classes} when encountered as
  2823. @i{literal objects}, and should document any relevant @i{methods}
  2824. for @b{make-load-form}.
  2825. @node make-load-form-saving-slots, with-accessors, make-load-form, Objects Dictionary
  2826. @subsection make-load-form-saving-slots [Function]
  2827. @code{make-load-form-saving-slots} @i{object {&key} slot-names environment}@*
  2828. @result{} @i{creation-form, initialization-form}
  2829. @subsubheading Arguments and Values::
  2830. @i{object}---an @i{object}.
  2831. @i{slot-names}---a @i{list}.
  2832. @i{environment}---an @i{environment object}.
  2833. @i{creation-form}---a @i{form}.
  2834. @i{initialization-form}---a @i{form}.
  2835. @subsubheading Description::
  2836. Returns @i{forms} that, when @i{evaluated}, will construct an
  2837. @i{object} equivalent to @i{object}, without @i{executing}
  2838. @i{initialization forms}. The @i{slots} in the new @i{object}
  2839. that correspond to initialized @i{slots} in @i{object} are
  2840. initialized using the values from @i{object}. Uninitialized @i{slots}
  2841. in @i{object} are not initialized in the new @i{object}.
  2842. @b{make-load-form-saving-slots} works for any @i{instance} of
  2843. @b{standard-object} or @b{structure-object}.
  2844. @i{Slot-names} is a @i{list} of the names of the
  2845. @i{slots} to preserve. If @i{slot-names} is not
  2846. supplied, its value is all of the @i{local slots}.
  2847. @b{make-load-form-saving-slots} returns two values,
  2848. thus it can deal with circular structures.
  2849. Whether the result is useful in an application depends on
  2850. whether the @i{object}'s @i{type} and slot contents
  2851. fully capture the application's idea of the @i{object}'s state.
  2852. @i{Environment} is the environment in which the forms will be processed.
  2853. @subsubheading See Also::
  2854. @ref{make-load-form}
  2855. ,
  2856. @ref{make-instance}
  2857. ,
  2858. @ref{setf; psetf}
  2859. ,
  2860. @ref{slot-value}
  2861. ,
  2862. @ref{slot-makunbound}
  2863. @subsubheading Notes::
  2864. @b{make-load-form-saving-slots} can be useful in user-written
  2865. @b{make-load-form} methods.
  2866. When the @i{object} is an @i{instance} of @b{standard-object},
  2867. @b{make-load-form-saving-slots} could return a creation form that
  2868. @i{calls} @b{allocate-instance} and an initialization form that
  2869. contains @i{calls} to @b{setf} of @b{slot-value} and
  2870. @b{slot-makunbound}, though other @i{functions} of similar effect
  2871. might actually be used.
  2872. @node with-accessors, with-slots, make-load-form-saving-slots, Objects Dictionary
  2873. @subsection with-accessors [Macro]
  2874. @code{with-accessors} @i{{@r{(}@{@i{slot-entry}@}{*}@r{)}}
  2875. instance-form
  2876. @{@i{declaration}@}{*} @{@i{form}@}{*}}@*
  2877. @result{} @i{@{@i{result}@}{*}}
  2878. @w{@i{slot-entry} ::=@r{(}variable-name accessor-name@r{)}}
  2879. @subsubheading Arguments and Values::
  2880. @i{variable-name}---a @i{variable name}; not evaluated.
  2881. @i{accessor-name}---a @i{function name}; not evaluated.
  2882. @i{instance-form}---a @i{form}; evaluated.
  2883. @i{declaration}---a @b{declare} @i{expression}; not evaluated.
  2884. @i{forms}---an @i{implicit progn}.
  2885. @i{results}---the @i{values} returned by the @i{forms}.
  2886. @subsubheading Description::
  2887. Creates a lexical environment in which
  2888. the slots specified by
  2889. @i{slot-entry} are lexically available through their accessors as if
  2890. they were variables. The macro @b{with-accessors} invokes the
  2891. appropriate accessors to @i{access} the @i{slots} specified
  2892. by @i{slot-entry}. Both @b{setf}
  2893. and @b{setq} can be used to set the value of the @i{slot}.
  2894. @subsubheading Examples::
  2895. @example
  2896. (defclass thing ()
  2897. ((x :initarg :x :accessor thing-x)
  2898. (y :initarg :y :accessor thing-y)))
  2899. @result{} #<STANDARD-CLASS THING 250020173>
  2900. (defmethod (setf thing-x) :before (new-x (thing thing))
  2901. (format t "~&Changing X from ~D to ~D in ~S.~
  2902. (thing-x thing) new-x thing))
  2903. (setq thing1 (make-instance 'thing :x 1 :y 2)) @result{} #<THING 43135676>
  2904. (setq thing2 (make-instance 'thing :x 7 :y 8)) @result{} #<THING 43147374>
  2905. (with-accessors ((x1 thing-x) (y1 thing-y))
  2906. thing1
  2907. (with-accessors ((x2 thing-x) (y2 thing-y))
  2908. thing2
  2909. (list (list x1 (thing-x thing1) y1 (thing-y thing1)
  2910. x2 (thing-x thing2) y2 (thing-y thing2))
  2911. (setq x1 (+ y1 x2))
  2912. (list x1 (thing-x thing1) y1 (thing-y thing1)
  2913. x2 (thing-x thing2) y2 (thing-y thing2))
  2914. (setf (thing-x thing2) (list x1))
  2915. (list x1 (thing-x thing1) y1 (thing-y thing1)
  2916. x2 (thing-x thing2) y2 (thing-y thing2)))))
  2917. @t{ |> } Changing X from 1 to 9 in #<THING 43135676>.
  2918. @t{ |> } Changing X from 7 to (9) in #<THING 43147374>.
  2919. @result{} ((1 1 2 2 7 7 8 8)
  2920. 9
  2921. (9 9 2 2 7 7 8 8)
  2922. (9)
  2923. (9 9 2 2 (9) (9) 8 8))
  2924. @end example
  2925. @subsubheading Affected By::
  2926. @b{defclass}
  2927. @subsubheading Exceptional Situations::
  2928. The consequences are undefined if any @i{accessor-name} is not the name
  2929. of an accessor for the @i{instance}.
  2930. @subsubheading See Also::
  2931. @ref{with-slots}
  2932. ,
  2933. @ref{symbol-macrolet}
  2934. @subsubheading Notes::
  2935. A @b{with-accessors} expression of the form:
  2936. @center
  2937. @example
  2938. @w{@t{(with-accessors} ({slot-entry}_1 ...{slot-entry}_n) @i{instance-form} {form}_1 ...{form}_k)}@*
  2939. @end example
  2940. @noindent
  2941. expands into the equivalent of
  2942. @center
  2943. @example
  2944. @w{@t{(}@t{let ((}in @i{instance-form}@t{))}}@*
  2945. @w{ @t{(symbol-macrolet (}{Q}_1... {Q}_n@t{)} {form}_1 ...{form}_k@t{))}}@*
  2946. @end example
  2947. @noindent
  2948. where {Q}_i is
  2949. @center {
  2950. @example
  2951. @t{(}{variable-name}_i ()
  2952. @t{({accessor-name}_i in))}
  2953. @end example
  2954. }
  2955. @node with-slots, defclass, with-accessors, Objects Dictionary
  2956. @subsection with-slots [Macro]
  2957. @code{with-slots} @i{@r{(}@{@i{slot-entry}@}{*}@r{)}
  2958. instance-form
  2959. @{@i{declaration}@}{*} @{@i{form}@}{*}}@*
  2960. @result{} @i{@{@i{result}@}{*}}
  2961. @w{@i{slot-entry} ::=slot-name | @r{(}variable-name slot-name@r{)}}
  2962. @subsubheading Arguments and Values::
  2963. @i{slot-name}---a @i{slot} @i{name}; not evaluated.
  2964. @i{variable-name}---a @i{variable name}; not evaluated.
  2965. @i{instance-form}---a @i{form}; evaluted to produce @i{instance}.
  2966. @i{instance}---an @i{object}.
  2967. @i{declaration}---a @b{declare} @i{expression}; not evaluated.
  2968. @i{forms}---an @i{implicit progn}.
  2969. @i{results}---the @i{values} returned by the @i{forms}.
  2970. @subsubheading Description::
  2971. The macro @b{with-slots} @i{establishes} a
  2972. @i{lexical environment}
  2973. for referring to the @i{slots} in the @i{instance}
  2974. named by the given @i{slot-names}
  2975. as though they were @i{variables}. Within such a context
  2976. the value of the @i{slot} can be specified by using its slot name, as if
  2977. it were a lexically bound variable. Both @b{setf} and @b{setq}
  2978. can be used to set the value of the @i{slot}.
  2979. The macro @b{with-slots} translates an appearance of the slot
  2980. name as a @i{variable} into a call to @b{slot-value}.
  2981. @subsubheading Examples::
  2982. @example
  2983. (defclass thing ()
  2984. ((x :initarg :x :accessor thing-x)
  2985. (y :initarg :y :accessor thing-y)))
  2986. @result{} #<STANDARD-CLASS THING 250020173>
  2987. (defmethod (setf thing-x) :before (new-x (thing thing))
  2988. (format t "~&Changing X from ~D to ~D in ~S.~
  2989. (thing-x thing) new-x thing))
  2990. (setq thing (make-instance 'thing :x 0 :y 1)) @result{} #<THING 62310540>
  2991. (with-slots (x y) thing (incf x) (incf y)) @result{} 2
  2992. (values (thing-x thing) (thing-y thing)) @result{} 1, 2
  2993. (setq thing1 (make-instance 'thing :x 1 :y 2)) @result{} #<THING 43135676>
  2994. (setq thing2 (make-instance 'thing :x 7 :y 8)) @result{} #<THING 43147374>
  2995. (with-slots ((x1 x) (y1 y))
  2996. thing1
  2997. (with-slots ((x2 x) (y2 y))
  2998. thing2
  2999. (list (list x1 (thing-x thing1) y1 (thing-y thing1)
  3000. x2 (thing-x thing2) y2 (thing-y thing2))
  3001. (setq x1 (+ y1 x2))
  3002. (list x1 (thing-x thing1) y1 (thing-y thing1)
  3003. x2 (thing-x thing2) y2 (thing-y thing2))
  3004. (setf (thing-x thing2) (list x1))
  3005. (list x1 (thing-x thing1) y1 (thing-y thing1)
  3006. x2 (thing-x thing2) y2 (thing-y thing2)))))
  3007. @t{ |> } Changing X from 7 to (9) in #<THING 43147374>.
  3008. @result{} ((1 1 2 2 7 7 8 8)
  3009. 9
  3010. (9 9 2 2 7 7 8 8)
  3011. (9)
  3012. (9 9 2 2 (9) (9) 8 8))
  3013. @end example
  3014. @subsubheading Affected By::
  3015. @b{defclass}
  3016. @subsubheading Exceptional Situations::
  3017. The consequences are undefined if any @i{slot-name} is not the name
  3018. of a @i{slot} in the @i{instance}.
  3019. @subsubheading See Also::
  3020. @ref{with-accessors}
  3021. ,
  3022. @ref{slot-value}
  3023. ,
  3024. @ref{symbol-macrolet}
  3025. @subsubheading Notes::
  3026. A @b{with-slots} expression of the form:
  3027. @center
  3028. @example
  3029. @w{@t{(with-slots} ({slot-entry}_1 ...{slot-entry}_n) @i{instance-form} {form}_1 ...{form}_k)}@*
  3030. @end example
  3031. @noindent
  3032. expands into the equivalent of
  3033. @center
  3034. @example
  3035. @w{@t{(}@t{let ((}in @i{instance-form}@t{))}}@*
  3036. @w{ @t{(symbol-macrolet (}{Q}_1... {Q}_n@t{)} {form}_1 ...{form}_k@t{))}}@*
  3037. @end example
  3038. @noindent
  3039. where {Q}_i is
  3040. @center
  3041. @example
  3042. @t{(}{slot-entry}_i ()
  3043. @t{(slot-value }in '{slot-entry}_i@t{))}
  3044. @end example
  3045. @noindent
  3046. if {slot-entry}_i is a @i{symbol}
  3047. and is
  3048. @center {
  3049. @example
  3050. @t{(}{variable-name}_i ()
  3051. @t{(slot-value }in '{slot-name}_i@t{))}
  3052. @end example
  3053. }
  3054. @noindent
  3055. if {slot-entry}_i
  3056. is of the form
  3057. @center
  3058. @example
  3059. @t{(}{variable-name}_i
  3060. {slot-name}_i@t{)}
  3061. @end example
  3062. @node defclass, defgeneric, with-slots, Objects Dictionary
  3063. @subsection defclass [Macro]
  3064. @code{defclass} @i{@i{class-name} @r{(}@{@i{superclass-name}@}{*}@r{)}
  3065. @r{(}@{{@i{slot-specifier}}@}{*}@r{)}
  3066. [[!@i{class-option}]]}@*
  3067. @result{} @i{new-class}
  3068. @w{ slot-specifier::=@i{slot-name} | (@i{slot-name} [[!@i{slot-option}]])}@*
  3069. @w{ @i{slot-name}::= @i{symbol}}@*
  3070. @w{ slot-option::=@{{:reader} @i{reader-function-name}@}{*} |}@*
  3071. @w{ @{{:writer} @i{writer-function-name}@}{*} |}@*
  3072. @w{ @{{:accessor} @i{reader-function-name}@}{*} |}@*
  3073. @w{ @{{:allocation} @i{allocation-type}@} |}@*
  3074. @w{ @{{:initarg} @i{initarg-name}@}{*} |}@*
  3075. @w{ @{{:initform} @i{form}@} |}@*
  3076. @w{ @{{:type} @i{type-specifier}@} |}@*
  3077. @w{ @{{:documentation} @i{string}@}}@*
  3078. @w{ @i{function-name}::= @{@i{symbol} | @t{(setf @i{symbol})}@}}@*
  3079. @w{ class-option::=(@t{:default-initargs} @t{.} @i{initarg-list}) |}@*
  3080. @w{ (@t{:documentation} @i{string}) |}@*
  3081. @w{ (@t{:metaclass} @i{class-name})}@*
  3082. @subsubheading Arguments and Values::
  3083. @i{Class-name}---a @i{non-nil} @i{symbol}.
  3084. @i{Superclass-name}--a @i{non-nil} @i{symbol}.
  3085. @i{Slot-name}--a @i{symbol}.
  3086. The @i{slot-name} argument is
  3087. a @i{symbol} that is syntactically valid for use as a variable name.
  3088. @i{Reader-function-name}---a @i{non-nil} @i{symbol}.
  3089. @t{:reader} can be supplied more than once for a given @i{slot}.
  3090. @i{Writer-function-name}---a @i{generic function} name.
  3091. @t{:writer} can be supplied more than once for a given @i{slot}.
  3092. @i{Reader-function-name}---a @i{non-nil} @i{symbol}.
  3093. @t{:accessor} can be supplied more than once for a given @i{slot}.
  3094. @i{Allocation-type}---(member @t{:instance} @t{:class}).
  3095. @t{:allocation} can be supplied once at most for a given @i{slot}.
  3096. @i{Initarg-name}---a @i{symbol}.
  3097. @t{:initarg} can be supplied more than once for a given @i{slot}.
  3098. @i{Form}---a @i{form}.
  3099. @t{:init-form} can be supplied once at most for a given @i{slot}.
  3100. @i{Type-specifier}---a @i{type specifier}.
  3101. @t{:type} can be supplied once at most for a given @i{slot}.
  3102. @i{Class-option}--- refers to the @i{class} as a whole or to all class @i{slots}.
  3103. @i{Initarg-list}---a @i{list} of alternating initialization argument
  3104. @i{names} and default initial value @i{forms}.
  3105. @t{:default-initargs} can be supplied at most once.
  3106. @i{Class-name}---a @i{non-nil} @i{symbol}.
  3107. @t{:metaclass} can be supplied once at most.
  3108. @i{new-class}---the new @i{class} @i{object}.
  3109. @subsubheading Description::
  3110. The macro @b{defclass} defines a new named @i{class}. It returns
  3111. the new @i{class} @i{object} as its result.
  3112. The syntax of @b{defclass} provides options for specifying
  3113. initialization arguments for @i{slots}, for specifying default
  3114. initialization values for @i{slots}, and for requesting that
  3115. @i{methods} on specified @i{generic functions} be automatically
  3116. generated for reading and writing the values of @i{slots}.
  3117. No reader or writer functions are defined by default;
  3118. their generation must be explicitly requested. However,
  3119. @i{slots} can always be @i{accessed} using @b{slot-value}.
  3120. Defining a new @i{class} also causes a @i{type} of the same name to be
  3121. defined. The predicate @t{(typep @i{object} @i{class-name})} returns
  3122. true if the @i{class} of the given @i{object} is
  3123. the @i{class} named by @i{class-name} itself or
  3124. a subclass of the class @i{class-name}. A @i{class} @i{object}
  3125. can be used as a @i{type specifier}.
  3126. Thus @t{(typep @i{object} @i{class})} returns @i{true}
  3127. if the @i{class} of the @i{object} is
  3128. @i{class} itself or a subclass of @i{class}.
  3129. The @i{class-name} argument specifies the @i{proper name}
  3130. of the new @i{class}.
  3131. If a @i{class} with the same @i{proper name} already exists
  3132. and that @i{class} is an @i{instance} of @b{standard-class},
  3133. and if the @b{defclass} form for the definition of the new @i{class}
  3134. specifies a @i{class} of @i{class} @b{standard-class},
  3135. the existing @i{class} is redefined,
  3136. and instances of it (and its @i{subclasses}) are updated
  3137. to the new definition at the time that they are next @i{accessed}.
  3138. For details, see @ref{Redefining Classes}.
  3139. Each @i{superclass-name} argument
  3140. specifies a direct @i{superclass} of the new @i{class}.
  3141. If the @i{superclass} list is empty, then the @i{superclass}
  3142. defaults depending on the @i{metaclass},
  3143. with @b{standard-object} being the
  3144. default for @b{standard-class}.
  3145. The new @i{class} will
  3146. inherit @i{slots} and @i{methods}
  3147. from each of its direct @i{superclasses}, from
  3148. their direct @i{superclasses}, and so on.
  3149. For a discussion of how @i{slots} and @i{methods} are inherited,
  3150. see @ref{Inheritance}.
  3151. The following slot options are available:
  3152. @table @asis
  3153. @item @t{*}
  3154. The @t{:reader} slot option specifies that an @i{unqualified method} is
  3155. to be defined on the @i{generic function} named @i{reader-function-name}
  3156. to read the value of the given @i{slot}.
  3157. @item @t{*}
  3158. The @t{:writer} slot option specifies that an @i{unqualified method} is
  3159. to be defined on the @i{generic function} named @i{writer-function-name}
  3160. to write the value of the @i{slot}.
  3161. @item @t{*}
  3162. The @t{:accessor} slot option specifies that an @i{unqualified method}
  3163. is to be defined on the generic function named @i{reader-function-name}
  3164. to read the value of the given @i{slot}
  3165. and that an @i{unqualified method} is to be defined on the
  3166. @i{generic function} named @t{(setf @i{reader-function-name})} to be
  3167. used with @b{setf} to modify the value of the @i{slot}.
  3168. @item @t{*}
  3169. The @t{:allocation} slot option is used to specify where storage is
  3170. to be allocated for the given @i{slot}. Storage for a
  3171. @i{slot} can be located
  3172. in each instance or in the @i{class} @i{object} itself.
  3173. The value of the @i{allocation-type} argument can be
  3174. either the keyword @t{:instance}
  3175. or the keyword @t{:class}. If the @t{:allocation}
  3176. slot option is not specified, the effect is the same as specifying
  3177. @t{:allocation :instance}.
  3178. @table @asis
  3179. @item --
  3180. If @i{allocation-type} is @t{:instance}, a @i{local slot} of
  3181. the name @i{slot-name} is allocated in each instance of the
  3182. @i{class}.
  3183. @item --
  3184. If @i{allocation-type} is @t{:class}, a shared
  3185. @i{slot} of the given
  3186. name is allocated in the @i{class} @i{object} created by this @b{defclass}
  3187. form. The value of the @i{slot} is shared by all
  3188. @i{instances} of the @i{class}.
  3189. If a class C_1 defines such a @i{shared slot}, any
  3190. subclass C_2 of
  3191. C_1 will share this single @i{slot} unless the @b{defclass} form
  3192. for C_2 specifies a @i{slot} of the same @i{name} or there is a
  3193. superclass of C_2 that precedes C_1 in the class precedence
  3194. list of C_2 and that defines a @i{slot} of the same @i{name}.
  3195. @end table
  3196. @item @t{*}
  3197. The @t{:initform} slot option is used to provide a default
  3198. initial value form to be used in the initialization of the @i{slot}. This
  3199. @i{form} is evaluated every time it is used to initialize the
  3200. @i{slot}. The
  3201. lexical environment in which this @i{form} is evaluated is the lexical
  3202. environment in which the @b{defclass} form was evaluated.
  3203. Note that the lexical environment refers both to variables and to
  3204. functions. For @i{local slots}, the dynamic environment is the dynamic
  3205. environment in which @b{make-instance} is called; for shared
  3206. @i{slots}, the dynamic environment is the dynamic environment in which the
  3207. @b{defclass} form was evaluated.
  3208. See @ref{Object Creation and Initialization}.
  3209. No implementation is permitted to extend the syntax of @b{defclass}
  3210. to allow @t{(@i{slot-name} @i{form})} as an abbreviation for
  3211. @t{(@i{slot-name} :initform @i{form})}.
  3212. [Reviewer Note by Barmar: Can you extend this to mean something else?]
  3213. @item @t{*}
  3214. The @t{:initarg} slot option declares an initialization
  3215. argument named @i{initarg-name} and specifies that this
  3216. initialization argument initializes the given @i{slot}. If the
  3217. initialization argument has a value in the call to
  3218. @b{initialize-instance}, the value will be stored into the given @i{slot},
  3219. and the slot's @t{:initform} slot option, if any, is not
  3220. evaluated. If none of the initialization arguments specified for a
  3221. given @i{slot} has a value, the @i{slot} is initialized according to the
  3222. @t{:initform} slot option, if specified.
  3223. @item @t{*}
  3224. The @t{:type} slot option specifies that the contents of the
  3225. @i{slot} will always be of the specified data type. It effectively
  3226. declares the result type of the reader generic function when applied
  3227. to an @i{object} of this @i{class}. The consequences of attempting to store in a
  3228. @i{slot} a value that does not satisfy the type of the @i{slot} are undefined.
  3229. The @t{:type} slot option is further discussed in
  3230. @ref{Inheritance of Slots and Slot Options}.
  3231. @item @t{*}
  3232. The @t{:documentation} slot option provides a @i{documentation string}
  3233. for the @i{slot}. @t{:documentation} can be supplied once at most
  3234. for a given @i{slot}.
  3235. [Reviewer Note by Barmar: How is this retrieved?]
  3236. @end table
  3237. Each class option is an option that refers to the @i{class} as a whole.
  3238. The following class options are available:
  3239. @table @asis
  3240. @item @t{*}
  3241. The @t{:default-initargs} class option is followed by a list of
  3242. alternating initialization argument @i{names} and default initial value
  3243. forms. If any of these initialization arguments does not appear in
  3244. the initialization argument list supplied to @b{make-instance}, the
  3245. corresponding default initial value form is evaluated, and the
  3246. initialization argument @i{name} and the @i{form}'s value are added to the end
  3247. of the initialization argument list before the instance is created;
  3248. see @ref{Object Creation and Initialization}.
  3249. The default initial value form is evaluated each time it is used. The lexical
  3250. environment in which this @i{form} is evaluated is the lexical environment
  3251. in which the @b{defclass} form was evaluated. The dynamic
  3252. environment is the dynamic environment in which @b{make-instance}
  3253. was called. If an initialization argument @i{name} appears more than once
  3254. in a @t{:default-initargs} class option, an error is signaled.
  3255. @item @t{*}
  3256. The @t{:documentation} class option causes a @i{documentation string}
  3257. to be attached with the @i{class} @i{object},
  3258. and attached with kind @b{type} to the @i{class-name}.
  3259. @t{:documentation} can be supplied once at most.
  3260. @item @t{*}
  3261. The @t{:metaclass} class option is used to specify that
  3262. instances of the @i{class} being defined are to have a different metaclass
  3263. than the default provided by the system (the @i{class} @b{standard-class}).
  3264. @end table
  3265. Note the following rules of @b{defclass} for @i{standard classes}:
  3266. @table @asis
  3267. @item @t{*}
  3268. It is not required that the @i{superclasses} of a @i{class} be defined before
  3269. the @b{defclass} form for that @i{class} is evaluated.
  3270. @item @t{*}
  3271. All the @i{superclasses} of a @i{class} must be defined before
  3272. an @i{instance} of the @i{class} can be made.
  3273. @item @t{*}
  3274. A @i{class} must be defined before it can be used as a parameter
  3275. specializer in a @b{defmethod} form.
  3276. @end table
  3277. The object system can be extended to cover situations where these rules are not
  3278. obeyed.
  3279. Some slot options are inherited by a @i{class} from its
  3280. @i{superclasses}, and
  3281. some can be shadowed or altered by providing a local slot description.
  3282. No class options except @t{:default-initargs} are inherited. For a
  3283. detailed description of how @i{slots} and slot options are inherited,
  3284. see @ref{Inheritance of Slots and Slot Options}.
  3285. The options to @b{defclass} can be extended. It is required that
  3286. all implementations signal an error if they observe a class option or
  3287. a slot option that is not implemented locally.
  3288. It is valid to specify more than one reader, writer, accessor, or
  3289. initialization argument for a @i{slot}. No other slot option can
  3290. appear
  3291. more than once in a single slot description, or an error is
  3292. signaled.
  3293. If no reader, writer, or accessor is specified for a @i{slot},
  3294. the @i{slot} can only be @i{accessed} by the @i{function} @b{slot-value}.
  3295. If a @b{defclass} @i{form} appears as a @i{top level form},
  3296. the @i{compiler} must make the @i{class} @i{name} be recognized as a
  3297. valid @i{type} @i{name} in subsequent declarations (as for @b{deftype})
  3298. and be recognized as a valid @i{class} @i{name} for @b{defmethod}
  3299. @i{parameter specializers} and for use as the @t{:metaclass} option of a
  3300. subsequent @b{defclass}. The @i{compiler} must make
  3301. the @i{class} definition
  3302. available to be returned by @b{find-class} when its @i{environment}
  3303. @i{argument} is a value received as the @i{environment parameter} of a @i{macro}.
  3304. @subsubheading Exceptional Situations::
  3305. If there are any duplicate slot names,
  3306. an error of @i{type} @b{program-error} is signaled.
  3307. If an initialization argument @i{name} appears more than once in
  3308. @t{:default-initargs} class option,
  3309. an error of @i{type} @b{program-error} is signaled.
  3310. If any of the following slot options appears more than once in a
  3311. single slot description, an error of @i{type} @b{program-error}
  3312. is signaled: @t{:allocation},
  3313. @t{:initform}, @t{:type}, @t{:documentation}.
  3314. It is required that all implementations signal
  3315. an error of @i{type} @b{program-error} if they observe a class option
  3316. or a slot option that is not implemented locally.
  3317. @subsubheading See Also::
  3318. @ref{documentation; (setf documentation)}
  3319. ,
  3320. @ref{Initialize-Instance}
  3321. ,
  3322. @ref{make-instance}
  3323. ,
  3324. @ref{slot-value}
  3325. ,
  3326. @ref{Classes},
  3327. @ref{Inheritance},
  3328. @ref{Redefining Classes},
  3329. @ref{Determining the Class Precedence List},
  3330. @ref{Object Creation and Initialization}
  3331. @node defgeneric, defmethod, defclass, Objects Dictionary
  3332. @subsection defgeneric [Macro]
  3333. @code{defgeneric} @i{function-name gf-lambda-list
  3334. [[!@i{option} | @{!@i{method-description}@}{*}]]}@*
  3335. @result{} @i{new-generic}
  3336. @w{@i{option} ::=@r{(}@t{:argument-precedence-order} @{@i{parameter-name}@}^+@r{)} |}
  3337. @w{ @r{(}@b{declare} @{@i{gf-declaration}@}^+@r{)} |}
  3338. @w{ @r{(}@t{:documentation} @i{gf-documentation}@r{)} |}
  3339. @w{ @r{(}@t{:method-combination} @i{method-combination} @{@i{method-combination-argument}@}{*}@r{)} |}
  3340. @w{ @r{(}@t{:generic-function-class} @i{generic-function-class}@r{)} |}
  3341. @w{ @r{(}@t{:method-class} @i{method-class}@r{)}}
  3342. @w{@i{method-description} ::=@r{(}@t{:method} @{@i{method-qualifier}@}{*} @i{specialized-lambda-list} {[[@{@i{declaration}@}{*} | @i{documentation}]]} @{@i{form}@}{*}@r{)}}
  3343. @subsubheading Arguments and Values::
  3344. @i{function-name}---a @i{function name}.
  3345. @i{generic-function-class}---a @i{non-nil} @i{symbol} naming a @i{class}.
  3346. @i{gf-declaration}---an @b{optimize} @i{declaration specifier};
  3347. other @i{declaration specifiers} are not permitted.
  3348. @i{gf-documentation}---a @i{string}; not evaluated.
  3349. @i{gf-lambda-list}---a @i{generic function lambda list}.
  3350. @i{method-class}---a @i{non-nil} @i{symbol} naming a @i{class}.
  3351. @i{method-combination-argument}---an @i{object.}
  3352. @i{method-combination-name}---a @i{symbol}
  3353. naming a @i{method combination} @i{type}.
  3354. @i{method-qualifiers},
  3355. @i{specialized-lambda-list},
  3356. @i{declarations},
  3357. @i{documentation},
  3358. @i{forms}---as per @b{defmethod}.
  3359. @i{new-generic}---the @i{generic function} @i{object}.
  3360. @i{parameter-name}---a @i{symbol} that names a @i{required parameter}
  3361. in the @i{lambda-list}.
  3362. (If the @t{:argument-precedence-order} option is specified,
  3363. each @i{required parameter} in the @i{lambda-list}
  3364. must be used exactly once as a @i{parameter-name}.)
  3365. @subsubheading Description::
  3366. The macro @b{defgeneric} is used to define a @i{generic function}
  3367. or to specify options and declarations that pertain
  3368. to a @i{generic function} as a whole.
  3369. If @i{function-name} is a
  3370. @i{list} it must be of the form @t{(setf @i{symbol})}.
  3371. If @t{(fboundp @i{function-name})} is @i{false}, a new
  3372. @i{generic function} is created.
  3373. If @t{(fdefinition @i{function-name})} is a @i{generic function}, that
  3374. @i{generic function}
  3375. is modified. If @i{function-name} names
  3376. an @i{ordinary function},
  3377. a @i{macro}, or a @i{special operator},
  3378. an error is signaled.
  3379. The effect of the @b{defgeneric} macro is as if the following three
  3380. steps were performed: first,
  3381. @i{methods} defined by previous @b{defgeneric} @i{forms} are removed;
  3382. [Reviewer Note by Barmar: Shouldn't this (second) be first?]
  3383. second, @b{ensure-generic-function}
  3384. is called; and finally, @i{methods} specified by the current
  3385. @b{defgeneric} @i{form} are added to the @i{generic function}.
  3386. Each @i{method-description} defines a @i{method} on the @i{generic function}.
  3387. The @i{lambda list} of each @i{method} must be congruent with the
  3388. @i{lambda list}
  3389. specified by the @i{gf-lambda-list} option.
  3390. If no @i{method} descriptions are specified and a @i{generic function} of the same
  3391. name does not already exist, a @i{generic function} with no
  3392. @i{methods} is created.
  3393. The @i{gf-lambda-list} argument of @b{defgeneric} specifies the shape of
  3394. @i{lambda lists} for the @i{methods} on this @i{generic function}.
  3395. All @i{methods} on the resulting
  3396. @i{generic function} must have
  3397. @i{lambda lists} that are congruent with this shape. If a @b{defgeneric}
  3398. form is evaluated and some
  3399. @i{methods} for that @i{generic function}
  3400. have @i{lambda lists} that are not congruent with that given in
  3401. the @b{defgeneric} form, an error is signaled. For further details
  3402. on method congruence, see @ref{Congruent Lambda-lists for all Methods of a Generic Function}.
  3403. The @i{generic function} passes to the
  3404. @i{method} all the argument values passed to
  3405. it, and only those; default values are not supported.
  3406. Note that optional and keyword arguments in method definitions, however,
  3407. can have default initial value forms and can use supplied-p parameters.
  3408. The following options are provided.
  3409. Except as otherwise noted,
  3410. a given option may occur only once.
  3411. @table @asis
  3412. @item @t{*}
  3413. The @t{:argument-precedence-order} option is used to specify the
  3414. order in which the required arguments in a call to the @i{generic function}
  3415. are tested for specificity when selecting a particular
  3416. @i{method}. Each required argument, as specified in the @i{gf-lambda-list}
  3417. argument, must be included exactly once as a @i{parameter-name}
  3418. so that the full and unambiguous precedence order is
  3419. supplied. If this condition is not met, an error is signaled.
  3420. [Reviewer Note by Barmar: What is the default order?]
  3421. @item @t{*}
  3422. The @b{declare} option is used to specify declarations that pertain
  3423. to the @i{generic function}.
  3424. An @b{optimize} @i{declaration specifier} is allowed.
  3425. It specifies whether method selection should be optimized for
  3426. speed or space, but it has no effect on @i{methods}.
  3427. To control how a @i{method} is optimized, an @b{optimize}
  3428. declaration must be placed directly in the @b{defmethod} @i{form}
  3429. or method description. The optimization qualities @b{speed} and
  3430. @b{space} are the only qualities this standard requires, but an
  3431. implementation can extend the object system to recognize other qualities.
  3432. A simple implementation that has only one method selection technique
  3433. and ignores @b{optimize} @i{declaration specifiers} is valid.
  3434. The @b{special}, @b{ftype}, @b{function}, @b{inline},
  3435. @b{notinline}, and @b{declaration} declarations are not permitted.
  3436. Individual implementations can extend the @b{declare} option to
  3437. support additional declarations.
  3438. [Editorial Note by KMP: Does ``additional'' mean including special, ftype, etc.?
  3439. Or only other things that are not mentioned here?]
  3440. If an implementation notices a @i{declaration specifier} that it does
  3441. not support and that has not been proclaimed as a non-standard
  3442. @i{declaration identifier} name in a @b{declaration} @i{proclamation},
  3443. it should issue a warning.
  3444. [Editorial Note by KMP: The wording of this previous sentence,
  3445. particularly the word ``and'' suggests to me that you can `proclaim declaration'
  3446. of an unsupported declaration (e.g., ftype) in order to suppress the warning.
  3447. That seems wrong. Perhaps it instead means to say ``does not support or
  3448. is both undefined and not proclaimed declaration.'']
  3449. The @b{declare} option may be specified more than once.
  3450. The effect is the same as if the lists of @i{declaration specifiers}
  3451. had been appended together into a single list and specified as a
  3452. single @b{declare} option.
  3453. @item @t{*}
  3454. The @t{:documentation} argument is a @i{documentation string}
  3455. to be attached to the @i{generic function} @i{object},
  3456. and to be attached with kind @b{function} to the @i{function-name}.
  3457. @item @t{*}
  3458. The @t{:generic-function-class} option may be used to specify that
  3459. the @i{generic function} is to have a different @i{class} than
  3460. the default provided by the system (the @i{class} @b{standard-generic-function}).
  3461. The @i{class-name} argument is the name of a @i{class} that can be the
  3462. @i{class} of a @i{generic function}. If @i{function-name} specifies
  3463. an existing @i{generic function} that has a different value for the
  3464. @t{:generic-function-class} argument and the new generic function
  3465. @i{class} is compatible with the old, @b{change-class} is called
  3466. to change the @i{class} of the @i{generic function};
  3467. otherwise an error is signaled.
  3468. @item @t{*}
  3469. The @t{:method-class} option is used to specify that all @i{methods} on
  3470. this @i{generic function} are to have a different @i{class} from the
  3471. default provided by the system (the @i{class} @b{standard-method}).
  3472. The @i{class-name} argument is the name of a @i{class} that is capable
  3473. of being the @i{class} of a @i{method}.
  3474. [Reviewer Note by Barmar: Is @b{change-class} called on existing methods?]
  3475. @item @t{*}
  3476. The @t{:method-combination} option is followed by a symbol that
  3477. names a type of method combination. The arguments (if any) that
  3478. follow that symbol depend on the type of method combination. Note
  3479. that the standard method combination type does not support any
  3480. arguments. However, all types of method combination defined by the
  3481. short form of @b{define-method-combination} accept an optional
  3482. argument named @i{order}, defaulting to @t{:most-specific-first},
  3483. where a value of @t{:most-specific-last} reverses
  3484. the order of the primary @i{methods} without affecting the order of the
  3485. auxiliary @i{methods}.
  3486. @end table
  3487. The @i{method-description} arguments define @i{methods} that will
  3488. be associated with the @i{generic function}. The @i{method-qualifier}
  3489. and @i{specialized-lambda-list} arguments in a method description
  3490. are the same as for @b{defmethod}.
  3491. The @i{form} arguments specify the method body. The body of the
  3492. @i{method} is enclosed in an @i{implicit block}.
  3493. If @i{function-name} is a @i{symbol}, this block bears the same name as
  3494. the @i{generic function}. If @i{function-name} is a
  3495. @i{list} of the
  3496. form @t{(setf @i{symbol})}, the name of the block is @i{symbol}.
  3497. Implementations can extend @b{defgeneric} to include other options.
  3498. It is required that an implementation signal an error if
  3499. it observes an option that is not implemented locally.
  3500. @b{defgeneric} is not required to perform any compile-time side effects.
  3501. In particular, the @i{methods} are not installed for invocation during
  3502. compilation. An @i{implementation} may choose to store information about
  3503. the @i{generic function} for the purposes of compile-time error-checking
  3504. (such as checking the number of arguments on calls, or noting that a definition
  3505. for the function name has been seen).
  3506. @subsubheading Examples::
  3507. @subsubheading Exceptional Situations::
  3508. If @i{function-name} names an @i{ordinary function}, a @i{macro},
  3509. or a @i{special operator}, an error of @i{type} @b{program-error} is signaled.
  3510. Each required argument, as specified in the @i{gf-lambda-list}
  3511. argument, must be included exactly once as a @i{parameter-name},
  3512. or an error of @i{type} @b{program-error} is signaled.
  3513. The @i{lambda list} of each @i{method} specified by a
  3514. @i{method-description} must be congruent with the @i{lambda list} specified
  3515. by the @i{gf-lambda-list} option, or
  3516. an error of @i{type} @b{error} is signaled.
  3517. If a @b{defgeneric} form is evaluated and some @i{methods} for
  3518. that @i{generic function} have @i{lambda lists} that are not congruent with
  3519. that given in the @b{defgeneric} form,
  3520. an error of @i{type} @b{error} is signaled.
  3521. A given @i{option} may occur only once,
  3522. or an error of @i{type} @b{program-error} is signaled.
  3523. [Reviewer Note by Barmar: This says that an error is signaled if you specify the same generic
  3524. function class as it already has!]
  3525. If @i{function-name} specifies an existing @i{generic function}
  3526. that has a different value for the @t{:generic-function-class}
  3527. argument and the new generic function @i{class} is compatible with the
  3528. old, @b{change-class} is called to change the @i{class} of
  3529. the @i{generic function}; otherwise an error of @i{type} @b{error} is signaled.
  3530. Implementations can extend @b{defgeneric} to include other options.
  3531. It is required that an implementation
  3532. signal an error of @i{type} @b{program-error} if
  3533. it observes an option that is not implemented locally.
  3534. @subsubheading See Also::
  3535. @ref{defmethod}
  3536. ,
  3537. @ref{documentation; (setf documentation)}
  3538. ,
  3539. @ref{ensure-generic-function}
  3540. ,
  3541. @b{generic-function},
  3542. @ref{Congruent Lambda-lists for all Methods of a Generic Function}
  3543. @node defmethod, find-class, defgeneric, Objects Dictionary
  3544. @subsection defmethod [Macro]
  3545. @code{defmethod} @i{@i{function-name}
  3546. @{{@i{method-qualifier}}@}{*}
  3547. @i{specialized-lambda-list}
  3548. {[[@{@i{declaration}@}{*} | @i{documentation}]]} @{@i{form}@}{*}}@*
  3549. @result{} @i{new-method}
  3550. @i{function-name}::= @{@i{symbol}
  3551. | @t{(setf @i{symbol})}@}
  3552. @i{method-qualifier}::= @i{non-list}
  3553. @w{ @i{specialized-lambda-list}::= (@{@i{var} | @r{(}{@i{var} @i{parameter-specializer-name}}@r{)}@}{*}}@*
  3554. @w{ @t{[}{&optional} @{@i{var} | @r{(}var @t{[}@i{initform} {@r{[}@i{supplied-p-parameter}@r{]}} @t{]}@r{)}@}{*}@t{]}}@*
  3555. @w{ @t{[}@t{&rest} @i{var}@t{]}}@*
  3556. @w{ @t{{[}}{{&key}{}}@{@i{var} | @r{(}@{@i{var} | @r{(}@i{keyword}@i{var}@r{)}@} @t{[}@i{initform} @r{[}@i{supplied-p-parameter}@r{]} @t{]}@r{)}@}{*}}@*
  3557. @w{ @r{[}@b{&allow-other-keys}@r{]} @t{{]}}}@*
  3558. @w{ @t{[}@t{&aux} @{@i{var} | @r{(}@i{var} @r{[}@i{initform}@r{]} @r{)}@}{*}@t{]} @r{)}}@*
  3559. @w{ @i{parameter-specializer-name}::= @i{symbol} | @r{(}@t{eql} @i{eql-specializer-form}@r{)}}@*
  3560. @subsubheading Arguments and Values::
  3561. @i{declaration}---a @b{declare} @i{expression}; not evaluated.
  3562. @i{documentation}---a @i{string}; not evaluated.
  3563. @i{var}---a @i{variable} @i{name}.
  3564. @i{eql-specializer-form}---a @i{form}.
  3565. @i{Form}---a @i{form}.
  3566. @i{Initform}---a @i{form}.
  3567. @i{Supplied-p-parameter}---variable name.
  3568. @i{new-method}---the new @i{method} @i{object}.
  3569. @subsubheading Description::
  3570. The macro @b{defmethod} defines a @i{method} on a
  3571. @i{generic function}.
  3572. If @t{(fboundp @i{function-name})} is @b{nil}, a
  3573. @i{generic function} is created with default values for
  3574. the argument precedence order
  3575. (each argument is more specific than the arguments to its right
  3576. in the argument list),
  3577. for the generic function class (the @i{class} @b{standard-generic-function}),
  3578. for the method class (the @i{class} @b{standard-method}),
  3579. and for the method combination type (the standard method combination type).
  3580. The @i{lambda list} of the @i{generic function} is
  3581. congruent with the @i{lambda list} of the
  3582. @i{method} being defined; if the
  3583. @b{defmethod} form mentions keyword arguments, the @i{lambda list} of
  3584. the @i{generic function}
  3585. will mention @t{&key} (but no keyword
  3586. arguments). If @i{function-name} names
  3587. an @i{ordinary function},
  3588. a @i{macro}, or a @i{special operator},
  3589. an error is signaled.
  3590. If a @i{generic function} is currently named by @i{function-name},
  3591. the @i{lambda list} of the
  3592. @i{method} must be congruent with the @i{lambda list} of the
  3593. @i{generic function}.
  3594. If this condition does not hold, an error is signaled.
  3595. For a definition of congruence in this context, see @ref{Congruent Lambda-lists for all Methods of a Generic Function}.
  3596. Each @i{method-qualifier} argument is an @i{object} that is used by
  3597. method combination to identify the given @i{method}.
  3598. The method combination type might further
  3599. restrict what a method @i{qualifier} can be.
  3600. The standard method combination type allows for @i{unqualified methods} and
  3601. @i{methods} whose sole
  3602. @i{qualifier} is one of the keywords @t{:before}, @t{:after}, or @t{:around}.
  3603. The @i{specialized-lambda-list} argument is like an ordinary
  3604. @i{lambda list} except that the @i{names} of required parameters can
  3605. be replaced by specialized parameters. A specialized parameter is a
  3606. list of the form
  3607. @t{(@i{var} @i{parameter-specializer-name})}.
  3608. Only required parameters can be
  3609. specialized. If @i{parameter-specializer-name} is a @i{symbol} it names a
  3610. @i{class}; if it is a @i{list},
  3611. it is of the form @t{(eql @i{eql-specializer-form})}. The parameter
  3612. specializer name @t{(eql @i{eql-specializer-form})} indicates
  3613. that the corresponding argument must be @b{eql} to the @i{object} that
  3614. is the value of @i{eql-specializer-form} for the @i{method} to be applicable.
  3615. The @i{eql-specializer-form} is evaluated at the time
  3616. that the expansion of the @b{defmethod} macro is evaluated.
  3617. If no @i{parameter specializer name} is specified for a given
  3618. required parameter, the @i{parameter specializer} defaults to
  3619. the @i{class} @b{t}.
  3620. For further discussion, see @ref{Introduction to Methods}.
  3621. The @i{form} arguments specify the method body.
  3622. The body of the @i{method} is enclosed in an @i{implicit block}. If
  3623. @i{function-name} is a @i{symbol},
  3624. this block bears the same @i{name} as the @i{generic function}.
  3625. If @i{function-name} is a @i{list} of the form
  3626. @t{(setf @i{symbol})}, the @i{name} of the block is @i{symbol}.
  3627. The @i{class} of the @i{method} @i{object} that is created is that given by the
  3628. method class option of the @i{generic function}
  3629. on which the @i{method} is defined.
  3630. If the @i{generic function} already has a @i{method} that agrees with the
  3631. @i{method} being defined on @i{parameter specializers} and @i{qualifiers},
  3632. @b{defmethod} replaces the existing @i{method} with the one now being
  3633. defined.
  3634. For a definition of agreement in this context.
  3635. see @ref{Agreement on Parameter Specializers and Qualifiers}.
  3636. The @i{parameter specializers} are derived from
  3637. the @i{parameter specializer names} as described in
  3638. @ref{Introduction to Methods}.
  3639. The expansion of the @b{defmethod} macro ``refers to'' each
  3640. specialized parameter (see the description of @b{ignore}
  3641. within the description of @b{declare}).
  3642. This includes parameters that
  3643. have an explicit @i{parameter specializer name} of @b{t}. This means
  3644. that a compiler warning does not occur if the body of the @i{method} does
  3645. not refer to a specialized parameter, while a warning might occur
  3646. if the body of the @i{method} does not refer to an unspecialized parameter.
  3647. For this reason, a parameter that specializes on @b{t} is not quite synonymous
  3648. with an unspecialized parameter in this context.
  3649. Declarations at the head of the method body that apply to the
  3650. method's @i{lambda variables} are treated as @i{bound declarations}
  3651. whose @i{scope} is the same as the corresponding @i{bindings}.
  3652. Declarations at the head of the method body that apply to the
  3653. functional bindings of @b{call-next-method} or @b{next-method-p}
  3654. apply to references to those functions within the method body @i{forms}.
  3655. Any outer @i{bindings} of the @i{function names} @b{call-next-method} and
  3656. @b{next-method-p}, and declarations associated with such @i{bindings}
  3657. are @i{shadowed}_2 within the method body @i{forms}.
  3658. The @i{scope} of @i{free declarations} at the head of the method body
  3659. is the entire method body,
  3660. which includes any implicit local function definitions
  3661. but excludes @i{initialization forms} for the @i{lambda variables}.
  3662. @b{defmethod} is not required to perform any compile-time side effects.
  3663. In particular, the @i{methods} are not installed for invocation during
  3664. compilation. An @i{implementation} may choose to store information about
  3665. the @i{generic function} for the purposes of compile-time error-checking
  3666. (such as checking the number of arguments on calls, or noting that a definition
  3667. for the function name has been seen).
  3668. @i{Documentation} is attached as a @i{documentation string}
  3669. to the @i{method} @i{object}.
  3670. @subsubheading Affected By::
  3671. The definition of the referenced @i{generic function}.
  3672. @subsubheading Exceptional Situations::
  3673. If @i{function-name} names an @i{ordinary function},
  3674. a @i{macro}, or a @i{special operator},
  3675. an error of @i{type} @b{error} is signaled.
  3676. If a @i{generic function} is currently named by @i{function-name},
  3677. the @i{lambda list} of the
  3678. @i{method} must be congruent with the @i{lambda list} of the
  3679. @i{generic function}, or
  3680. an error of @i{type} @b{error} is signaled.
  3681. @subsubheading See Also::
  3682. @ref{defgeneric}
  3683. ,
  3684. @ref{documentation; (setf documentation)}
  3685. ,
  3686. @ref{Introduction to Methods},
  3687. @ref{Congruent Lambda-lists for all Methods of a Generic Function},
  3688. @ref{Agreement on Parameter Specializers and Qualifiers},
  3689. @ref{Syntactic Interaction of Documentation Strings and Declarations}
  3690. @node find-class, next-method-p, defmethod, Objects Dictionary
  3691. @subsection find-class [Accessor]
  3692. @code{find-class} @i{symbol {&optional} errorp environment} @result{} @i{class}
  3693. (setf (@code{ find-class} @i{symbol {&optional} errorp environment}) new-class)@*
  3694. @subsubheading Arguments and Values::
  3695. @i{symbol}---a @i{symbol}.
  3696. @i{errorp}---a @i{generalized boolean}.
  3697. The default is @i{true}.
  3698. @i{environment} -- same as the @b{&environment} argument to
  3699. macro expansion functions and is used to distinguish between
  3700. compile-time and run-time environments.
  3701. The @b{&environment} argument has
  3702. @i{dynamic extent}; the consequences are undefined if
  3703. the @b{&environment} argument is
  3704. referred to outside the @i{dynamic extent}
  3705. of the macro expansion function.
  3706. @i{class}---a @i{class} @i{object}, or @b{nil}.
  3707. @subsubheading Description::
  3708. Returns the @i{class} @i{object} named by the @i{symbol}
  3709. in the @i{environment}. If there is no such @i{class},
  3710. @b{nil} is returned if @i{errorp} is @i{false}; otherwise,
  3711. if @i{errorp} is @i{true}, an error is signaled.
  3712. The @i{class} associated with a particular @i{symbol} can be changed by using
  3713. @b{setf} with @b{find-class};
  3714. or, if the new @i{class} given to @b{setf} is @b{nil},
  3715. the @i{class} association is removed
  3716. (but the @i{class} @i{object} itself is not affected).
  3717. The results are undefined if the user attempts to change
  3718. or remove
  3719. the @i{class} associated with a
  3720. @i{symbol} that is defined as a @i{type specifier} in this standard.
  3721. See @ref{Integrating Types and Classes}.
  3722. When using @b{setf} of @b{find-class}, any @i{errorp} argument is @i{evaluated}
  3723. for effect, but any @i{values} it returns are ignored; the @i{errorp}
  3724. @i{parameter} is permitted primarily so that the @i{environment} @i{parameter}
  3725. can be used.
  3726. The @i{environment} might be used to distinguish between a compile-time and a
  3727. run-time environment.
  3728. @subsubheading Exceptional Situations::
  3729. If there is no such @i{class} and @i{errorp} is @i{true},
  3730. @b{find-class} signals an error of @i{type} @b{error}.
  3731. @subsubheading See Also::
  3732. @ref{defmacro}
  3733. ,
  3734. @ref{Integrating Types and Classes}
  3735. @node next-method-p, call-method, find-class, Objects Dictionary
  3736. @subsection next-method-p [Local Function]
  3737. @subsubheading Syntax::
  3738. @code{next-method-p} @i{<@i{no @i{arguments}}>} @result{} @i{generalized-boolean}
  3739. @subsubheading Arguments and Values::
  3740. @i{generalized-boolean}---a @i{generalized boolean}.
  3741. @subsubheading Description::
  3742. The locally defined function @b{next-method-p} can be used
  3743. within the body @i{forms} (but not the @i{lambda list})
  3744. defined by a @i{method-defining form} to determine
  3745. whether a next @i{method} exists.
  3746. The @i{function} @b{next-method-p} has @i{lexical scope} and @i{indefinite extent}.
  3747. Whether or not @b{next-method-p} is @i{fbound} in the
  3748. @i{global environment} is @i{implementation-dependent};
  3749. however, the restrictions on redefinition and @i{shadowing} of
  3750. @b{next-method-p} are the same as for @i{symbols} in the @t{COMMON-LISP} @i{package}
  3751. which are @i{fbound} in the @i{global environment}.
  3752. The consequences of attempting to use @b{next-method-p} outside
  3753. of a @i{method-defining form} are undefined.
  3754. @subsubheading See Also::
  3755. @ref{call-next-method}
  3756. ,
  3757. @ref{defmethod}
  3758. ,
  3759. @ref{call-method; make-method}
  3760. @node call-method, call-next-method, next-method-p, Objects Dictionary
  3761. @subsection call-method, make-method [Local Macro]
  3762. @subsubheading Syntax::
  3763. @code{call-method} @i{method {&optional} next-method-list} @result{} @i{@{@i{result}@}{*}}
  3764. @code{make-method} @i{form} @result{} @i{method-object}
  3765. @subsubheading Arguments and Values::
  3766. @i{method}---a @i{method} @i{object},
  3767. or a @i{list} (see below); not evaluated.
  3768. @i{method-object}---a @i{method} @i{object}.
  3769. @i{next-method-list}---a @i{list} of @i{method} @i{objects}; not evaluated.
  3770. @i{results}---the @i{values} returned by the @i{method} invocation.
  3771. @subsubheading Description::
  3772. The macro @b{call-method} is used in method combination. It hides
  3773. the @i{implementation-dependent} details of how
  3774. @i{methods} are called. The
  3775. macro @b{call-method} has @i{lexical scope} and
  3776. can only be used within
  3777. an @i{effective method} @i{form}.
  3778. [Editorial Note by KMP: This next paragraph still needs some work.]
  3779. Whether or not @b{call-method} is @i{fbound} in the
  3780. @i{global environment} is @i{implementation-dependent};
  3781. however, the restrictions on redefinition and @i{shadowing} of
  3782. @b{call-method} are the same as for @i{symbols} in the @t{COMMON-LISP} @i{package}
  3783. which are @i{fbound} in the @i{global environment}.
  3784. The consequences of attempting to use @b{call-method} outside
  3785. of an @i{effective method} @i{form} are undefined.
  3786. The macro @b{call-method} invokes the specified @i{method},
  3787. supplying it with arguments and with definitions for
  3788. @b{call-next-method} and for @b{next-method-p}.
  3789. If the invocation of @b{call-method} is lexically inside
  3790. of a @b{make-method}, the arguments are those that
  3791. were supplied to that method. Otherwise the arguments are
  3792. those that were supplied to the generic function.
  3793. The definitions
  3794. of @b{call-next-method} and @b{next-method-p} rely on
  3795. the specified @i{next-method-list}.
  3796. If @i{method} is a @i{list}, the first element of the @i{list}
  3797. must be the symbol @b{make-method} and the second element must be
  3798. a @i{form}. Such a @i{list} specifies a @i{method} @i{object}
  3799. whose @i{method} function has a body that is the given @i{form}.
  3800. @i{Next-method-list} can contain @i{method} @i{objects} or @i{lists},
  3801. the first element of which must be the symbol @b{make-method} and the
  3802. second element of which must be a @i{form}.
  3803. Those are the only two places where @b{make-method} can be used.
  3804. The @i{form} used with @b{make-method} is evaluated in
  3805. the @i{null lexical environment} augmented with a local macro definition
  3806. for @b{call-method} and with bindings named by
  3807. symbols not @i{accessible} from the @t{COMMON-LISP-USER} @i{package}.
  3808. The @b{call-next-method} function available to @i{method}
  3809. will call the first @i{method} in @i{next-method-list}.
  3810. The @b{call-next-method} function
  3811. available in that @i{method}, in turn, will call the second
  3812. @i{method} in @i{next-method-list}, and so on, until
  3813. the list of next @i{methods} is exhausted.
  3814. If @i{next-method-list} is not supplied, the
  3815. @b{call-next-method} function available to
  3816. @i{method} signals an error of @i{type} @b{control-error}
  3817. and the @b{next-method-p} function
  3818. available to @i{method} returns {@b{nil}}.
  3819. @subsubheading Examples::
  3820. @subsubheading See Also::
  3821. @ref{call-next-method}
  3822. ,
  3823. @ref{define-method-combination}
  3824. ,
  3825. @ref{next-method-p}
  3826. @node call-next-method, compute-applicable-methods, call-method, Objects Dictionary
  3827. @subsection call-next-method [Local Function]
  3828. @subsubheading Syntax::
  3829. @code{call-next-method} @i{{&rest} args} @result{} @i{@{@i{result}@}{*}}
  3830. @subsubheading Arguments and Values::
  3831. @i{arg}---an @i{object}.
  3832. @i{results}---the @i{values} returned by the @i{method} it calls.
  3833. @subsubheading Description::
  3834. The @i{function} @b{call-next-method} can be used
  3835. within the body @i{forms} (but not the @i{lambda list})
  3836. of a @i{method} defined by a @i{method-defining form} to call the
  3837. @i{next method}.
  3838. If there is no next @i{method}, the generic function
  3839. @b{no-next-method} is called.
  3840. The type of method combination used determines which @i{methods}
  3841. can invoke @b{call-next-method}. The standard
  3842. @i{method combination} type allows @b{call-next-method}
  3843. to be used within primary @i{methods} and @i{around methods}.
  3844. For generic functions using a type of method combination defined by
  3845. the short form of @b{define-method-combination},
  3846. @b{call-next-method} can be used in @i{around methods} only.
  3847. When @b{call-next-method} is called with no arguments, it passes the
  3848. current @i{method}'s original arguments to the next @i{method}. Neither
  3849. argument defaulting, nor using @b{setq}, nor rebinding variables
  3850. with the same @i{names} as parameters of the @i{method} affects the values
  3851. @b{call-next-method} passes to the @i{method} it calls.
  3852. When @b{call-next-method} is called with arguments, the
  3853. @i{next method} is called with those arguments.
  3854. If @b{call-next-method} is called with arguments but omits
  3855. optional arguments, the @i{next method} called defaults those arguments.
  3856. The @i{function} @b{call-next-method} returns any @i{values} that are
  3857. returned by the @i{next method}.
  3858. The @i{function} @b{call-next-method} has @i{lexical scope} and
  3859. @i{indefinite extent} and can only be used within the body of a
  3860. @i{method} defined by a @i{method-defining form}.
  3861. Whether or not @b{call-next-method} is @i{fbound} in the
  3862. @i{global environment} is @i{implementation-dependent};
  3863. however, the restrictions on redefinition and @i{shadowing} of
  3864. @b{call-next-method} are the same as for @i{symbols} in the @t{COMMON-LISP} @i{package}
  3865. which are @i{fbound} in the @i{global environment}.
  3866. The consequences of attempting to use @b{call-next-method} outside
  3867. of a @i{method-defining form} are undefined.
  3868. @subsubheading Affected By::
  3869. @b{defmethod}, @b{call-method}, @b{define-method-combination}.
  3870. @subsubheading Exceptional Situations::
  3871. When providing arguments to @b{call-next-method},
  3872. the following rule must be satisfied or an error of @i{type} @b{error}
  3873. should be
  3874. signaled:
  3875. the ordered set of @i{applicable methods} for a changed set of arguments
  3876. for @b{call-next-method} must be the same as the ordered set of
  3877. @i{applicable methods} for the original arguments to the
  3878. @i{generic function}.
  3879. Optimizations of the error checking are possible, but they must not change
  3880. the semantics of @b{call-next-method}.
  3881. @subsubheading See Also::
  3882. @ref{define-method-combination}
  3883. ,
  3884. @ref{defmethod}
  3885. ,
  3886. @ref{next-method-p}
  3887. ,
  3888. @ref{no-next-method}
  3889. ,
  3890. @ref{call-method; make-method}
  3891. ,
  3892. @ref{Method Selection and Combination},
  3893. @ref{Standard Method Combination},
  3894. @ref{Built-in Method Combination Types}
  3895. @node compute-applicable-methods, define-method-combination, call-next-method, Objects Dictionary
  3896. @subsection compute-applicable-methods [Standard Generic Function]
  3897. @subsubheading Syntax::
  3898. @code{compute-applicable-methods} @i{generic-function function-arguments} @result{} @i{methods}
  3899. @subsubheading Method Signatures::
  3900. @code{compute-applicable-methods} @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}}
  3901. @subsubheading Arguments and Values::
  3902. @i{generic-function}---a @i{generic function}.
  3903. @i{function-arguments}---a @i{list} of arguments for the @i{generic-function}.
  3904. @i{methods}---a @i{list} of @i{method} @i{objects}.
  3905. @subsubheading Description::
  3906. Given a @i{generic-function} and a set of
  3907. @i{function-arguments}, the function
  3908. @b{compute-applicable-methods} returns the set of @i{methods}
  3909. that are applicable for those arguments
  3910. sorted according to precedence order.
  3911. See @ref{Method Selection and Combination}.
  3912. @subsubheading Affected By::
  3913. @b{defmethod}
  3914. @subsubheading See Also::
  3915. @ref{Method Selection and Combination}
  3916. @node define-method-combination, find-method, compute-applicable-methods, Objects Dictionary
  3917. @subsection define-method-combination [Macro]
  3918. @code{define-method-combination} @i{name [[!@i{short-form-option}]]}@*
  3919. @result{} @i{name}
  3920. @code{define-method-combination} @i{name lambda-list
  3921. @r{(}@{@i{method-group-specifier}@}{*}@r{)}
  3922. @r{[}@r{(}@t{:arguments} . args-lambda-list@r{)}@r{]}
  3923. @r{[}@r{(}@t{:generic-function}
  3924. generic-function-symbol@r{)}@r{]}
  3925. [[@{@i{declaration}@}{*} | @i{documentation}]]
  3926. @{@i{form}@}{*}}@*
  3927. @result{} @i{name}
  3928. @w{@i{short-form-option} ::=@t{:documentation} @i{documentation} | }
  3929. @w{ @t{:identity-with-one-argument} @i{identity-with-one-argument} |}
  3930. @w{ @t{:operator} @i{operator}}
  3931. @w{@i{method-group-specifier} ::=@r{(}name @{@{@i{qualifier-pattern}@}^+ | predicate@} [[!@i{long-form-option}]]@r{)}}
  3932. @w{@i{long-form-option} ::=@t{:description} @i{description} |}
  3933. @w{ @t{:order} @i{order} |}
  3934. @w{ @t{:required} @i{required-p}}
  3935. @subsubheading Arguments and Values::
  3936. @i{args-lambda-list}---
  3937. a @i{define-method-combination arguments lambda list}.
  3938. @i{declaration}---a @b{declare} @i{expression}; not evaluated.
  3939. @i{description}---a @i{format control}.
  3940. @i{documentation}---a @i{string}; not evaluated.
  3941. @i{forms}---an @i{implicit progn}
  3942. that must compute and return the @i{form} that specifies how
  3943. the @i{methods} are combined, that is, the @i{effective method}.
  3944. @i{generic-function-symbol}---a @i{symbol}.
  3945. @i{identity-with-one-argument}---a @i{generalized boolean}.
  3946. @i{lambda-list}---@i{ordinary lambda list}.
  3947. @i{name}---a @i{symbol}.
  3948. Non-@i{keyword}, @i{non-nil} @i{symbols} are usually used.
  3949. @i{operator}---an @i{operator}.
  3950. @i{Name} and @i{operator} are often the @i{same} @i{symbol}.
  3951. This is the default, but it is not required.
  3952. @i{order}---@t{:most-specific-first} or @t{:most-specific-last}; evaluated.
  3953. @i{predicate}---a @i{symbol} that names a @i{function} of one argument
  3954. that returns a @i{generalized boolean}.
  3955. @i{qualifier-pattern}---a @i{list},
  3956. or the @i{symbol} @b{*}.
  3957. @i{required-p}---a @i{generalized boolean}.
  3958. @subsubheading Description::
  3959. The macro @b{define-method-combination} is used to define new types
  3960. of method combination.
  3961. There are two forms of @b{define-method-combination}. The short
  3962. form is a simple facility for the cases that are expected
  3963. to be most commonly needed. The long form is more powerful but more
  3964. verbose. It resembles @b{defmacro} in that the body is an
  3965. expression, usually using backquote, that computes a @i{form}. Thus
  3966. arbitrary control structures can be implemented. The long form also
  3967. allows arbitrary processing of method @i{qualifiers}.
  3968. @table @asis
  3969. @item @b{Short Form}
  3970. The short form syntax of @b{define-method-combination} is recognized
  3971. when the second @i{subform} is a @i{non-nil} symbol or is not present.
  3972. When the short form is used, @i{name} is defined as a type of
  3973. method combination that produces a Lisp form
  3974. @t{({@i{operator} @i{method-call} @i{method-call} ...})}.
  3975. The @i{operator} is a @i{symbol} that can be the @i{name} of a
  3976. @i{function}, @i{macro}, or @i{special operator}.
  3977. The @i{operator} can be supplied by a keyword option;
  3978. it defaults to @i{name}.
  3979. Keyword options for the short form are the following:
  3980. @table @asis
  3981. @item @t{*}
  3982. The @t{:documentation} option is used to document the method-combination type;
  3983. see description of long form below.
  3984. @item @t{*}
  3985. The @t{:identity-with-one-argument} option enables an optimization
  3986. when its value is @i{true} (the default is @i{false}). If there is
  3987. exactly one applicable method and it is a primary method, that method
  3988. serves as the effective method and @i{operator} is not called.
  3989. This optimization avoids the need to create a new effective method and
  3990. avoids the overhead of a @i{function} call. This option is designed to be
  3991. used with operators such as @b{progn}, @b{and}, @b{+}, and
  3992. @b{max}.
  3993. @item @t{*}
  3994. The @t{:operator} option specifies the @i{name} of the operator. The
  3995. @i{operator} argument is a @i{symbol} that can be the
  3996. @i{name} of a @i{function},
  3997. @i{macro}, or
  3998. @i{special form}.
  3999. @end table
  4000. These types of method combination require exactly one @i{qualifier} per
  4001. method. An error is signaled if there are applicable methods with no
  4002. @i{qualifiers} or with @i{qualifiers} that are not supported by
  4003. the method combination type.
  4004. A method combination procedure defined in this way recognizes two
  4005. roles for methods. A method whose one @i{qualifier} is the symbol naming
  4006. this type of method combination is defined to be a primary method. At
  4007. least one primary method must be applicable or an error is signaled.
  4008. A method with @t{:around} as its one @i{qualifier} is an auxiliary
  4009. method that behaves the same as an @i{around method} in standard
  4010. method combination. The @i{function} @b{call-next-method} can only be
  4011. used in @i{around methods}; it cannot be used in primary methods
  4012. defined by the short form of the @b{define-method-combination} macro.
  4013. A method combination procedure defined in this way accepts an optional
  4014. argument named @i{order}, which defaults to
  4015. @t{:most-specific-first}. A value of @t{:most-specific-last} reverses
  4016. the order of the primary methods without affecting the order of the
  4017. auxiliary methods.
  4018. The short form automatically includes error checking and support for
  4019. @i{around methods}.
  4020. For a discussion of built-in method combination types,
  4021. see @ref{Built-in Method Combination Types}.
  4022. @item @b{Long Form}
  4023. The long form syntax of @b{define-method-combination} is recognized
  4024. when the second @i{subform} is a list.
  4025. The @i{lambda-list}
  4026. receives any arguments provided after the @i{name} of the method
  4027. combination type in the @t{:method-combination} option to
  4028. @b{defgeneric}.
  4029. A list of method group specifiers follows. Each specifier selects a subset
  4030. of the applicable methods to play a particular role, either by matching
  4031. their @i{qualifiers} against some patterns or by testing their @i{qualifiers} with
  4032. a @i{predicate}.
  4033. These method group specifiers define all method @i{qualifiers}
  4034. that can be used with this type of method combination.
  4035. The @i{car} of each @i{method-group-specifier} is a @i{symbol}
  4036. which @i{names} a @i{variable}.
  4037. During the execution of
  4038. the @i{forms} in the body of @b{define-method-combination}, this
  4039. @i{variable} is bound to a list of the @i{methods} in the method group. The
  4040. @i{methods} in this list occur in the order specified by the
  4041. @t{:order} option.
  4042. If @i{qualifier-pattern} is a @i{symbol} it must be @b{*}.
  4043. A method matches
  4044. a @i{qualifier-pattern} if the method's
  4045. list of @i{qualifiers} is @b{equal}
  4046. to the @i{qualifier-pattern} (except that the symbol @b{*} in a
  4047. @i{qualifier-pattern} matches anything). Thus
  4048. a @i{qualifier-pattern} can be one of the
  4049. following:
  4050. the @i{empty list}, which matches @i{unqualified methods};
  4051. the symbol @b{*}, which matches all methods;
  4052. a true list, which matches methods with the same number of @i{qualifiers}
  4053. as the length of the list when each @i{qualifier} matches
  4054. the corresponding list element; or
  4055. a dotted list that ends in the symbol @b{*}
  4056. (the @b{*} matches any number of additional @i{qualifiers}).
  4057. Each applicable method is tested against the @i{qualifier-patterns} and
  4058. @i{predicates} in left-to-right order.
  4059. As soon as a @i{qualifier-pattern} matches
  4060. or a @i{predicate} returns true, the method becomes a member of the
  4061. corresponding method group and no further tests are made. Thus if a method
  4062. could be a member of more than one method group, it joins only the first
  4063. such group. If a method group has more than one
  4064. @i{qualifier-pattern}, a
  4065. method need only satisfy one of the @i{qualifier-patterns} to be a member of
  4066. the group.
  4067. The @i{name} of a @i{predicate} function can appear instead of
  4068. @i{qualifier-patterns} in a method group specifier.
  4069. The @i{predicate} is called for
  4070. each method that has not been assigned to an earlier method group; it
  4071. is called with one argument, the method's @i{qualifier} @i{list}.
  4072. The @i{predicate} should return true if the method is to be a member of the
  4073. method group. A @i{predicate} can be distinguished from a
  4074. @i{qualifier-pattern}
  4075. because it is a @i{symbol} other than @b{nil} or @b{*}.
  4076. If there is an applicable method that does not fall into any method group,
  4077. the @i{function} @b{invalid-method-error} is called.
  4078. Method group specifiers can have keyword options following the
  4079. @i{qualifier} patterns or predicate. Keyword options can be distinguished from
  4080. additional @i{qualifier} patterns because they are neither lists nor the symbol
  4081. @b{*}. The keyword options are as follows:
  4082. @table @asis
  4083. @item @t{*}
  4084. The @t{:description} option is used to provide a description of the
  4085. role of methods in the method group. Programming environment tools
  4086. use
  4087. @t{(apply #'format stream @i{format-control} (method-qualifiers @i{method}))}
  4088. to print this description, which
  4089. is expected to be concise. This keyword
  4090. option allows the description of a method @i{qualifier} to be defined in
  4091. the same module that defines the meaning of the
  4092. method @i{qualifier}. In most cases, @i{format-control} will not contain any
  4093. @b{format} directives, but they are available for generality.
  4094. If @t{:description} is not supplied, a default description is generated
  4095. based on the variable name and the @i{qualifier} patterns and on whether
  4096. this method group includes the @i{unqualified methods}.
  4097. @item @t{*}
  4098. The @t{:order} option specifies the order of methods. The @i{order}
  4099. argument is a @i{form} that evaluates to
  4100. @t{:most-specific-first} or @t{:most-specific-last}. If it evaluates
  4101. to any other value, an error is signaled.
  4102. If @t{:order} is not supplied, it defaults to
  4103. @t{:most-specific-first}.
  4104. @item @t{*}
  4105. The @t{:required} option specifies whether at least one method in
  4106. this method group is required.
  4107. If its value is @i{true} and the method group is empty
  4108. (that is, no applicable methods match the @i{qualifier} patterns
  4109. or satisfy the predicate),
  4110. an error is signaled.
  4111. If @t{:required} is not supplied,
  4112. it defaults to @b{nil}.
  4113. @end table
  4114. The use of method group specifiers provides a convenient syntax to
  4115. select methods, to divide them among the possible roles, and to perform the
  4116. necessary error checking. It is possible to perform further filtering
  4117. of methods in the body @i{forms} by using normal list-processing operations
  4118. and the functions @b{method-qualifiers} and
  4119. @b{invalid-method-error}. It is permissible to use @b{setq} on the
  4120. variables named in the method group specifiers and to bind additional
  4121. variables. It is also possible to bypass the method group specifier
  4122. mechanism and do everything in the body @i{forms}. This is accomplished
  4123. by writing a single method group with @b{*} as its only
  4124. @i{qualifier-pattern};
  4125. the variable is then bound to a @i{list} of all of the
  4126. @i{applicable methods}, in most-specific-first order.
  4127. The body @i{forms} compute and return the @i{form} that specifies
  4128. how the methods are combined, that is, the effective method.
  4129. The effective method is evaluated in
  4130. the @i{null lexical environment} augmented with a local macro definition
  4131. for @b{call-method} and with bindings named by
  4132. symbols not @i{accessible} from the @t{COMMON-LISP-USER} @i{package}.
  4133. Given a method object in one of the
  4134. @i{lists} produced by the method group
  4135. specifiers and a @i{list} of next methods,
  4136. @b{call-method}
  4137. will invoke the method such that @b{call-next-method} has available
  4138. the next methods.
  4139. When an effective method has no effect other than to call a single
  4140. method, some implementations employ an optimization that uses the
  4141. single method directly as the effective method, thus avoiding the need
  4142. to create a new effective method. This optimization is active when
  4143. the effective method form consists entirely of an invocation of
  4144. the @b{call-method} macro whose first @i{subform} is a method object and
  4145. whose second @i{subform} is @b{nil} or unsupplied. Each
  4146. @b{define-method-combination} body is responsible for stripping off
  4147. redundant invocations of @b{progn}, @b{and},
  4148. @b{multiple-value-prog1}, and the like, if this optimization is desired.
  4149. The list @t{(:arguments . @i{lambda-list})} can appear before
  4150. any declarations or @i{documentation string}. This form is useful when
  4151. the method combination type performs some specific behavior as part of
  4152. the combined method and that behavior needs access to the arguments to
  4153. the @i{generic function}. Each parameter variable defined by
  4154. @i{lambda-list} is bound to a @i{form} that can be inserted into the
  4155. effective method. When this @i{form} is evaluated during execution of the
  4156. effective method, its value is the corresponding argument to the
  4157. @i{generic function}; the consequences of using such a @i{form} as
  4158. the @i{place} in a @b{setf} @i{form} are undefined.
  4159. Argument correspondence is computed by dividing the @t{:arguments} @i{lambda-list}
  4160. and the @i{generic function} @i{lambda-list} into three sections:
  4161. the @i{required parameters},
  4162. the @i{optional parameters},
  4163. and the @i{keyword} and @i{rest parameters}.
  4164. The @i{arguments} supplied to the @i{generic function} for a particular @i{call}
  4165. are also divided into three sections;
  4166. the required @i{arguments} section contains as many @i{arguments}
  4167. as the @i{generic function} has @i{required parameters},
  4168. the optional @i{arguments} section contains as many arguments
  4169. as the @i{generic function} has @i{optional parameters},
  4170. and the keyword/rest @i{arguments} section contains the remaining arguments.
  4171. Each @i{parameter} in the required and optional sections of the
  4172. @t{:arguments} @i{lambda-list} accesses the argument at the same position
  4173. in the corresponding section of the @i{arguments}.
  4174. If the section of the @t{:arguments} @i{lambda-list} is shorter,
  4175. extra @i{arguments} are ignored.
  4176. If the section of the @t{:arguments} @i{lambda-list} is longer,
  4177. excess @i{required parameters} are bound to forms that evaluate to @b{nil}
  4178. and excess @i{optional parameters} are @i{bound} to their initforms.
  4179. The @i{keyword parameters} and @i{rest parameters} in the @t{:arguments}
  4180. @i{lambda-list} access the keyword/rest section of the @i{arguments}.
  4181. If the @t{:arguments} @i{lambda-list} contains @b{&key}, it behaves as
  4182. if it also contained @b{&allow-other-keys}.
  4183. In addition, @b{&whole} @i{var} can be placed first in the @t{:arguments}
  4184. @i{lambda-list}. It causes @i{var} to be @i{bound} to a @i{form}
  4185. that @i{evaluates} to a @i{list} of all of the @i{arguments} supplied
  4186. to the @i{generic function}. This is different from @b{&rest} because it
  4187. accesses all of the arguments, not just the keyword/rest @i{arguments}.
  4188. Erroneous conditions detected by the body should be reported with
  4189. @b{method-combination-error} or @b{invalid-method-error}; these
  4190. @i{functions}
  4191. add any necessary contextual information to the error message and will
  4192. signal the appropriate error.
  4193. The body @i{forms} are evaluated inside of the @i{bindings} created by
  4194. the
  4195. @i{lambda list} and method group specifiers.
  4196. [Reviewer Note by Barmar: Are they inside or outside the :ARGUMENTS bindings?]
  4197. Declarations at the head of
  4198. the body are positioned directly inside of @i{bindings} created by the
  4199. @i{lambda list} and outside of the @i{bindings} of the method group variables.
  4200. Thus method group variables cannot be declared in this way. @b{locally} may be used
  4201. around the body, however.
  4202. Within the body @i{forms}, @i{generic-function-symbol}
  4203. is bound to the @i{generic function} @i{object}.
  4204. @i{Documentation} is attached as a @i{documentation string}
  4205. to @i{name} (as kind @b{method-combination})
  4206. and to the @i{method combination} @i{object}.
  4207. Note that two methods with identical specializers, but with different
  4208. @i{qualifiers}, are not ordered by the algorithm described in Step 2 of
  4209. the method selection and combination process described in
  4210. @ref{Method Selection and Combination}. Normally the two methods play
  4211. different roles in the effective method because they have different
  4212. @i{qualifiers}, and no matter how they are ordered in the result of Step
  4213. 2, the effective method is the same. If the two methods play the same
  4214. role and their order matters,
  4215. [Reviewer Note by Barmar: How does the system know when the order matters?]
  4216. an error is signaled. This happens as
  4217. part of the @i{qualifier} pattern matching in
  4218. @b{define-method-combination}.
  4219. @end table
  4220. If a @b{define-method-combination} @i{form} appears as a
  4221. @i{top level form}, the @i{compiler} must make the
  4222. @i{method combination} @i{name} be recognized as a valid
  4223. @i{method combination} @i{name} in subsequent @b{defgeneric}
  4224. @i{forms}. However, the @i{method combination} is executed
  4225. no earlier than when the @b{define-method-combination} @i{form}
  4226. is executed, and possibly as late as the time that @i{generic functions}
  4227. that use the @i{method combination} are executed.
  4228. @subsubheading Examples::
  4229. Most examples of the long form of @b{define-method-combination} also
  4230. illustrate the use of the related @i{functions} that are provided as part
  4231. of the declarative method combination facility.
  4232. @example
  4233. ;;; Examples of the short form of define-method-combination
  4234. (define-method-combination and :identity-with-one-argument t)
  4235. (defmethod func and ((x class1) y) ...)
  4236. ;;; The equivalent of this example in the long form is:
  4237. (define-method-combination and
  4238. (&optional (order :most-specific-first))
  4239. ((around (:around))
  4240. (primary (and) :order order :required t))
  4241. (let ((form (if (rest primary)
  4242. `(and ,@@(mapcar #'(lambda (method)
  4243. `(call-method ,method))
  4244. primary))
  4245. `(call-method ,(first primary)))))
  4246. (if around
  4247. `(call-method ,(first around)
  4248. (,@@(rest around)
  4249. (make-method ,form)))
  4250. form)))
  4251. ;;; Examples of the long form of define-method-combination
  4252. ;The default method-combination technique
  4253. (define-method-combination standard ()
  4254. ((around (:around))
  4255. (before (:before))
  4256. (primary () :required t)
  4257. (after (:after)))
  4258. (flet ((call-methods (methods)
  4259. (mapcar #'(lambda (method)
  4260. `(call-method ,method))
  4261. methods)))
  4262. (let ((form (if (or before after (rest primary))
  4263. `(multiple-value-prog1
  4264. (progn ,@@(call-methods before)
  4265. (call-method ,(first primary)
  4266. ,(rest primary)))
  4267. ,@@(call-methods (reverse after)))
  4268. `(call-method ,(first primary)))))
  4269. (if around
  4270. `(call-method ,(first around)
  4271. (,@@(rest around)
  4272. (make-method ,form)))
  4273. form))))
  4274. ;A simple way to try several methods until one returns non-nil
  4275. (define-method-combination or ()
  4276. ((methods (or)))
  4277. `(or ,@@(mapcar #'(lambda (method)
  4278. `(call-method ,method))
  4279. methods)))
  4280. ;A more complete version of the preceding
  4281. (define-method-combination or
  4282. (&optional (order ':most-specific-first))
  4283. ((around (:around))
  4284. (primary (or)))
  4285. ;; Process the order argument
  4286. (case order
  4287. (:most-specific-first)
  4288. (:most-specific-last (setq primary (reverse primary)))
  4289. (otherwise (method-combination-error "~S is an invalid order.~@@
  4290. :most-specific-first and :most-specific-last are the possible values."
  4291. order)))
  4292. ;; Must have a primary method
  4293. (unless primary
  4294. (method-combination-error "A primary method is required."))
  4295. ;; Construct the form that calls the primary methods
  4296. (let ((form (if (rest primary)
  4297. `(or ,@@(mapcar #'(lambda (method)
  4298. `(call-method ,method))
  4299. primary))
  4300. `(call-method ,(first primary)))))
  4301. ;; Wrap the around methods around that form
  4302. (if around
  4303. `(call-method ,(first around)
  4304. (,@@(rest around)
  4305. (make-method ,form)))
  4306. form)))
  4307. ;The same thing, using the :order and :required keyword options
  4308. (define-method-combination or
  4309. (&optional (order ':most-specific-first))
  4310. ((around (:around))
  4311. (primary (or) :order order :required t))
  4312. (let ((form (if (rest primary)
  4313. `(or ,@@(mapcar #'(lambda (method)
  4314. `(call-method ,method))
  4315. primary))
  4316. `(call-method ,(first primary)))))
  4317. (if around
  4318. `(call-method ,(first around)
  4319. (,@@(rest around)
  4320. (make-method ,form)))
  4321. form)))
  4322. ;This short-form call is behaviorally identical to the preceding
  4323. (define-method-combination or :identity-with-one-argument t)
  4324. ;Order methods by positive integer qualifiers
  4325. ;:around methods are disallowed to keep the example small
  4326. (define-method-combination example-method-combination ()
  4327. ((methods positive-integer-qualifier-p))
  4328. `(progn ,@@(mapcar #'(lambda (method)
  4329. `(call-method ,method))
  4330. (stable-sort methods #'<
  4331. :key #'(lambda (method)
  4332. (first (method-qualifiers method)))))))
  4333. (defun positive-integer-qualifier-p (method-qualifiers)
  4334. (and (= (length method-qualifiers) 1)
  4335. (typep (first method-qualifiers) '(integer 0 *))))
  4336. ;;; Example of the use of :arguments
  4337. (define-method-combination progn-with-lock ()
  4338. ((methods ()))
  4339. (:arguments object)
  4340. `(unwind-protect
  4341. (progn (lock (object-lock ,object))
  4342. ,@@(mapcar #'(lambda (method)
  4343. `(call-method ,method))
  4344. methods))
  4345. (unlock (object-lock ,object))))
  4346. @end example
  4347. @subsubheading Side Effects::
  4348. The @i{compiler} is not required to perform any compile-time side-effects.
  4349. @subsubheading Exceptional Situations::
  4350. Method combination types defined with the short form require exactly
  4351. one @i{qualifier} per method.
  4352. An error of @i{type} @b{error} is signaled if there are
  4353. applicable methods with no @i{qualifiers} or with @i{qualifiers} that are not
  4354. supported by the method combination type.
  4355. At least one primary method must be applicable or
  4356. an error of @i{type} @b{error} is signaled.
  4357. If an applicable method does not fall into any method group, the
  4358. system signals an error of @i{type} @b{error}
  4359. indicating that the method is invalid for the kind of
  4360. method combination in use.
  4361. If the value of the @t{:required} option is @i{true}
  4362. and the method group is empty (that is, no applicable
  4363. methods match the @i{qualifier} patterns or satisfy the predicate),
  4364. an error of @i{type} @b{error} is signaled.
  4365. If the @t{:order} option evaluates to a value other than
  4366. @t{:most-specific-first} or @t{:most-specific-last},
  4367. an error of @i{type} @b{error} is signaled.
  4368. @subsubheading See Also::
  4369. @ref{call-method; make-method}
  4370. ,
  4371. @ref{call-next-method}
  4372. ,
  4373. @ref{documentation; (setf documentation)}
  4374. ,
  4375. @ref{method-qualifiers}
  4376. ,
  4377. @ref{method-combination-error}
  4378. ,
  4379. @ref{invalid-method-error}
  4380. ,
  4381. @ref{defgeneric}
  4382. ,
  4383. @ref{Method Selection and Combination},
  4384. @ref{Built-in Method Combination Types},
  4385. @ref{Syntactic Interaction of Documentation Strings and Declarations}
  4386. @subsubheading Notes::
  4387. The @t{:method-combination} option of @b{defgeneric} is used to
  4388. specify that a @i{generic function} should use a particular method
  4389. combination type. The first argument to the @t{:method-combination}
  4390. option is the @i{name} of a method combination type and the remaining
  4391. arguments are options for that type.
  4392. @node find-method, add-method, define-method-combination, Objects Dictionary
  4393. @subsection find-method [Standard Generic Function]
  4394. @subsubheading Syntax::
  4395. @code{find-method} @i{generic-function method-qualifiers specializers {&optional} errorp}@*
  4396. @result{} @i{method}
  4397. @subsubheading Method Signatures::
  4398. @code{find-method} @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
  4399. method-qualifiers specializers {&optional} errorp}
  4400. @subsubheading Arguments and Values::
  4401. @i{generic-function}---a @i{generic function}.
  4402. @i{method-qualifiers}---a @i{list}.
  4403. @i{specializers}---a @i{list}.
  4404. @i{errorp}---a @i{generalized boolean}.
  4405. The default is @i{true}.
  4406. @i{method}---a @i{method} @i{object}, or @b{nil}.
  4407. @subsubheading Description::
  4408. The @i{generic function} @b{find-method} takes a @i{generic function}
  4409. and returns the @i{method} @i{object} that agrees on @i{qualifiers}
  4410. and @i{parameter specializers} with the @i{method-qualifiers} and
  4411. @i{specializers} arguments of @b{find-method}.
  4412. @i{Method-qualifiers} contains the
  4413. method @i{qualifiers} for the @i{method}.
  4414. The order of the method @i{qualifiers}
  4415. is significant.
  4416. For a definition of agreement in this context,
  4417. see @ref{Agreement on Parameter Specializers and Qualifiers}.
  4418. The @i{specializers} argument contains the parameter
  4419. specializers for the @i{method}. It must correspond in length to
  4420. the number of required arguments of the @i{generic function}, or
  4421. an error is signaled. This means that to obtain the
  4422. default @i{method} on a given @i{generic-function},
  4423. a @i{list} whose elements are the @i{class} @b{t} must be given.
  4424. If there is no such @i{method} and @i{errorp} is @i{true},
  4425. @b{find-method} signals an error.
  4426. If there is no such @i{method} and @i{errorp} is @i{false},
  4427. @b{find-method} returns @b{nil}.
  4428. @subsubheading Examples::
  4429. @example
  4430. (defmethod some-operation ((a integer) (b float)) (list a b))
  4431. @result{} #<STANDARD-METHOD SOME-OPERATION (INTEGER FLOAT) 26723357>
  4432. (find-method #'some-operation '() (mapcar #'find-class '(integer float)))
  4433. @result{} #<STANDARD-METHOD SOME-OPERATION (INTEGER FLOAT) 26723357>
  4434. (find-method #'some-operation '() (mapcar #'find-class '(integer integer)))
  4435. @t{ |> } Error: No matching method
  4436. (find-method #'some-operation '() (mapcar #'find-class '(integer integer)) nil)
  4437. @result{} NIL
  4438. @end example
  4439. @subsubheading Affected By::
  4440. @b{add-method},
  4441. @b{defclass},
  4442. @b{defgeneric},
  4443. @b{defmethod}
  4444. @subsubheading Exceptional Situations::
  4445. If the @i{specializers} argument does not correspond in length to
  4446. the number of required arguments of the @i{generic-function}, an
  4447. an error of @i{type} @b{error} is signaled.
  4448. If there is no such @i{method} and @i{errorp} is @i{true},
  4449. @b{find-method} signals an error of @i{type} @b{error}.
  4450. @subsubheading See Also::
  4451. @ref{Agreement on Parameter Specializers and Qualifiers}
  4452. @node add-method, initialize-instance, find-method, Objects Dictionary
  4453. @subsection add-method [Standard Generic Function]
  4454. @subsubheading Syntax::
  4455. @code{add-method} @i{generic-function method} @result{} @i{generic-function}
  4456. @subsubheading Method Signatures::
  4457. @code{add-method} @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
  4458. @r{(}@i{method} @b{method}@r{)}}
  4459. @subsubheading Arguments and Values::
  4460. @i{generic-function}---a @i{generic function} @i{object}.
  4461. @i{method}---a @i{method} @i{object}.
  4462. @subsubheading Description::
  4463. The generic function @b{add-method} adds a @i{method}
  4464. to a @i{generic function}.
  4465. If @i{method} agrees with an existing @i{method} of @i{generic-function}
  4466. on @i{parameter specializers} and @i{qualifiers},
  4467. the existing @i{method} is replaced.
  4468. @subsubheading Exceptional Situations::
  4469. The @i{lambda list} of the method function of @i{method} must be
  4470. congruent with the @i{lambda list} of @i{generic-function},
  4471. or an error of @i{type} @b{error} is signaled.
  4472. If @i{method} is a @i{method} @i{object} of
  4473. another @i{generic function}, an error of @i{type} @b{error} is signaled.
  4474. @subsubheading See Also::
  4475. @ref{defmethod}
  4476. ,
  4477. @ref{defgeneric}
  4478. ,
  4479. @ref{find-method}
  4480. ,
  4481. @ref{remove-method}
  4482. ,
  4483. @ref{Agreement on Parameter Specializers and Qualifiers}
  4484. @node initialize-instance, class-name, add-method, Objects Dictionary
  4485. @subsection initialize-instance [Standard Generic Function]
  4486. @subsubheading Syntax::
  4487. @code{initialize-instance} @i{instance {&rest} initargs {&key} {&allow-other-keys}} @result{} @i{instance}
  4488. @subsubheading Method Signatures::
  4489. @code{initialize-instance} @i{@r{(}@i{instance} @b{standard-object}@r{)} {&rest} initargs}
  4490. @subsubheading Arguments and Values::
  4491. @i{instance}---an @i{object}.
  4492. @i{initargs}---a @i{defaulted initialization argument list}.
  4493. @subsubheading Description::
  4494. Called by @b{make-instance} to initialize a newly created @i{instance}.
  4495. The generic function is called with the new @i{instance}
  4496. and the @i{defaulted initialization argument list}.
  4497. The system-supplied primary @i{method} on @b{initialize-instance}
  4498. initializes the @i{slots} of the @i{instance} with values according
  4499. to the @i{initargs} and the @t{:initform} forms of the @i{slots}.
  4500. It does this by calling the generic function @b{shared-initialize}
  4501. with the following arguments: the @i{instance}, @b{t} (this indicates
  4502. that all @i{slots} for which no initialization arguments are provided
  4503. should be initialized according to their @t{:initform} forms), and
  4504. the @i{initargs}.
  4505. Programmers can define @i{methods} for @b{initialize-instance} to
  4506. specify actions to be taken when an instance is initialized. If only
  4507. @i{after methods} are defined, they will be run after the
  4508. system-supplied primary @i{method} for initialization and therefore will
  4509. not interfere with the default behavior of @b{initialize-instance}.
  4510. @subsubheading See Also::
  4511. @ref{Shared-Initialize}
  4512. ,
  4513. @ref{make-instance}
  4514. ,
  4515. @ref{slot-boundp}
  4516. ,
  4517. @ref{slot-makunbound}
  4518. ,
  4519. @ref{Object Creation and Initialization},
  4520. @ref{Rules for Initialization Arguments},
  4521. @ref{Declaring the Validity of Initialization Arguments}
  4522. @node class-name, (setf class-name), initialize-instance, Objects Dictionary
  4523. @subsection class-name [Standard Generic Function]
  4524. @subsubheading Syntax::
  4525. @code{class-name} @i{class} @result{} @i{name}
  4526. @subsubheading Method Signatures::
  4527. @code{class-name} @i{@r{(}@i{class} @b{class}@r{)}}
  4528. @subsubheading Arguments and Values::
  4529. @i{class}---a @i{class} @i{object}.
  4530. @i{name}---a @i{symbol}.
  4531. @subsubheading Description::
  4532. Returns the @i{name} of the given @i{class}.
  4533. @subsubheading See Also::
  4534. @ref{find-class}
  4535. ,
  4536. @ref{Classes}
  4537. @subsubheading Notes::
  4538. If S is a @i{symbol} such that S =@t{(class-name C)}
  4539. and C =@t{(find-class S)}, then S is the proper name of C.
  4540. For further discussion, see @ref{Classes}.
  4541. The name of an anonymous @i{class} is @b{nil}.
  4542. @node (setf class-name), class-of, class-name, Objects Dictionary
  4543. @subsection (setf class-name) [Standard Generic Function]
  4544. @subsubheading Syntax::
  4545. @code{(setf class-name)} @i{new-value class} @result{} @i{new-value}
  4546. @subsubheading Method Signatures::
  4547. @code{(setf class-name)} @i{new-value @r{(}@i{class} @b{class}@r{)}}
  4548. @subsubheading Arguments and Values::
  4549. @i{new-value}---a @i{symbol}.
  4550. @i{class}---a @i{class}.
  4551. @subsubheading Description::
  4552. The generic function @t{(setf class-name)} sets the name of
  4553. a @i{class} object.
  4554. @subsubheading See Also::
  4555. @ref{find-class}
  4556. ,
  4557. @i{proper name},
  4558. @ref{Classes}
  4559. @node class-of, unbound-slot, (setf class-name), Objects Dictionary
  4560. @subsection class-of [Function]
  4561. @code{class-of} @i{object} @result{} @i{class}
  4562. @subsubheading Arguments and Values::
  4563. @i{object}---an @i{object}.
  4564. @i{class}---a @i{class} @i{object}.
  4565. @subsubheading Description::
  4566. Returns the @i{class} of which the @i{object} is
  4567. a @i{direct instance}.
  4568. @subsubheading Examples::
  4569. @example
  4570. (class-of 'fred) @result{} #<BUILT-IN-CLASS SYMBOL 610327300>
  4571. (class-of 2/3) @result{} #<BUILT-IN-CLASS RATIO 610326642>
  4572. (defclass book () ()) @result{} #<STANDARD-CLASS BOOK 33424745>
  4573. (class-of (make-instance 'book)) @result{} #<STANDARD-CLASS BOOK 33424745>
  4574. (defclass novel (book) ()) @result{} #<STANDARD-CLASS NOVEL 33424764>
  4575. (class-of (make-instance 'novel)) @result{} #<STANDARD-CLASS NOVEL 33424764>
  4576. (defstruct kons kar kdr) @result{} KONS
  4577. (class-of (make-kons :kar 3 :kdr 4)) @result{} #<STRUCTURE-CLASS KONS 250020317>
  4578. @end example
  4579. @subsubheading See Also::
  4580. @ref{make-instance}
  4581. ,
  4582. @ref{type-of}
  4583. @node unbound-slot, unbound-slot-instance, class-of, Objects Dictionary
  4584. @subsection unbound-slot [Condition Type]
  4585. @subsubheading Class Precedence List::
  4586. @b{unbound-slot},
  4587. @b{cell-error},
  4588. @b{error},
  4589. @b{serious-condition},
  4590. @b{condition},
  4591. @b{t}
  4592. @subsubheading Description::
  4593. The @i{object} having the unbound slot is initialized by
  4594. the @t{:instance} initialization argument to @b{make-condition},
  4595. and is @i{accessed} by the @i{function} @b{unbound-slot-instance}.
  4596. The name of the cell (see @b{cell-error}) is the name of the slot.
  4597. @subsubheading See Also::
  4598. @ref{cell-error-name}
  4599. ,
  4600. @b{unbound-slot-object},
  4601. @ref{Condition System Concepts}
  4602. @node unbound-slot-instance, , unbound-slot, Objects Dictionary
  4603. @subsection unbound-slot-instance [Function]
  4604. @code{unbound-slot-instance} @i{condition} @result{} @i{instance}
  4605. @subsubheading Arguments and Values::
  4606. @i{condition}---a @i{condition} of @i{type} @b{unbound-slot}.
  4607. @i{instance}---an @i{object}.
  4608. @subsubheading Description::
  4609. Returns the instance which had the unbound slot in the @i{situation}
  4610. represented by the @i{condition}.
  4611. @subsubheading See Also::
  4612. @ref{cell-error-name}
  4613. ,
  4614. @b{unbound-slot},
  4615. @ref{Condition System Concepts}
  4616. @c end of including dict-objects
  4617. @c %**end of chapter