dict-objects.tex 180 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010
  1. % -*- Mode: TeX -*-
  2. \def\GFauxOptionsAndMethDesc{
  3. \auxbnf{option}{\paren{\kwd{argument-precedence-order} \plusparam{parameter-name}} | \CR
  4. \paren{\misc{declare} \plusparam{declaration}} | \CR
  5. \paren{\kwd{documentation} \i{string}} | \CR
  6. \paren{\kwd{method-combination} \i{symbol} \starparam{arg}} | \CR
  7. \paren{\kwd{generic-function-class} \i{class-name}} | \CR
  8. \paren{\kwd{method-class} \i{class-name}}}
  9. \auxbnf{method-description}{\lparen\kwd{method} \CR
  10. \ \starparam{method-qualifier} specialized-lambda-list \CR
  11. \ {\DeclsAndDoc} \CR
  12. \ \starparam{form}\rparen}
  13. }
  14. %%% ========== FUNCTION-KEYWORDS
  15. \begincom{function-keywords}\ftype{Standard Generic Function}
  16. %Barmar: This function should have been called ``method-keywords.''
  17. \label Syntax::
  18. \DefgenWithValues {function-keywords} {method} {keys, allow-other-keys-p}
  19. \label Method Signatures::
  20. \Defmeth {function-keywords} {\specparam{method}{standard-method}}
  21. \label Arguments and Values::
  22. \param{method}---a \term{method}.
  23. \param{keys}---a \term{list}.
  24. \param{allow-other-keys-p}---a \term{generalized boolean}.
  25. \label Description::
  26. Returns the keyword parameter specifiers for a \param{method}.
  27. Two values are returned:
  28. a \term{list} of the explicitly named keywords
  29. and a \term{generalized boolean} that states whether \keyref{allow-other-keys}
  30. had been specified in the \param{method} definition.
  31. \label Examples::
  32. \code
  33. (defmethod gf1 ((a integer) &optional (b 2)
  34. &key (c 3) ((:dee d) 4) e ((eff f)))
  35. (list a b c d e f))
  36. \EV #<STANDARD-METHOD GF1 (INTEGER) 36324653>
  37. (find-method #'gf1 '() (list (find-class 'integer)))
  38. \EV #<STANDARD-METHOD GF1 (INTEGER) 36324653>
  39. (function-keywords *)
  40. \EV (:C :DEE :E EFF), \term{false}
  41. (defmethod gf2 ((a integer))
  42. (list a b c d e f))
  43. \EV #<STANDARD-METHOD GF2 (INTEGER) 42701775>
  44. (function-keywords (find-method #'gf1 '() (list (find-class 'integer))))
  45. \EV (), \term{false}
  46. (defmethod gf3 ((a integer) &key b c d &allow-other-keys)
  47. (list a b c d e f))
  48. (function-keywords *)
  49. \EV (:B :C :D), \term{true}
  50. \endcode
  51. \label Affected By::
  52. \macref{defmethod}
  53. \label Exceptional Situations:\None.
  54. \label See Also::
  55. \macref{defmethod}
  56. \label Notes:\None.
  57. \endcom
  58. %%% ========== ENSURE-GENERIC-FUNCTION
  59. \begincom{ensure-generic-function}\ftype{Function}
  60. \label Syntax::
  61. \DefunWithValuesNewline ensure-generic-function
  62. {function-name {\key}
  63. \vtop{\hbox{argument-precedence-order declare}
  64. \hbox{documentation environment}
  65. \hbox{generic-function-class lambda-list}
  66. \hbox{method-class method-combination}}}
  67. {generic-function}
  68. \label Arguments and Values::
  69. \param{function-name}---a \term{function name}.
  70. The keyword arguments correspond to the \param{option} arguments of
  71. \macref{defgeneric}, except that the \kwd{method-class} and
  72. \kwd{generic-function-class} arguments can be \term{class} \term{object}s
  73. as well as names.
  74. %!!! What's a method combination object??
  75. {\keyword Method-combination} -- method combination object.
  76. {\keyword Environment} -- the same as the \keyref{environment} argument
  77. to macro expansion functions and is used to distinguish between compile-time
  78. and run-time environments.
  79. %Barmar said (and I agree) that this just doesn't belong here.
  80. % \issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  81. % The \keyref{environment} argument has
  82. % \term{dynamic extent}; the consequences are undefined if
  83. % the \keyref{environment} argument is
  84. % referred to outside the \term{dynamic extent}
  85. % of the macro expansion function.
  86. % \endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  87. \editornote{KMP: What about documentation. Missing from this arguments enumeration,
  88. and confusing in description below.}%!!!
  89. \param{generic-function}---a \term{generic function} \term{object}.
  90. \label Description::
  91. \Thefunction{ensure-generic-function} is used to define
  92. a globally named \term{generic function} with no \term{methods}
  93. or to specify or modify options and declarations that pertain to
  94. a globally named \term{generic function} as a whole.
  95. %!!! This used to refer to FBOUNDP but I changed it to use "fbound".
  96. % The question is, why is it looking in the global env if an environment
  97. % argument was passed.
  98. If \param{function-name} is not \term{fbound} in the \term{global environment},
  99. a new
  100. \term{generic function} is created.
  101. %!!! Rewrite in terms of function cell contents?
  102. If
  103. \issue{FUNCTION-NAME:LARGE}
  104. \f{(fdefinition \param{function-name})}
  105. \endissue{FUNCTION-NAME:LARGE}
  106. is an \term{ordinary function},
  107. a \term{macro},
  108. or a \term{special operator},
  109. an error is signaled.
  110. If \param{function-name}
  111. is a \term{list}, it must be of the
  112. form \f{(setf \param{symbol})}.
  113. If \param{function-name} specifies a \term{generic function} that has a
  114. different value for any of the following arguments,
  115. the \term{generic function} is modified to have the new value:
  116. \kwd{argument-precedence-order}, \kwd{declare}, \kwd{documentation},
  117. \kwd{method-combination}.
  118. If \param{function-name} specifies a \term{generic function} that has a
  119. different value for the \kwd{lambda-list} argument, and the new value
  120. is congruent with the \term{lambda lists} of all existing
  121. \term{methods} or there
  122. are no \term{methods}, the value is changed; otherwise an error is signaled.
  123. %!!! Barmar: What does this part about
  124. % "new generic function class is compatible with the old" mean?
  125. If \param{function-name} specifies a \term{generic function} that has a
  126. different value for the \kwd{generic-function-class} argument and if
  127. the new generic function class is compatible with the old,
  128. \funref{change-class} is called to change the \term{class} of the
  129. \term{generic function};
  130. otherwise an error is signaled.
  131. If \param{function-name} specifies a \term{generic function} that has a
  132. different value for the \kwd{method-class} argument, the value is
  133. changed, but any existing \term{methods} are not changed.
  134. \label Examples:\None.
  135. \label Affected By::
  136. Existing function binding of \param{function-name}.
  137. \label Exceptional Situations::
  138. If
  139. \issue{FUNCTION-NAME:LARGE}
  140. \f{(fdefinition \param{function-name})}
  141. \endissue{FUNCTION-NAME:LARGE}
  142. is an \term{ordinary function}, a \term{macro}, or a \term{special operator},
  143. an error \oftype{error} is signaled.
  144. If \param{function-name} specifies a
  145. \term{generic function} that has a
  146. different value for the \kwd{lambda-list} argument, and the new value
  147. is not congruent with the \term{lambda list} of any existing
  148. \term{method},
  149. an error \oftype{error} is signaled.
  150. If \param{function-name} specifies a
  151. \term{generic function} that has a
  152. different value for the \kwd{generic-function-class} argument and if
  153. the new generic function class not is compatible with the old,
  154. an error \oftype{error} is signaled.
  155. \label See Also::
  156. \macref{defgeneric}
  157. \label Notes:\None.
  158. \endcom
  159. %%% ========== ALLOCATE-INSTANCE
  160. \begincom{allocate-instance}\ftype{Standard Generic Function}
  161. \issue{ALLOCATE-INSTANCE:ADD}
  162. \label Syntax::
  163. \issue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  164. \DefgenWithValues allocate-instance
  165. {class {\rest} initargs {\key} {\allowotherkeys}}
  166. {new-instance}
  167. \endissue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  168. \label Method Signatures::
  169. \Defmeth {allocate-instance} {\specparam{class}{standard-class} {\rest} initargs}
  170. \Defmeth {allocate-instance} {\specparam{class}{structure-class} {\rest} initargs}
  171. \label Arguments and Values::
  172. \param{class}---a \term{class}.
  173. \param{initargs}---a \term{list} of \term{keyword/value pairs}
  174. (initialization argument \term{names} and \term{values}).
  175. \param{new-instance}---an \term{object} whose \term{class} is \param{class}.
  176. \label Description::
  177. The generic function \funref{allocate-instance} creates and returns
  178. a new instance of the \param{class}, without initializing it.
  179. When the \param{class} is a \term{standard class}, this means that
  180. the \term{slots} are \term{unbound}; when the \term{class} is a
  181. \term{structure class}, this means the \term{slots}' \term{values}
  182. are unspecified.
  183. The caller of \funref{allocate-instance} is expected to have
  184. already checked the initialization arguments.
  185. The \term{generic function} \funref{allocate-instance} is called by
  186. \funref{make-instance}, as described in
  187. \secref\ObjectCreationAndInit.
  188. \label Affected By:\None. % ????
  189. \label Exceptional Situations:\None. % ????
  190. \label See Also::
  191. \macref{defclass}, \funref{make-instance}, \funref{class-of},
  192. {\secref\ObjectCreationAndInit}
  193. \label Notes::
  194. The consequences of adding \term{methods} to \funref{allocate-instance} is unspecified.
  195. This capability might be added by the \term{Metaobject Protocol}.
  196. % kmp: This section was copied with minor changes from
  197. % \funref{make-instance}, and then reviewed by Moon.
  198. \endissue{ALLOCATE-INSTANCE:ADD}
  199. \endcom
  200. %%% ========== REINITIALIZE-INSTANCE
  201. \begincom{reinitialize-instance}\ftype{Standard Generic Function}
  202. \label Syntax::
  203. \issue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  204. \DefgenWithValues reinitialize-instance
  205. {instance {\rest} initargs {\key} {\allowotherkeys}}
  206. {instance}
  207. \endissue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  208. \label Method Signatures::
  209. \Defmeth reinitialize-instance {\specparam{instance}{standard-object} {\rest} initargs}
  210. \label Arguments and Values::
  211. \param{instance}---an \term{object}.
  212. \param{initargs}---an \term{initialization argument list}.
  213. \label Description::
  214. The \term{generic function} \funref{reinitialize-instance} can be used to change
  215. the values of \term{local slots} of an \param{instance} according to
  216. \param{initargs}.
  217. %This generic function is called by the Meta-Object
  218. %Protocol.
  219. This \term{generic function} can be called by users.
  220. The system-supplied primary \term{method} for \funref{reinitialize-instance}
  221. checks the validity of \param{initargs} and signals an error if
  222. an \param{initarg} is supplied that is not declared as valid.
  223. The \term{method} then calls the generic function \funref{shared-initialize}
  224. with the following arguments: the \param{instance},
  225. \nil\ (which means no \term{slots}
  226. should be initialized according to their initforms), and the
  227. \param{initargs} it received.
  228. \label Examples:\None.
  229. \label Side Effects::
  230. \TheGF{reinitialize-instance} changes the values of \term{local slots}.
  231. \label Affected By:\None.
  232. \label Exceptional Situations::
  233. The system-supplied primary \term{method} for \funref{reinitialize-instance}
  234. signals an error if an \param{initarg} is supplied that is not declared as valid.
  235. \label See Also::
  236. \funref{initialize-instance},
  237. \funref{shared-initialize},
  238. \funref{update-instance-for-redefined-class},
  239. \funref{update-instance-for-different-class},
  240. \funref{slot-boundp},
  241. \funref{slot-makunbound},
  242. {\secref\InstanceReInit},
  243. {\secref\InitargRules},
  244. {\secref\DeclaringInitargValidity}
  245. \label Notes::
  246. \param{Initargs} are declared as valid by using the
  247. \kwd{initarg} option to \macref{defclass}, or by defining
  248. \term{methods} for \funref{reinitialize-instance}
  249. or \funref{shared-initialize}. The keyword name
  250. of each keyword parameter specifier in the \term{lambda list} of any
  251. \term{method}
  252. defined on \funref{reinitialize-instance} or \funref{shared-initialize} is
  253. declared as a valid initialization argument name for all
  254. \term{classes} for
  255. which that \term{method} is applicable.
  256. \endcom
  257. %%% ========== SHARED-INITIALIZE
  258. \begincom{shared-initialize}\ftype{Standard Generic Function}
  259. \label Syntax::
  260. \issue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  261. \DefgenWithValues shared-initialize
  262. {instance slot-names {\rest} initargs {\key} {\allowotherkeys}}
  263. {instance}
  264. \endissue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  265. \label Method Signatures::
  266. \Defmeth shared-initialize {\specparam{instance}{standard-object} slot-names {\rest} initargs}
  267. \label Arguments and Values::
  268. \param{instance}---an \term{object}.
  269. \param{slot-names}---a \term{list} or \t.
  270. \param{initargs}---a \term{list} of \term{keyword/value pairs}
  271. (of initialization argument \term{names} and \term{values}).
  272. \label Description::
  273. The generic function \funref{shared-initialize} is used to fill the
  274. \term{slots}
  275. of an \param{instance}
  276. using \param{initargs} and \kwd{initform}
  277. forms. It is called when an instance is created, when an instance is
  278. re-initialized, when an instance is updated to conform to a redefined
  279. \term{class}, and when an instance is updated to conform to a different
  280. \term{class}. The generic function \funref{shared-initialize} is called by the
  281. system-supplied primary \term{method} for \funref{initialize-instance},
  282. \funref{reinitialize-instance}, \funref{update-instance-for-redefined-class}, and
  283. \funref{update-instance-for-different-class}.
  284. The generic function \funref{shared-initialize} takes the following
  285. arguments: the \param{instance} to be initialized, a specification of a set of
  286. \param{slot-names} \term{accessible} in that \param{instance},
  287. and any number of \param{initargs}.
  288. The arguments after the first two must form an
  289. \term{initialization argument list}. The system-supplied primary \term{method} on
  290. \funref{shared-initialize} initializes the \term{slots} with values according to the
  291. \param{initargs} and supplied \kwd{initform} forms. \param{Slot-names}
  292. indicates which \term{slots} should be initialized according
  293. to their \kwd{initform} forms if no \param{initargs} are
  294. provided for those \term{slots}.
  295. The system-supplied primary \term{method} behaves as follows,
  296. regardless of whether the \term{slots} are local or shared:
  297. \beginlist
  298. \itemitem{\bull}
  299. If an \param{initarg} in the \term{initialization argument list}
  300. specifies a value for that \term{slot}, that
  301. value is stored into the \term{slot}, even if a value has
  302. already been stored in the \term{slot} before the \term{method} is run.
  303. \itemitem{\bull}
  304. Any \term{slots} indicated by \param{slot-names} that are still unbound
  305. at this point are initialized according to their \kwd{initform} forms.
  306. For any such \term{slot} that has an \kwd{initform} form,
  307. that \term{form} is evaluated in the lexical environment of its defining
  308. \macref{defclass} \term{form} and the result is stored into the \term{slot}.
  309. For example, if a \term{before method} stores a value in the \term{slot},
  310. the \kwd{initform} form will not be used to supply a value for the \term{slot}.
  311. \itemitem{\bull}
  312. The rules mentioned in {\secref\InitargRules} are obeyed.
  313. \endlist
  314. The \param{slots-names} argument specifies the \term{slots} that are to be
  315. initialized according to their \kwd{initform} forms if no
  316. initialization arguments apply. It can be a \term{list} of slot \term{names},
  317. which specifies the set of those slot \term{names}; or it can be the \term{symbol} \t,
  318. which specifies the set of all of the \term{slots}.
  319. %The generic function \funref{shared-initialize} fills the \term{slots}
  320. %of \param{instance}.
  321. \label Examples:\None.
  322. \label Affected By:\None.
  323. \label Exceptional Situations:\None.
  324. %% Removed per X3J13. -kmp 5-Oct-93
  325. % An error \oftype{error} is signaled if an \param{initarg}
  326. % is supplied that is not declared as valid.
  327. \label See Also::
  328. \funref{initialize-instance},
  329. \funref{reinitialize-instance},
  330. \funref{update-instance-for-redefined-class},
  331. \funref{update-instance-for-different-class},
  332. \funref{slot-boundp},
  333. \funref{slot-makunbound},
  334. {\secref\ObjectCreationAndInit},
  335. {\secref\InitargRules},
  336. {\secref\DeclaringInitargValidity}
  337. \label Notes::
  338. \param{Initargs} are declared as valid by using the \kwd{initarg}
  339. option to \macref{defclass}, or by defining
  340. \term{methods} for \funref{shared-initialize}.
  341. The keyword name of each keyword parameter
  342. specifier in the \term{lambda list} of any \term{method} defined on
  343. \funref{shared-initialize} is declared as a valid \param{initarg}
  344. name for all \term{classes} for which that \term{method} is applicable.
  345. Implementations are permitted to optimize \kwd{initform} forms that
  346. neither produce nor depend on side effects, by evaluating these \term{forms}
  347. and storing them into slots before running any
  348. \funref{initialize-instance} methods, rather than by handling them in the
  349. primary \funref{initialize-instance} method. (This optimization might
  350. be implemented by having the \funref{allocate-instance} method copy a
  351. prototype instance.)
  352. Implementations are permitted to optimize default initial value forms
  353. for \param{initargs} associated with slots by not actually
  354. creating the complete initialization argument
  355. \term{list} when the only \term{method}
  356. that would receive the complete \term{list} is the
  357. \term{method} on \typeref{standard-object}.
  358. In this case default initial value forms can be
  359. treated like \kwd{initform} forms. This optimization has no visible
  360. effects other than a performance improvement.
  361. \endcom
  362. %%% ========== UPDATE-INSTANCE-FOR-DIFFERENT-CLASS
  363. \begincom{update-instance-for-different-class}\ftype{Standard Generic Function}
  364. \label Syntax::
  365. \issue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  366. \DefgenWithValues update-instance-for-different-class
  367. {previous current
  368. {\rest} initargs
  369. {\key} {\allowotherkeys}}
  370. {\term{implementation-dependent}}
  371. \endissue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  372. \label Method Signatures::
  373. \Defmeth {update-instance-for-different-class}
  374. {\vtop{\hbox{\specparam{previous}{standard-object}}
  375. \hbox{\specparam{current}{standard-object}}
  376. \hbox{{\rest} initargs}}}
  377. \label Arguments and Values::
  378. \param{previous}---a copy of the original \term{instance}.
  379. \param{current}---the original \term{instance} (altered).
  380. \param{initargs}---an \term{initialization argument list}.
  381. \label Description::
  382. The generic function \funref{update-instance-for-different-class} is not
  383. intended to be called by programmers. Programmers may write
  384. \term{methods} for it. \Thefunction{update-instance-for-different-class}
  385. is called only by \thefunction{change-class}.
  386. The system-supplied primary \term{method} on
  387. \funref{update-instance-for-different-class} checks the validity of
  388. \param{initargs} and signals an error if an \param{initarg}
  389. is supplied that is not declared as valid. This \term{method} then
  390. initializes \term{slots} with values according to the \param{initargs},
  391. and initializes the newly added \term{slots} with values according
  392. to their \kwd{initform} forms. It does this by calling the generic
  393. function \funref{shared-initialize} with the following arguments: the
  394. instance (\param{current}),
  395. a list of \term{names} of the newly added \term{slots}, and the \param{initargs}
  396. it received. Newly added \term{slots} are those \term{local slots} for which
  397. no \term{slot} of the same name exists in the \param{previous} class.
  398. \term{Methods} for \funref{update-instance-for-different-class} can be defined to
  399. specify actions to be taken when an \term{instance} is updated. If only
  400. \term{after methods} for \funref{update-instance-for-different-class} are
  401. defined, they will be run after the system-supplied primary \term{method} for
  402. initialization and therefore will not interfere with the default
  403. behavior of \funref{update-instance-for-different-class}.
  404. \term{Methods} on \funref{update-instance-for-different-class} can be defined to
  405. initialize \term{slots} differently from \funref{change-class}. The default
  406. behavior of \funref{change-class} is described in
  407. \secref\ChangingInstanceClass.
  408. The arguments to \funref{update-instance-for-different-class} are
  409. computed by \funref{change-class}. When \funref{change-class} is invoked on
  410. an \term{instance}, a copy of that \term{instance} is made; \funref{change-class} then
  411. destructively alters the original \term{instance}. The first argument to
  412. \funref{update-instance-for-different-class}, \param{previous}, is that
  413. copy; it holds the old \term{slot} values temporarily. This argument has
  414. dynamic extent within \funref{change-class}; if it is referenced in any
  415. way once \funref{update-instance-for-different-class} returns, the
  416. results are undefined. The second argument to
  417. \funref{update-instance-for-different-class}, \param{current}, is the altered
  418. original \term{instance}.
  419. The intended use of \param{previous} is to extract old \term{slot} values by using
  420. \funref{slot-value} or \macref{with-slots} or by invoking
  421. a reader generic function, or to run other \term{methods} that were applicable to
  422. \term{instances} of
  423. the original \term{class}.
  424. %The system-supplied primary \term{method} on
  425. %\funref{update-instance-for-different-class}
  426. %initializes \term{slots} with values according to the initialization
  427. %arguments, and initializes the newly added \term{slots} with values according
  428. %to their \kwd{initform} forms.
  429. \label Examples::
  430. See the example for \thefunction{change-class}.
  431. \label Affected By:\None.
  432. \label Exceptional Situations::
  433. The system-supplied primary \term{method} on
  434. \funref{update-instance-for-different-class} signals an error if an
  435. initialization argument is supplied that is not declared as valid.
  436. \label See Also::
  437. \funref{change-class},
  438. \funref{shared-initialize},
  439. {\secref\ChangingInstanceClass},
  440. {\secref\InitargRules},
  441. {\secref\DeclaringInitargValidity}
  442. \label Notes::
  443. \param{Initargs} are declared as valid by using the \kwd{initarg}
  444. option to \macref{defclass}, or by defining \term{methods}
  445. for \funref{update-instance-for-different-class} or \funref{shared-initialize}.
  446. The keyword name of each keyword parameter specifier in the \term{lambda list} of
  447. any \term{method} defined on \funref{update-instance-for-different-class}
  448. or \funref{shared-initialize} is declared as a valid \param{initarg} name
  449. for all \term{classes} for which that \term{method} is applicable.
  450. The value returned by \funref{update-instance-for-different-class} is
  451. ignored by \funref{change-class}.
  452. \endcom
  453. %%% ========== UPDATE-INSTANCE-FOR-REDEFINED-CLASS
  454. \begincom{update-instance-for-redefined-class}\ftype{Standard Generic Function}
  455. \label Syntax::
  456. \issue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  457. \DefgenWithValuesNewline update-instance-for-redefined-class
  458. {\vtop{\hbox{instance}
  459. \hbox{added-slots discarded-slots}
  460. \hbox{property-list}
  461. \hbox{{\rest} initargs {\key} {\allowotherkeys}}}}
  462. {\starparam{result}}
  463. \endissue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  464. \label Method Signatures::
  465. \Defmeth {update-instance-for-redefined-class}
  466. {\vtop{\hbox{\specparam{instance}{standard-object}}
  467. \hbox{added-slots discarded-slots}
  468. \hbox{property-list}
  469. \hbox{{\rest} initargs}}}
  470. \label Arguments and Values::
  471. \param{instance}---an \term{object}.
  472. \param{added-slots}---a \term{list}.
  473. \param{discarded-slots}---a \term{list}.
  474. \param{property-list}---a \term{list}.
  475. \param{initargs}---an \term{initialization argument list}.
  476. \param{result}---an \term{object}.
  477. \label Description::
  478. The \term{generic function} \funref{update-instance-for-redefined-class}
  479. is not intended to be called by programmers. Programmers may write
  480. \term{methods} for it. The \term{generic function}
  481. \funref{update-instance-for-redefined-class} is called by the mechanism
  482. activated by \funref{make-instances-obsolete}.
  483. The system-supplied primary \term{method} on
  484. \funref{update-instance-for-redefined-class} checks the validity of
  485. \param{initargs} and signals an error if an \param{initarg}
  486. is supplied that is not declared as valid. This \term{method} then
  487. initializes \term{slots} with values according to the \param{initargs},
  488. and initializes the newly \param{added-slots} with values according
  489. to their \kwd{initform} forms. It does this by calling the generic
  490. function \funref{shared-initialize} with the following arguments:
  491. the \param{instance},
  492. a list of names of the newly \param{added-slots} to \param{instance},
  493. and the \param{initargs}
  494. it received. Newly \param{added-slots} are those \term{local slots} for which
  495. no \term{slot} of the same name exists in the old version of the \term{class}.
  496. When \funref{make-instances-obsolete} is invoked or when a \term{class} has been
  497. redefined and an \term{instance} is being updated, a \param{property-list} is created
  498. that captures the slot names and values of all the \param{discarded-slots} with
  499. values in the original \param{instance}. The structure of the
  500. \param{instance} is
  501. transformed so that it conforms to the current class definition. The
  502. arguments to \funref{update-instance-for-redefined-class} are this
  503. transformed \param{instance}, a list of \param{added-slots} to the
  504. \param{instance}, a list \param{discarded-slots} from the
  505. \param{instance}, and the \param{property-list}
  506. containing the slot names and values for
  507. \term{slots} that were discarded and had values. Included in this list of
  508. discarded \term{slots} are \term{slots} that were local in the old \term{class} and are
  509. shared in the new \term{class}.
  510. %The system-supplied primary \term{method} on
  511. %\funref{update-instance-for-redefined-class}
  512. %initializes \term{slots} with values according to the \param{initargs},
  513. %and initializes the newly \param{added-slots} with values according
  514. %to their \kwd{initform} forms. It does this by calling the generic
  515. %function \funref{shared-initialize}.
  516. %!!! So?
  517. The value returned by \funref{update-instance-for-redefined-class} is ignored.
  518. \label Examples::
  519. \code
  520. (defclass position () ())
  521. (defclass x-y-position (position)
  522. ((x :initform 0 :accessor position-x)
  523. (y :initform 0 :accessor position-y)))
  524. ;;; It turns out polar coordinates are used more than Cartesian
  525. ;;; coordinates, so the representation is altered and some new
  526. ;;; accessor methods are added.
  527. (defmethod update-instance-for-redefined-class :before
  528. ((pos x-y-position) added deleted plist &key)
  529. ;; Transform the x-y coordinates to polar coordinates
  530. ;; and store into the new slots.
  531. (let ((x (getf plist 'x))
  532. (y (getf plist 'y)))
  533. (setf (position-rho pos) (sqrt (+ (* x x) (* y y)))
  534. (position-theta pos) (atan y x))))
  535. (defclass x-y-position (position)
  536. ((rho :initform 0 :accessor position-rho)
  537. (theta :initform 0 :accessor position-theta)))
  538. ;;; All instances of the old x-y-position class will be updated
  539. ;;; automatically.
  540. ;;; The new representation is given the look and feel of the old one.
  541. (defmethod position-x ((pos x-y-position))
  542. (with-slots (rho theta) pos (* rho (cos theta))))
  543. (defmethod (setf position-x) (new-x (pos x-y-position))
  544. (with-slots (rho theta) pos
  545. (let ((y (position-y pos)))
  546. (setq rho (sqrt (+ (* new-x new-x) (* y y)))
  547. theta (atan y new-x))
  548. new-x)))
  549. (defmethod position-y ((pos x-y-position))
  550. (with-slots (rho theta) pos (* rho (sin theta))))
  551. (defmethod (setf position-y) (new-y (pos x-y-position))
  552. (with-slots (rho theta) pos
  553. (let ((x (position-x pos)))
  554. (setq rho (sqrt (+ (* x x) (* new-y new-y)))
  555. theta (atan new-y x))
  556. new-y)))
  557. \endcode
  558. \label Affected By:\None.
  559. \label Exceptional Situations::
  560. The system-supplied primary \term{method} on
  561. \funref{update-instance-for-redefined-class} signals an error if an
  562. \param{initarg} is supplied that is not declared as valid.
  563. \label See Also::
  564. \funref{make-instances-obsolete},
  565. \funref{shared-initialize},
  566. {\secref\ClassReDef},
  567. {\secref\InitargRules},
  568. {\secref\DeclaringInitargValidity}
  569. \label Notes::
  570. \param{Initargs} are declared as valid by using the \kwd{initarg}
  571. option to \macref{defclass}, or by defining \term{methods} for
  572. \funref{update-instance-for-redefined-class} or \funref{shared-initialize}.
  573. The keyword name of each keyword parameter specifier in the \term{lambda list} of
  574. any \term{method} defined on
  575. \funref{update-instance-for-redefined-class} or
  576. \funref{shared-initialize} is declared as a valid \param{initarg} name
  577. for all \term{classes} for which that \term{method} is applicable.
  578. \endcom
  579. %%% ========== CHANGE-CLASS
  580. \begincom{change-class}\ftype{Standard Generic Function}
  581. \label Syntax::
  582. \issue{CHANGE-CLASS-INITARGS:PERMIT}
  583. \DefgenWithValues change-class
  584. {instance new-class {\key} {\allowotherkeys}}
  585. {instance}
  586. \endissue{CHANGE-CLASS-INITARGS:PERMIT}
  587. \label Method Signatures::
  588. \issue{CHANGE-CLASS-INITARGS:PERMIT}
  589. \Defmeth {change-class} {\specparam{instance}{standard-object}
  590. \specparam{new-class}{standard-class}
  591. {\rest} initargs}
  592. \Defmeth {change-class} {\specparam{instance}{t}
  593. \specparam{new-class}{symbol}
  594. {\rest} initargs}
  595. \endissue{CHANGE-CLASS-INITARGS:PERMIT}
  596. \label Arguments and Values::
  597. \param{instance}---an \term{object}.
  598. \param{new-class}---a \term{class designator}.
  599. \issue{CHANGE-CLASS-INITARGS:PERMIT}
  600. \param{initargs}---an \term{initialization argument list}.
  601. \endissue{CHANGE-CLASS-INITARGS:PERMIT}
  602. \label Description::
  603. The \term{generic function} \funref{change-class} changes the
  604. \term{class} of an \param{instance} to \param{new-class}.
  605. It destructively modifies and returns the \param{instance}.
  606. If in the old \term{class} there is any \term{slot} of the
  607. same name as a local \term{slot} in the \param{new-class},
  608. the value of that \term{slot} is retained. This means that if
  609. the \term{slot} has a value, the value returned by \funref{slot-value}
  610. after \funref{change-class} is invoked is \funref{eql} to the
  611. value returned by \funref{slot-value} before \funref{change-class} is
  612. invoked. Similarly, if the \term{slot} was unbound, it remains
  613. unbound. The other \term{slots} are initialized as described in
  614. \secref\ChangingInstanceClass.
  615. After completing all other actions, \funref{change-class} invokes
  616. \funref{update-instance-for-different-class}. The
  617. generic function \funref{update-instance-for-different-class} can be used
  618. to assign values to slots in the transformed instance.
  619. \issue{CHANGE-CLASS-INITARGS:PERMIT}
  620. \Seesection\InitNewLocalSlots.
  621. \endissue{CHANGE-CLASS-INITARGS:PERMIT}
  622. \issue{CHANGE-CLASS-INITARGS:PERMIT}
  623. If the second of the above \term{methods} is selected,
  624. that \term{method} invokes \funref{change-class}
  625. on \param{instance}, \f{(find-class \param{new-class})},
  626. and the \param{initargs}.
  627. \endissue{CHANGE-CLASS-INITARGS:PERMIT}
  628. \label Examples::
  629. \code
  630. (defclass position () ())
  631. (defclass x-y-position (position)
  632. ((x :initform 0 :initarg :x)
  633. (y :initform 0 :initarg :y)))
  634. (defclass rho-theta-position (position)
  635. ((rho :initform 0)
  636. (theta :initform 0)))
  637. (defmethod update-instance-for-different-class :before ((old x-y-position)
  638. (new rho-theta-position)
  639. &key)
  640. ;; Copy the position information from old to new to make new
  641. ;; be a rho-theta-position at the same position as old.
  642. (let ((x (slot-value old 'x))
  643. (y (slot-value old 'y)))
  644. (setf (slot-value new 'rho) (sqrt (+ (* x x) (* y y)))
  645. (slot-value new 'theta) (atan y x))))
  646. ;;; At this point an instance of the class x-y-position can be
  647. ;;; changed to be an instance of the class rho-theta-position using
  648. ;;; change-class:
  649. (setq p1 (make-instance 'x-y-position :x 2 :y 0))
  650. (change-class p1 'rho-theta-position)
  651. ;;; The result is that the instance bound to p1 is now an instance of
  652. ;;; the class rho-theta-position. The update-instance-for-different-class
  653. ;;; method performed the initialization of the rho and theta slots based
  654. ;;; on the value of the x and y slots, which were maintained by
  655. ;;; the old instance.
  656. \endcode
  657. \label Examples:\None.
  658. \label Affected By:\None.
  659. \label Exceptional Situations:\None.
  660. \label See Also::
  661. \funref{update-instance-for-different-class},
  662. {\secref\ChangingInstanceClass}
  663. \label Notes::
  664. The generic function \funref{change-class} has several semantic
  665. difficulties. First, it performs a destructive operation that can be
  666. invoked within a \term{method} on an \term{instance} that was used to select that
  667. \term{method}.
  668. When multiple \term{methods} are involved because \term{methods} are being
  669. combined, the \term{methods} currently executing or about to be executed may
  670. no longer be applicable. Second, some implementations might use
  671. compiler optimizations of slot \term{access}, and when the \term{class} of an
  672. \term{instance} is changed the assumptions the compiler made might be
  673. violated. This implies that a programmer must not use
  674. \funref{change-class} inside a \term{method} if any
  675. \term{methods} for that \term{generic function}
  676. \term{access} any \term{slots}, or the results are undefined.
  677. \endcom
  678. %%% ========== SLOT-BOUNDP
  679. \begincom{slot-boundp}\ftype{Function}
  680. %!!! Barmar: 88-002R says this is generic. I should check on this. -kmp 27-Aug-91
  681. \label Syntax::
  682. \DefunWithValues slot-boundp {instance slot-name} {generalized-boolean}
  683. \label Arguments and Values::
  684. \param{instance}---an \term{object}.
  685. \param{slot-name}---a \term{symbol} naming a \term{slot} of \param{instance}.
  686. \param{generalized-boolean}---a \term{generalized boolean}.
  687. \label Description::
  688. Returns \term{true} if the \term{slot} named \param{slot-name} in \param{instance} is bound;
  689. otherwise, returns \term{false}.
  690. \label Examples:\None.
  691. \label Affected By:\None.
  692. \label Exceptional Situations::
  693. If no \term{slot} of the \term{name} \param{slot-name} exists in the
  694. \param{instance}, \funref{slot-missing} is called as follows:
  695. \code
  696. (slot-missing (class-of \i{instance})
  697. \i{instance}
  698. \i{slot-name}
  699. 'slot-boundp)
  700. \endcode
  701. \issue{SLOT-MISSING-VALUES:SPECIFY}
  702. (If \funref{slot-missing} is invoked and returns a value,
  703. a \term{boolean equivalent} to its \term{primary value}
  704. is returned by \funref{slot-boundp}.)
  705. \endissue{SLOT-MISSING-VALUES:SPECIFY}
  706. \issue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  707. The specific behavior depends on \param{instance}'s \term{metaclass}.
  708. An error is never signaled if \param{instance} has \term{metaclass} \typeref{standard-class}.
  709. An error is always signaled if \param{instance} has \term{metaclass} \typeref{built-in-class}.
  710. The consequences are undefined if \param{instance} has any other \term{metaclass}--an error
  711. might or might not be signaled in this situation. Note in particular that the behavior
  712. for \term{conditions} and \term{structures} is not specified.
  713. \endissue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  714. \label See Also::
  715. \funref{slot-makunbound},
  716. \funref{slot-missing}
  717. \label Notes::
  718. \Thefunction{slot-boundp} allows for writing
  719. \term{after methods} on \funref{initialize-instance} in order to initialize only
  720. those \term{slots} that have not already been bound.
  721. \MentionMetaObjects{slot-boundp}{slot-boundp-using-class}
  722. \endcom
  723. %%% ========== SLOT-EXISTS-P
  724. \begincom{slot-exists-p}\ftype{Function}
  725. %!!! Barmar: 88-002R says this is generic. I should check on this. -kmp 27-Aug-91
  726. \label Syntax::
  727. \DefunWithValues {slot-exists-p} {object slot-name} {generalized-boolean}
  728. \label Arguments and Values::
  729. \issue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  730. \param{object}---an \term{object}.
  731. \endissue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  732. \param{slot-name}---a \term{symbol}.
  733. \param{generalized-boolean}---a \term{generalized boolean}.
  734. \label Description::
  735. % \Thefunction{slot-exists-p} tests whether the \param{object} has
  736. % a \term{slot} of the given \term{name}.
  737. Returns \term{true} if the \param{object} has
  738. a \term{slot} named \param{slot-name}.
  739. \label Examples:\None.
  740. \label Affected By::
  741. \macref{defclass},
  742. \macref{defstruct}
  743. \label Exceptional Situations:\None.
  744. \label See Also::
  745. \macref{defclass},
  746. \funref{slot-missing}
  747. \label Notes::
  748. \MentionMetaObjects{slot-exists-p}{slot-exists-p-using-class}
  749. \endcom
  750. %%% ========== SLOT-MAKUNBOUND
  751. \begincom{slot-makunbound}\ftype{Function}
  752. %!!! Barmar: 88-002R says this is generic. I should check on this. -kmp 27-Aug-91
  753. \label Syntax::
  754. \DefunWithValues {slot-makunbound} {instance slot-name} {instance}
  755. \label Arguments and Values::
  756. \param{instance} -- instance.
  757. \param{Slot-name}---a \term{symbol}.
  758. \label Description::
  759. \Thefunction{slot-makunbound} restores a \term{slot}
  760. of the name \param{slot-name} in an \param{instance} to
  761. the unbound state.
  762. \label Examples:\None.
  763. \label Affected By:\None.
  764. \label Exceptional Situations::
  765. If no \term{slot} of the name \param{slot-name} exists in the
  766. \param{instance}, \funref{slot-missing} is called as follows:
  767. \code
  768. (slot-missing (class-of \i{instance})
  769. \i{instance}
  770. \i{slot-name}
  771. 'slot-makunbound)
  772. \endcode
  773. \issue{SLOT-MISSING-VALUES:SPECIFY}
  774. (Any values returned by \funref{slot-missing} in this case are
  775. ignored by \funref{slot-makunbound}.)
  776. \endissue{SLOT-MISSING-VALUES:SPECIFY}
  777. \issue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  778. The specific behavior depends on \param{instance}'s \term{metaclass}.
  779. An error is never signaled if \param{instance} has \term{metaclass} \typeref{standard-class}.
  780. An error is always signaled if \param{instance} has \term{metaclass} \typeref{built-in-class}.
  781. The consequences are undefined if \param{instance} has any other \term{metaclass}--an error
  782. might or might not be signaled in this situation. Note in particular that the behavior
  783. for \term{conditions} and \term{structures} is not specified.
  784. \endissue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  785. \label See Also::
  786. \funref{slot-boundp},
  787. \funref{slot-missing}
  788. \label Notes::
  789. \MentionMetaObjects{slot-makunbound}{slot-makunbound-using-class}
  790. \endcom
  791. %%% ========== SLOT-MISSING
  792. \begincom{slot-missing}\ftype{Standard Generic Function}
  793. \label Syntax::
  794. \DefgenWithValues slot-missing
  795. {class object slot-name operation {\opt} new-value}
  796. {\starparam{result}}
  797. \label Method Signatures::
  798. \Defmeth slot-missing {\vtop{\hbox{\specparam{class}{t}
  799. object slot-name}
  800. \hbox{operation {\opt} new-value}}}
  801. \label Arguments and Values::
  802. \param{class}---the \term{class} of \param{object}.
  803. \param{object}---an \term{object}.
  804. \param{slot-name}---a \term{symbol} (the \term{name} of a would-be \term{slot}).
  805. \param{operation}---one of the \term{symbols}
  806. \funref{setf},
  807. \funref{slot-boundp},
  808. \funref{slot-makunbound},
  809. or \funref{slot-value}.
  810. \param{new-value}---an \term{object}.
  811. \param{result}---an \term{object}.
  812. \label Description::
  813. The generic function \funref{slot-missing} is invoked when an attempt is
  814. made to \term{access} a \term{slot} in an \param{object} whose
  815. \term{metaclass} is \typeref{standard-class}
  816. and the \term{slot} of the name \param{slot-name}
  817. is not a \term{name} of a
  818. \term{slot} in that \term{class}.
  819. The default \term{method} signals an error.
  820. The generic function \funref{slot-missing} is not intended to be called by
  821. programmers. Programmers may write \term{methods} for it.
  822. The generic function \funref{slot-missing} may be called during
  823. evaluation of \funref{slot-value}, \f{(setf slot-value)},
  824. \funref{slot-boundp}, and \funref{slot-makunbound}. For each
  825. of these operations the corresponding \term{symbol}
  826. for the \param{operation}
  827. argument is \misc{slot-value}, \misc{setf}, \misc{slot-boundp},
  828. and \misc{slot-makunbound} respectively.
  829. The optional \param{new-value} argument to \funref{slot-missing} is used
  830. when the operation is attempting to set the value of the \term{slot}.
  831. \issue{SLOT-MISSING-VALUES:SPECIFY}
  832. If \funref{slot-missing} returns, its values will be treated as follows:
  833. \beginlist
  834. \item{\bull}
  835. If the \param{operation} is \misc{setf} or \misc{slot-makunbound},
  836. any \term{values} will be ignored by the caller.
  837. \item{\bull}
  838. If the \param{operation} is \misc{slot-value},
  839. only the \term{primary value} will be used by the caller,
  840. and all other values will be ignored.
  841. \item{\bull}
  842. If the \param{operation} is \misc{slot-boundp},
  843. any \term{boolean equivalent} of the \term{primary value}
  844. of the \term{method} might be is used,
  845. and all other values will be ignored.
  846. \endlist
  847. \endissue{SLOT-MISSING-VALUES:SPECIFY}
  848. \label Examples:\None.
  849. \label Affected By:\None.
  850. \label Exceptional Situations::
  851. The default \term{method} on \funref{slot-missing}
  852. signals an error \oftype{error}.
  853. \label See Also::
  854. \macref{defclass},
  855. \funref{slot-exists-p},
  856. \funref{slot-value}
  857. \label Notes::
  858. The set of arguments (including the \term{class} of the instance) facilitates
  859. defining methods on the metaclass for \funref{slot-missing}.
  860. \endcom
  861. %%% ========== SLOT-UNBOUND
  862. \begincom{slot-unbound}\ftype{Standard Generic Function}
  863. \label Syntax::
  864. \DefgenWithValues {slot-unbound} {class instance slot-name} {\starparam{result}}
  865. \label Method Signatures::
  866. \Defmeth slot-unbound {\specparam{class}{t}
  867. instance slot-name}
  868. \label Arguments and Values::
  869. \param{class}---the \term{class} of the \param{instance}.
  870. \param{instance}---the \param{instance} in which an attempt
  871. was made to \term{read} the \term{unbound} \term{slot}.
  872. \param{slot-name}---the \term{name} of the \term{unbound} \term{slot}.
  873. \param{result}---an \term{object}.
  874. \label Description::
  875. The generic function \funref{slot-unbound} is called when an
  876. unbound \term{slot} is read in
  877. an \param{instance} whose metaclass is \typeref{standard-class}.
  878. The default \term{method} signals an error
  879. \issue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  880. \oftype{unbound-slot}.
  881. The name slot of the
  882. \typeref{unbound-slot} \term{condition} is initialized
  883. to the name of the offending variable, and the instance slot
  884. of the \typeref{unbound-slot} \term{condition} is initialized to the offending instance.
  885. \endissue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  886. The generic function \funref{slot-unbound} is not intended to be called
  887. by programmers. Programmers may write \term{methods} for it.
  888. \Thefunction{slot-unbound} is called only
  889. %%Looks like metaobjects to me. -kmp 15-Jan-91
  890. %by \thefunction{slot-value-using-class} and thus
  891. indirectly by \funref{slot-value}.
  892. \issue{SLOT-MISSING-VALUES:SPECIFY}
  893. %% Per X3J13. -kmp 05-Oct-93
  894. % If \funref{slot-unbound} returns, its values will be treated as follows:
  895. %
  896. % \beginlist
  897. % \item{\bull}
  898. % If the \param{operation} is \misc{setf} or \misc{slot-makunbound},
  899. % any \term{values} will be ignored by the caller.
  900. %
  901. % \item{\bull}
  902. % If the \param{operation} is \misc{slot-value},
  903. % only the \term{primary value} will be used by the caller,
  904. % and all other values will be ignored.
  905. %
  906. % \item{\bull}
  907. % If the \param{operation} is \misc{slot-boundp},
  908. % any \term{boolean equivalent} of the \term{primary value}
  909. % of the \term{method} might be is used,
  910. % and all other values will be ignored.
  911. % \endlist
  912. If \funref{slot-unbound} returns,
  913. only the \term{primary value} will be used by the caller,
  914. and all other values will be ignored.
  915. \endissue{SLOT-MISSING-VALUES:SPECIFY}
  916. \label Examples:\None.
  917. \label Affected By:\None.
  918. \label Exceptional Situations::
  919. \issue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  920. The default \term{method} on \funref{slot-unbound}
  921. signals an error \oftype{unbound-slot}.
  922. \endissue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  923. \label See Also::
  924. \funref{slot-makunbound}
  925. \label Notes::
  926. An unbound \term{slot} may occur if no \kwd{initform} form was
  927. specified for the \term{slot} and the \term{slot} value has not been set,
  928. or if \funref{slot-makunbound} has been called on the \term{slot}.
  929. \endcom
  930. %%% ========== SLOT-VALUE
  931. \begincom{slot-value}\ftype{Function}
  932. \label Syntax::
  933. \DefunWithValues {slot-value} {object slot-name} {value}
  934. \label Arguments and Values::
  935. \param{object}---an \term{object}.
  936. \param{name}---a \term{symbol}.
  937. \param{value}---an \term{object}.
  938. \label Description::
  939. \Thefunction{slot-value} returns the \term{value} of the \term{slot}
  940. named \param{slot-name} in the \param{object}.
  941. If there is no \term{slot} named \param{slot-name}, \funref{slot-missing} is called.
  942. If the \term{slot} is unbound, \funref{slot-unbound} is called.
  943. %!!! Reflect this in the Syntax above? Or is (SETF SLOT-VALUE) described somewhere?
  944. The macro \macref{setf} can be used with \funref{slot-value}
  945. to change the value of a \term{slot}.
  946. \label Examples::
  947. \code
  948. (defclass foo ()
  949. ((a :accessor foo-a :initarg :a :initform 1)
  950. (b :accessor foo-b :initarg :b)
  951. (c :accessor foo-c :initform 3)))
  952. \EV #<STANDARD-CLASS FOO 244020371>
  953. (setq foo1 (make-instance 'foo :a 'one :b 'two))
  954. \EV #<FOO 36325624>
  955. (slot-value foo1 'a) \EV ONE
  956. (slot-value foo1 'b) \EV TWO
  957. (slot-value foo1 'c) \EV 3
  958. (setf (slot-value foo1 'a) 'uno) \EV UNO
  959. (slot-value foo1 'a) \EV UNO
  960. (defmethod foo-method ((x foo))
  961. (slot-value x 'a))
  962. \EV #<STANDARD-METHOD FOO-METHOD (FOO) 42720573>
  963. (foo-method foo1) \EV UNO
  964. \endcode
  965. \label Affected By:\None.
  966. \label Exceptional Situations::
  967. If an attempt is made to read a \term{slot} and no \term{slot} of
  968. the name \param{slot-name} exists in the \param{object},
  969. \funref{slot-missing} is called as follows:
  970. \code
  971. (slot-missing (class-of \i{instance})
  972. \i{instance}
  973. \i{slot-name}
  974. 'slot-value)
  975. \endcode
  976. \issue{SLOT-MISSING-VALUES:SPECIFY}
  977. (If \funref{slot-missing} is invoked, its \term{primary value}
  978. is returned by \funref{slot-value}.)
  979. \endissue{SLOT-MISSING-VALUES:SPECIFY}
  980. If an attempt is made to write a \term{slot} and no \term{slot} of
  981. the name \param{slot-name} exists in the \param{object},
  982. \funref{slot-missing} is called as follows:
  983. \code
  984. (slot-missing (class-of \i{instance})
  985. \i{instance}
  986. \i{slot-name}
  987. 'setf
  988. \i{new-value})
  989. \endcode
  990. \issue{SLOT-MISSING-VALUES:SPECIFY}
  991. (If \funref{slot-missing} returns in this case, any \term{values} are ignored.)
  992. \endissue{SLOT-MISSING-VALUES:SPECIFY}
  993. \issue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  994. The specific behavior depends on \param{object}'s \term{metaclass}.
  995. An error is never signaled if \param{object} has \term{metaclass} \typeref{standard-class}.
  996. An error is always signaled if \param{object} has \term{metaclass} \typeref{built-in-class}.
  997. The consequences are
  998. %% Per X3J13. -kmp 05-Oct-93
  999. %undefined
  1000. unspecified
  1001. if \param{object} has any other \term{metaclass}--an error
  1002. might or might not be signaled in this situation. Note in particular that the behavior
  1003. for \term{conditions} and \term{structures} is not specified.
  1004. \endissue{SLOT-VALUE-METACLASSES:LESS-MINIMAL}
  1005. \label See Also::
  1006. \funref{slot-missing},
  1007. \funref{slot-unbound},
  1008. \macref{with-slots}
  1009. \label Notes::
  1010. \MentionMetaObjects{slot-value}{slot-value-using-class}
  1011. Implementations may optimize \funref{slot-value} by compiling it inline.
  1012. \endcom
  1013. %%% ========== METHOD-QUALIFIERS
  1014. \begincom{method-qualifiers}\ftype{Standard Generic Function}
  1015. \label Syntax::
  1016. \DefgenWithValues method-qualifiers {method} {qualifiers}
  1017. \label Method Signatures::
  1018. \Defmeth method-qualifiers {\specparam{method}{standard-method}}
  1019. \label Arguments and Values::
  1020. \param{method}---a \term{method}.
  1021. \param{qualifiers}---a \term{proper list}.
  1022. \label Description::
  1023. Returns a \term{list} of the \term{qualifiers} of the \param{method}.
  1024. \label Examples::
  1025. \code
  1026. (defmethod some-gf :before ((a integer)) a)
  1027. \EV #<STANDARD-METHOD SOME-GF (:BEFORE) (INTEGER) 42736540>
  1028. (method-qualifiers *) \EV (:BEFORE)
  1029. \endcode
  1030. \label Affected By:\None.
  1031. \label Exceptional Situations:\None.
  1032. \label See Also::
  1033. \macref{define-method-combination}
  1034. \label Notes:\None.
  1035. \endcom
  1036. %%% ========== NO-APPLICABLE-METHOD
  1037. \begincom{no-applicable-method}\ftype{Standard Generic Function}
  1038. \label Syntax::
  1039. \DefgenWithValues no-applicable-method
  1040. {generic-function {\rest} function-arguments}
  1041. {\starparam{result}}
  1042. \label Method Signatures::
  1043. \Defmeth no-applicable-method {\vtop{\hbox{\specparam{generic-function}{t}}
  1044. \hbox{{\rest} function-arguments}}}
  1045. \label Arguments and Values::
  1046. %!!! But the signature above says T, not STANDARD-GENERIC-FUNCTION ...? -kmp 9-May-91
  1047. \param{generic-function}---a \term{generic function}
  1048. %% Per X3J13. -kmp 05-Oct-93
  1049. % of the class \typeref{standard-generic-function}
  1050. on which no \term{applicable method} was found.
  1051. \param{function-arguments}---\term{arguments} to the \param{generic-function}.
  1052. \param{result}---an \term{object}.
  1053. \label Description::
  1054. The generic function \funref{no-applicable-method} is called when a
  1055. \term{generic function}
  1056. %% Per X3J13. -kmp 05-Oct-93
  1057. %of \theclass{standard-generic-function}
  1058. is invoked
  1059. and no \term{method} on that \term{generic function} is applicable.
  1060. % "default \term{method}" => "\term{default method}" per X3J13. -kmp 05-Oct-93
  1061. The \term{default method} signals an error.
  1062. The generic function \funref{no-applicable-method} is not intended
  1063. to be called by programmers. Programmers may write \term{methods} for it.
  1064. \label Examples:\None.
  1065. \label Affected By:\None.
  1066. \label Exceptional Situations::
  1067. The default \term{method} signals an error \oftype{error}.
  1068. \label See Also::
  1069. \label Notes:\None.
  1070. \endcom
  1071. %%% ========== NO-NEXT-METHOD
  1072. \begincom{no-next-method}\ftype{Standard Generic Function}
  1073. \label Syntax::
  1074. \DefgenWithValues no-next-method
  1075. {generic-function method {\rest} args}
  1076. {\starparam{result}}
  1077. \label Method Signatures::
  1078. \Defmeth no-next-method {\vtop{\hbox{\specparam{generic-function}{standard-generic-function}}
  1079. \hbox{\specparam{method}{standard-method}}
  1080. \hbox{{\rest} args}}}
  1081. \label Arguments and Values::
  1082. \param{generic-function} -- \term{generic function} to which \param{method} belongs.
  1083. \param{method} -- \term{method} that contained the call to
  1084. \funref{call-next-method} for which there is no next \term{method}.
  1085. \param{args} -- arguments to \funref{call-next-method}.
  1086. \param{result}---an \term{object}.
  1087. \label Description::
  1088. \TheGF{no-next-method} is called by \funref{call-next-method}
  1089. when there is no \term{next method}.
  1090. \TheGF{no-next-method} is not intended to be called by programmers.
  1091. Programmers may write \term{methods} for it.
  1092. \label Examples:\None.
  1093. \label Affected By:\None.
  1094. \label Exceptional Situations::
  1095. The system-supplied \term{method} on \funref{no-next-method}
  1096. signals an error \oftype{error}. \editornote{KMP: perhaps control-error??}
  1097. \label See Also::
  1098. \funref{call-next-method}
  1099. \label Notes:\None.
  1100. \endcom
  1101. %%% ========== REMOVE-METHOD
  1102. \begincom{remove-method}\ftype{Standard Generic Function}
  1103. \label Syntax::
  1104. \DefgenWithValues remove-method {generic-function method} {generic-function}
  1105. \label Method Signatures::
  1106. \Defmeth remove-method {\vtop{\hbox{\specparam{generic-function}{standard-generic-function}}
  1107. \hbox{method}}}
  1108. \label Arguments and Values::
  1109. \param{generic-function}---a \term{generic function}.
  1110. \param{method}---a \term{method}.
  1111. \label Description::
  1112. \TheGF{remove-method} removes a \term{method} from \param{generic-function}
  1113. by modifying the \param{generic-function} (if necessary).
  1114. \funref{remove-method} must not signal an error if the \term{method}
  1115. is not one of the \term{methods} on the \param{generic-function}.
  1116. \label Examples:\None.
  1117. \label Affected By:\None.
  1118. \label Exceptional Situations:\None.
  1119. \label See Also::
  1120. \funref{find-method}
  1121. \label Notes:\None.
  1122. \endcom
  1123. \issue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  1124. % %%% ========== GENERIC-FLET
  1125. % %%% ========== GENERIC-LABELS
  1126. %
  1127. % \begincom{generic-flet, generic-labels}\ftype{Special Operator}
  1128. %
  1129. % \label Syntax::
  1130. %
  1131. % \DefspecWithValuesNewline generic-flet
  1132. % {\vtop{\hbox{\paren{\starparen{function-name
  1133. % lambda-list
  1134. % \interleave{\down{option} |
  1135. % \stardown{method-description}}}}}
  1136. % \hbox{\starparam{form}}}}
  1137. % {\starparam{result}}
  1138. %
  1139. % \DefspecWithValuesNewline generic-labels
  1140. % {\vtop{\hbox{\paren{\starparen{function-name
  1141. % lambda-list
  1142. % \interleave{\down{option} |
  1143. % \stardown{method-description}}}}}
  1144. % \hbox{\starparam{form}}}}
  1145. % {\starparam{result}}
  1146. %
  1147. % {\GFauxOptionsAndMethDesc}
  1148. %
  1149. % \label Arguments and Values::
  1150. %
  1151. % \editornote{KMP: Treatment of documentation?}%!!!
  1152. %
  1153. % \param{function-name}, \param{lambda-list}, \param{option}, \param{method-qualifier},
  1154. % \param{specialized-lambda-list}---the same as for \macref{defgeneric}.
  1155. %
  1156. % \param{method-definition}---the same as for \macref{defmethod}.
  1157. %
  1158. % \param{forms}---an \term{implicit progn}.
  1159. %
  1160. % \param{results}---the \term{values} returned by the \param{forms}.
  1161. %
  1162. % \label Description::
  1163. %
  1164. % \Thespecop{generic-flet} is analogous to \thespecop{flet}, and
  1165. % \thespecop{generic-labels} is analogous to \thespecop{labels}.
  1166. %
  1167. % The \term{forms} are \term{evaluated} in a \term{lexical environment}
  1168. % in which \term{function} \term{bindings} for the \param{function-names} have
  1169. % been \term{established}.
  1170. % The \term{value} of each \term{binding} is a \term{fresh} \term{generic function},
  1171. % with \term{methods} as specified by the corresponding \param{method-description}.
  1172. % The \term{bindings} of the \term{function-names} have \term{lexical scope},
  1173. % and the \term{generic functions} (and their \term{methods}) have \term{indefinite extent}.
  1174. %
  1175. % For \specref{generic-flet},
  1176. % the \term{scope} of the \term{bindings} for the \param{function-names}
  1177. % includes only the \param{forms},
  1178. % not the bodies of the local definitions of the \term{methods}.
  1179. % Within the method bodies, references to any of the \param{function-names}
  1180. % refer to global \term{functions} with coincidentally similar names,
  1181. % not to the \term{generic functions} established for use by the \param{forms}.
  1182. % It is thus not possible to define recursive \term{functions}
  1183. % with \specref{generic-flet}.
  1184. %
  1185. % For \specref{generic-labels},
  1186. % the \term{scope} of the \term{bindings} for the \param{function-names}
  1187. % includes the entire \specref{generic-labels} \term{form},
  1188. % including not only the \param{forms},
  1189. % but also the bodies of the local definitions of the \term{methods}.
  1190. % It is thus possible to define recursive \term{functions}
  1191. % with \specref{generic-labels}.
  1192. %
  1193. % The body of each \term{method} is enclosed in an \term{implicit block}.
  1194. % If \param{function-name} is a \term{symbol},
  1195. % the \term{implicit block} has that \term{name}.
  1196. % If \param{function-name} is a \term{list} of the form \f{(setf \param{sym})},
  1197. % the \term{name} of the \term{implicit block} is \param{sym}.
  1198. %
  1199. % \label Examples:\None.
  1200. %
  1201. % \label Affected By:\None.
  1202. %
  1203. % \label Exceptional Situations:\None.
  1204. %
  1205. % \label See Also::
  1206. %
  1207. % \specref{flet},
  1208. % \specref{labels},
  1209. % \macref{defmethod},
  1210. % \macref{defgeneric},
  1211. % \macref{generic-function}
  1212. %
  1213. % \label Notes:\None.
  1214. %
  1215. % \endcom
  1216. %
  1217. %
  1218. % %%% ========== GENERIC-FUNCTION
  1219. % \begincom{generic-function}\ftype{Macro}
  1220. %
  1221. % \label Syntax::
  1222. %
  1223. % \DefmacWithValues generic-function
  1224. % {lambda-list \interleave{\down{option} | \starparam{method-description}}}
  1225. % {generic-function}
  1226. %
  1227. % {\GFauxOptionsAndMethDesc}
  1228. %
  1229. % \label Arguments and Values::
  1230. %
  1231. % \editornote{KMP: Treatment of documentation?}%!!!
  1232. %
  1233. % \param{Option}, \param{method-qualifier},
  1234. % and \param{specialized-lambda-list} are the same as for
  1235. % \macref{defgeneric}.
  1236. %
  1237. % \param{generic-function}---a \term{generic function} \term{object}.
  1238. %
  1239. % \label Description::
  1240. %
  1241. % Creates an \term{anonymous} \term{generic function} with the
  1242. % set of \term{methods} specified by its \param{method-descriptions}.
  1243. %
  1244. % %%I don't think this is really needed. -kmp 15-Jan-91
  1245. % % If no \param{method-descriptions} are supplied,
  1246. % % an \term{anonymous} \term{generic function} with no \term{methods} is created.
  1247. %
  1248. % \label Examples:\None.
  1249. %
  1250. % \label Affected By:\None.
  1251. %
  1252. % \label Exceptional Situations:\None.
  1253. %
  1254. % \label See Also::
  1255. %
  1256. % \macref{defgeneric},
  1257. % \specref{generic-flet},
  1258. % \specref{generic-labels},
  1259. % \macref{defmethod}
  1260. %
  1261. % \label Notes:\None.
  1262. %
  1263. % \endcom
  1264. \endissue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  1265. %%% ========== MAKE-INSTANCE
  1266. \begincom{make-instance}\ftype{Standard Generic Function}
  1267. \label Syntax::
  1268. \issue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  1269. \DefgenWithValues make-instance
  1270. {class {\rest} initargs {\key} {\allowotherkeys}}
  1271. {instance}
  1272. \endissue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  1273. \label Method Signatures::
  1274. \Defmeth make-instance {\specparam{class}{standard-class} {\rest} initargs}
  1275. \Defmeth make-instance {\specparam{class}{symbol} {\rest} initargs}
  1276. \label Arguments and Values::
  1277. %!!! I'd rather this were called class-name. -kmp 15-Jan-91
  1278. %!!! Or maybe class designator? -kmp 18-Feb-91
  1279. \param{class}---a \term{class},
  1280. or a \term{symbol} that names a \term{class}.
  1281. \param{initargs}---an \term{initialization argument list}.
  1282. \param{instance}---a \term{fresh} \term{instance} of \term{class} \param{class}.
  1283. \label Description::
  1284. The \term{generic function} \funref{make-instance}
  1285. creates and returns a new \term{instance} of the given \param{class}.
  1286. If the second of the above \term{methods} is selected,
  1287. that \term{method} invokes \funref{make-instance} on the arguments
  1288. \f{(find-class \param{class})} and \param{initargs}.
  1289. The initialization arguments are checked within \funref{make-instance}.
  1290. The \term{generic function} \funref{make-instance}
  1291. may be used as described in \secref\ObjectCreationAndInit.
  1292. \label Affected By:\None.
  1293. \label Exceptional Situations::
  1294. If any of the initialization arguments has not
  1295. been declared as valid, an error \oftype{error} is signaled.
  1296. \label See Also::
  1297. \macref{defclass},
  1298. \funref{class-of},
  1299. \funref{allocate-instance},
  1300. \funref{initialize-instance},
  1301. {\secref\ObjectCreationAndInit}
  1302. %% Per X3J13. -kmp 05-Oct-93
  1303. \label Notes:\None.
  1304. %The meta-object protocol can be used to define new methods on
  1305. %\funref{make-instance} to replace the object-creation protocol.
  1306. \endcom
  1307. %%% ========== MAKE-INSTANCES-OBSOLETE
  1308. \begincom{make-instances-obsolete}\ftype{Standard Generic Function}
  1309. \label Syntax::
  1310. \DefgenWithValues make-instances-obsolete {class} {class}
  1311. \label Method Signatures::
  1312. \Defmeth make-instances-obsolete {\specparam{class}{standard-class}}
  1313. \Defmeth make-instances-obsolete {\specparam{class}{symbol}}
  1314. \label Arguments and Values::
  1315. \param{class}---a \term{class designator}.
  1316. \label Description::
  1317. \Thefunction{make-instances-obsolete} has the effect of
  1318. initiating the process of updating the instances of the
  1319. \term{class}. During updating, the generic function
  1320. \funref{update-instance-for-redefined-class} will be invoked.
  1321. The generic function \funref{make-instances-obsolete} is invoked
  1322. automatically by the system when \macref{defclass} has been used to
  1323. redefine an existing standard class and the set of local
  1324. \term{slots} \term{accessible} in an
  1325. instance is changed or the order of \term{slots} in storage is changed. It
  1326. can also be explicitly invoked by the user.
  1327. If the second of the above \term{methods} is selected, that
  1328. \term{method} invokes
  1329. \funref{make-instances-obsolete} on \f{(find-class \param{class})}.
  1330. \label Examples::
  1331. \label Affected By:\None.
  1332. \label Exceptional Situations:\None.
  1333. \label See Also::
  1334. \funref{update-instance-for-redefined-class},
  1335. {\secref\ClassReDef}
  1336. \label Notes:\None.
  1337. \endcom
  1338. %%% ========== MAKE-LOAD-FORM
  1339. \begincom{make-load-form}\ftype{Standard Generic Function}
  1340. \issue{MAKE-LOAD-FORM-CONFUSION:REWRITE}
  1341. \issue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  1342. \label Syntax::
  1343. \DefgenWithValues {make-load-form}
  1344. {object {\opt} environment}
  1345. {creation-form\brac{, initialization-form}}
  1346. \label Method Signatures::
  1347. \Defmeth make-load-form {\specparam{object}{standard-object} {\opt} environment}
  1348. \Defmeth make-load-form {\specparam{object}{structure-object} {\opt} environment}
  1349. \Defmeth make-load-form {\specparam{object}{condition} {\opt} environment}
  1350. \Defmeth make-load-form {\specparam{object}{class} {\opt} environment}
  1351. \label Arguments and Values::
  1352. \param{object}---an \term{object}.
  1353. % Barrett: Moved up from end, so arguments first, then values.
  1354. \param{environment}---an \term{environment object}.
  1355. \param{creation-form}---a \term{form}.
  1356. \param{initialization-form}---a \term{form}.
  1357. \label Description::
  1358. \TheGF{make-load-form} creates and returns
  1359. one or two \term{forms},
  1360. a \param{creation-form}
  1361. and an \param{initialization-form},
  1362. that enable \funref{load} to construct an \term{object}
  1363. equivalent to \param{object}.
  1364. %% Added per item 1 of MAKE-LOAD-FORM-CONFUSION:
  1365. \param{Environment} is an \term{environment object}
  1366. corresponding to the \term{lexical environment}
  1367. in which the \term{forms} will be processed.
  1368. % %% Added with rewrites per item 1.1 of MAKE-LOAD-FORM-CONFUSION.
  1369. % %% I had to do some minor fooling with the wording to make it read
  1370. % %% better using `modern' terminology. -kmp 11-Feb-92
  1371. % \funref{make-load-form} is called by the \term{file compiler} when
  1372. % \param{object} is referenced as a \term{literal object}
  1373. % in a \term{file} being compiled
  1374. % %by \funref{compile-file}
  1375. % if the \term{object} is a \term{generalized instance}
  1376. % of \typeref{standard-object}, \typeref{structure-object},
  1377. % \typeref{condition}, or any of a (possibly empty) \term{implementation-dependent}
  1378. % %list
  1379. % set of other \term{classes}.
  1380. % The \term{file compiler} will only call \funref{make-load-form} once for the \term{same}
  1381. % \term{object} within a single \term{file}.
  1382. % Barrett: Commented out the above, instead referencing the appropriate
  1383. % section describing how the compiler performs constant processing.
  1384. The \term{file compiler} calls \funref{make-load-form} to process certain
  1385. \term{classes} of \term{literal objects}; \seesection\CallingMakeLoadForm.
  1386. %% Added per item 1.2 of MAKE-LOAD-FORM-CONFUSION:
  1387. \term{Conforming programs} may call \funref{make-load-form} directly,
  1388. providing \param{object} is a \term{generalized instance} of
  1389. % Barrett: Fix dangling reference, now that list has been moved.
  1390. % one of the
  1391. % explicitly named \term{classes} mentioned previously.
  1392. \typeref{standard-object}, \typeref{structure-object},
  1393. or \typeref{condition}.
  1394. The creation form is a \term{form} that, when evaluated at
  1395. \funref{load} time, should return an \term{object} that
  1396. is equivalent to \param{object}. The exact meaning of
  1397. equivalent depends on the \term{type} of \term{object}
  1398. and is up to the programmer who defines a \term{method} for
  1399. \funref{make-load-form};
  1400. \seesection\LiteralsInCompiledFiles.
  1401. %This is the same type of equivalence discussed
  1402. % in issue CONSTANT-COMPILABLE-TYPES.
  1403. The initialization form is a \term{form} that, when evaluated at \funref{load} time,
  1404. should perform further initialization of the \term{object}.
  1405. The value returned by the initialization form is ignored.
  1406. % Barrett: Flush "method" -- its the value returned by the function that's
  1407. % being talked about.
  1408. %If the \funref{make-load-form} method
  1409. If \funref{make-load-form}
  1410. returns only one value,
  1411. the initialization form is \nil, which has no effect.
  1412. If \param{object} appears as a constant in the initialization form,
  1413. at \funref{load} time it will be replaced by the equivalent \term{object}
  1414. constructed by the creation form;
  1415. this is how the further initialization gains access to the \term{object}.
  1416. % Both the creation and initialization forms can contain references to \term{objects}
  1417. % of user-defined \term{types} (defined precisely below).
  1418. %% Rewritten per item 1.4 of MAKE-LOAD-FORM-CONFUSION:
  1419. Both the \param{creation-form} and the \param{initialization-form} may contain references
  1420. to any \term{externalizable object}.
  1421. However, there must not be any circular dependencies in creation forms.
  1422. An example of a circular dependency is when the creation form for the
  1423. object \f{X} contains a reference to the object \f{Y},
  1424. and the creation form for the object \f{Y} contains a reference to the object \f{X}.
  1425. %A simpler
  1426. % example would be when the creation form for the object X contains
  1427. % a reference to X itself.
  1428. Initialization forms are not subject to any restriction against circular dependencies,
  1429. which is the reason that initialization forms exist;
  1430. see the example of circular data structures below.
  1431. % The creation form for an \term{object} is always evaluated before the
  1432. % initialization form for that \term{object}.
  1433. % When either the creation form or
  1434. % the initialization form references other \term{objects}
  1435. % of user-defined \term{types}
  1436. % that have not been referenced earlier in the
  1437. % \funref{compile-file}, the
  1438. % compiler collects all of the creation and initialization forms. Each
  1439. % initialization form is evaluated as soon as possible after its
  1440. % creation form, as determined by data flow. If the initialization form
  1441. % for an \term{object} does not reference any other
  1442. % \term{objects} of user-defined
  1443. % \term{types}
  1444. % that have not been referenced earlier in the \funref{compile-file}, the
  1445. % initialization form is evaluated immediately after the creation form.
  1446. % If a creation or initialization form \f{F} references other
  1447. % \term{objects} of
  1448. % user-defined \term{types} that have not been referenced earlier in the
  1449. % \funref{compile-file},
  1450. % the creation forms for those other \term{objects} are evaluated
  1451. % before \f{F}, and the initialization forms for those other
  1452. % \term{objects} are
  1453. % also evaluated before \f{F} whenever they do not depend on the
  1454. % \term{object}
  1455. % created or initialized by
  1456. % \f{F}. Where the above rules do not uniquely
  1457. % determine an order of evaluation, which of the possible orders of
  1458. % evaluation is chosen is \term{implementation-dependent}.
  1459. % \idxtext{order of evaluation}\idxtext{evaluation order}
  1460. %% Rewritten per item 1.5 of MAKE-LOAD-FORM-CONFUSION:
  1461. The creation form for an \term{object} is always \term{evaluated} before the
  1462. initialization form for that \term{object}. When either the creation form or
  1463. the initialization form references other \term{objects} that have not been
  1464. referenced earlier in the \term{file} being \term{compiled}, the \term{compiler} ensures
  1465. that all of the referenced \term{objects} have been created before \term{evaluating}
  1466. the referencing \term{form}. When the referenced \term{object} is of a \term{type} which
  1467. %\funref{compile-file}
  1468. the \term{file compiler} processes using \funref{make-load-form},
  1469. this involves \term{evaluating}
  1470. the creation form returned for it. (This is the reason for the
  1471. prohibition against circular references among creation forms).
  1472. Each initialization form is \term{evaluated} as soon as possible after its
  1473. associated creation form, as determined by data flow. If the
  1474. initialization form for an \term{object} does not reference any other \term{objects}
  1475. not referenced earlier in the \term{file} and processed by
  1476. %\funref{compile-file}
  1477. the \term{file compiler}
  1478. using
  1479. \funref{make-load-form}, the initialization form is evaluated immediately after
  1480. the creation form. If a creation or initialization form $F$ does contain
  1481. references to such \term{objects}, the creation forms for those other objects
  1482. are evaluated before $F$, and the initialization forms for those other
  1483. \term{objects} are also evaluated before $F$ whenever they do not depend on the
  1484. \term{object} created or initialized by $F$. Where these rules do not uniquely
  1485. determine an order of \term{evaluation} between two creation/initialization
  1486. forms, the order of \term{evaluation} is unspecified.
  1487. While these creation and initialization forms are being evaluated, the
  1488. \term{objects} are possibly in an uninitialized state,
  1489. analogous to the state
  1490. of an \term{object}
  1491. between the time it has been created by \funref{allocate-instance}
  1492. and it has been processed fully by
  1493. \funref{initialize-instance}. Programmers
  1494. writing \term{methods} for
  1495. \funref{make-load-form} must take care in manipulating
  1496. \term{objects} not to depend on
  1497. \term{slots} that have not yet been initialized.
  1498. It is \term{implementation-dependent}
  1499. whether \funref{load} calls \funref{eval} on the
  1500. \term{forms} or does some
  1501. other operation that has an equivalent effect. For example, the
  1502. \term{forms} might be translated into different but equivalent
  1503. \term{forms} and
  1504. then evaluated, they might be compiled and the resulting functions
  1505. called by \funref{load},
  1506. or they might be interpreted by a special-purpose
  1507. function different from \funref{eval}.
  1508. All that is required is that the
  1509. effect be equivalent to evaluating the \term{forms}.
  1510. % Barrett: Add method descriptions, per make-load-form-confusion.
  1511. The \term{method} \term{specialized} on \typeref{class} returns a creation
  1512. \term{form} using the \term{name} of the \term{class} if the \term{class} has
  1513. a \term{proper name} in \param{environment}, signaling an error \oftype{error}
  1514. if it does not have a \term{proper name}. \term{Evaluation} of the creation
  1515. \term{form} uses the \term{name} to find the \term{class} with that
  1516. \term{name}, as if by \term{calling} \funref{find-class}. If a \term{class}
  1517. with that \term{name} has not been defined, then a \term{class} may be
  1518. computed in an \term{implementation-defined} manner. If a \term{class}
  1519. cannot be returned as the result of \term{evaluating} the creation
  1520. \term{form}, then an error \oftype{error} is signaled.
  1521. %!!! Barrett: MAKE-LOAD-FORM-CONFUSION sayed "... may define additional
  1522. % \term{conforming methods} ...", but we never actually came up
  1523. % with a definition for that term. That whole issue is not
  1524. % currently addressed by the standard, so I'm not going to try
  1525. % to fix it just here.
  1526. Both \term{conforming implementations} and \term{conforming programs} may
  1527. further \term{specialize} \funref{make-load-form}.
  1528. \label Examples::
  1529. \code
  1530. (defclass obj ()
  1531. ((x :initarg :x :reader obj-x)
  1532. (y :initarg :y :reader obj-y)
  1533. (dist :accessor obj-dist)))
  1534. \EV #<STANDARD-CLASS OBJ 250020030>
  1535. (defmethod shared-initialize :after ((self obj) slot-names &rest keys)
  1536. (declare (ignore slot-names keys))
  1537. (unless (slot-boundp self 'dist)
  1538. (setf (obj-dist self)
  1539. (sqrt (+ (expt (obj-x self) 2) (expt (obj-y self) 2))))))
  1540. \EV #<STANDARD-METHOD SHARED-INITIALIZE (:AFTER) (OBJ T) 26266714>
  1541. (defmethod make-load-form ((self obj) &optional environment)
  1542. (declare (ignore environment))
  1543. ;; Note that this definition only works because X and Y do not
  1544. ;; contain information which refers back to the object itself.
  1545. ;; For a more general solution to this problem, see revised example below.
  1546. `(make-instance ',(class-of self)
  1547. :x ',(obj-x self) :y ',(obj-y self)))
  1548. \EV #<STANDARD-METHOD MAKE-LOAD-FORM (OBJ) 26267532>
  1549. (setq obj1 (make-instance 'obj :x 3.0 :y 4.0)) \EV #<OBJ 26274136>
  1550. (obj-dist obj1) \EV 5.0
  1551. (make-load-form obj1) \EV (MAKE-INSTANCE 'OBJ :X '3.0 :Y '4.0)
  1552. \endcode
  1553. In the above example, an equivalent \term{instance} of \f{obj} is
  1554. reconstructed by using the values of two of its \term{slots}.
  1555. The value of the third \term{slot} is derived from those two values.
  1556. \medbreak
  1557. Another way to write the \funref{make-load-form} \term{method}
  1558. in that example is to use \funref{make-load-form-saving-slots}.
  1559. The code it generates might yield a slightly different result
  1560. from the \funref{make-load-form} \term{method} shown above,
  1561. but the operational effect will be the same. For example:
  1562. \smallbreak
  1563. \code
  1564. ;; Redefine method defined above.
  1565. (defmethod make-load-form ((self obj) &optional environment)
  1566. (make-load-form-saving-slots self
  1567. :slot-names '(x y)
  1568. :environment environment))
  1569. \EV #<STANDARD-METHOD MAKE-LOAD-FORM (OBJ) 42755655>
  1570. ;; Try MAKE-LOAD-FORM on object created above.
  1571. (make-load-form obj1)
  1572. \EV (ALLOCATE-INSTANCE '#<STANDARD-CLASS OBJ 250020030>),
  1573. (PROGN
  1574. (SETF (SLOT-VALUE '#<OBJ 26274136> 'X) '3.0)
  1575. (SETF (SLOT-VALUE '#<OBJ 26274136> 'Y) '4.0)
  1576. (INITIALIZE-INSTANCE '#<OBJ 26274136>))
  1577. \endcode
  1578. \medbreak
  1579. In the following example, \term{instances} of \f{my-frob} are ``interned''
  1580. in some way. An equivalent \term{instance} is reconstructed by using the
  1581. value of the name slot as a key for searching existing \term{objects}.
  1582. In this case the programmer has chosen to create a new \term{object}
  1583. if no existing \term{object} is found; alternatively an error could
  1584. have been signaled in that case.
  1585. \smallbreak
  1586. \code
  1587. (defclass my-frob ()
  1588. ((name :initarg :name :reader my-name)))
  1589. (defmethod make-load-form ((self my-frob) &optional environment)
  1590. (declare (ignore environment))
  1591. `(find-my-frob ',(my-name self) :if-does-not-exist :create))
  1592. \endcode
  1593. \medbreak
  1594. In the following example, the data structure to be dumped is circular,
  1595. because each parent has a list of its children and each child has a reference
  1596. back to its parent. If \funref{make-load-form} is called on one
  1597. \term{object} in such a structure, the creation form creates an equivalent
  1598. \term{object} and fills in the children slot, which forces creation of equivalent
  1599. \term{objects} for all of its children, grandchildren, etc. At this point
  1600. none of the parent \term{slots} have been filled in.
  1601. The initialization form fills in the parent \term{slot}, which forces creation
  1602. of an equivalent \term{object} for the parent if it was not already created.
  1603. Thus the entire tree is recreated at \funref{load} time.
  1604. At compile time, \funref{make-load-form} is called once for each \term{object}
  1605. in the tree.
  1606. All of the creation forms are evaluated,
  1607. in \term{implementation-dependent} order,
  1608. and then all of the initialization forms are evaluated,
  1609. also in \term{implementation-dependent} order.
  1610. \smallbreak
  1611. \code
  1612. (defclass tree-with-parent () ((parent :accessor tree-parent)
  1613. (children :initarg :children)))
  1614. (defmethod make-load-form ((x tree-with-parent) &optional environment)
  1615. (declare (ignore environment))
  1616. (values
  1617. ;; creation form
  1618. `(make-instance ',(class-of x) :children ',(slot-value x 'children))
  1619. ;; initialization form
  1620. `(setf (tree-parent ',x) ',(slot-value x 'parent))))
  1621. \endcode
  1622. \medbreak
  1623. In the following example, the data structure to be dumped has no special
  1624. properties and an equivalent structure can be reconstructed
  1625. simply by reconstructing the \term{slots}' contents.
  1626. \smallbreak
  1627. \code
  1628. (defstruct my-struct a b c)
  1629. (defmethod make-load-form ((s my-struct) &optional environment)
  1630. (make-load-form-saving-slots s :environment environment))
  1631. \endcode
  1632. \label Affected By:\None.
  1633. \label Exceptional Situations::
  1634. % \funref{make-load-form} of an \term{object}
  1635. % of \term{metaclass} \typeref{standard-class} or \typeref{structure-class}
  1636. % for which no user-defined \term{method} is applicable
  1637. % signals an error \oftype{error}.
  1638. % It is valid to implement this either by defining default
  1639. % methods on \typeref{standard-object} and \typeref{structure-object}
  1640. % that signal an error \oftype{error}
  1641. % or by having no \term{applicable method} for those \term{classes}.
  1642. %% Rewritten per item 1.3 of MAKE-LOAD-FORM-CONFUSION:
  1643. The \term{methods} \term{specialized} on
  1644. \typeref{standard-object},
  1645. \typeref{structure-object},
  1646. and \typeref{condition}
  1647. all signal an error \oftype{error}.
  1648. % Barrett: Add per make-load-form-confusion.
  1649. It is \term{implementation-dependent} whether \term{calling}
  1650. \funref{make-load-form} on a \term{generalized instance} of a
  1651. \term{system class} signals an error or returns creation and
  1652. initialization \term{forms}.
  1653. \label See Also::
  1654. \funref{compile-file},
  1655. \funref{make-load-form-saving-slots},
  1656. {\secref\CallingMakeLoadForm}
  1657. {\secref\Evaluation},
  1658. {\secref\Compilation}
  1659. \label Notes::
  1660. The \term{file compiler}
  1661. %\funref{compile-file}
  1662. calls \funref{make-load-form} in specific circumstances
  1663. detailed in \secref\CallingMakeLoadForm.
  1664. %% Removed per item 1.2 of MAKE-LOAD-FORM-CONFUSION:
  1665. % It is valid for user programs to
  1666. % call \funref{make-load-form} in other circumstances, providing \param{object}'s
  1667. % \term{metaclass} is neither \typeref{built-in-class}
  1668. % nor a \term{subclass} of \typeref{built-in-class}.
  1669. % Barrett: Add per make-load-form-confusion.
  1670. Some \term{implementations} may provide facilities for defining new
  1671. \term{subclasses} of \term{classes} which are specified as
  1672. \term{system classes}. (Some likely candidates include
  1673. \typeref{generic-function}, \typeref{method}, and \typeref{stream}). Such
  1674. \term{implementations} should document how the \term{file compiler} processes
  1675. \term{instances} of such \term{classes} when encountered as
  1676. \term{literal objects}, and should document any relevant \term{methods}
  1677. for \funref{make-load-form}.
  1678. \endissue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  1679. \endissue{MAKE-LOAD-FORM-CONFUSION:REWRITE}
  1680. \endcom
  1681. %%% ========== MAKE-LOAD-FORM-SAVING-SLOTS
  1682. \begincom{make-load-form-saving-slots}\ftype{Function}
  1683. \issue{MAKE-LOAD-FORM-CONFUSION:REWRITE}
  1684. % Barrett: Issue reference for LOAD-OBJECTS was missing.
  1685. \issue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  1686. \label Syntax::
  1687. \DefunWithValuesNewline make-load-form-saving-slots
  1688. {object {\key} slot-names environment}
  1689. {creation-form, initialization-form}
  1690. \label Arguments and Values::
  1691. \param{object}---an \term{object}.
  1692. \param{slot-names}---a \term{list}.
  1693. \param{environment}---an \term{environment object}.
  1694. \param{creation-form}---a \term{form}.
  1695. \param{initialization-form}---a \term{form}.
  1696. \label Description::
  1697. \issue{MAKE-LOAD-FORM-SAVING-SLOTS:NO-INITFORMS}
  1698. % Returns \term{forms} that, when \term{evaluated}, will construct an
  1699. % \term{object} equivalent to \param{object} using \funref{make-instance}
  1700. % and \macref{setf} of \funref{slot-value} for \term{slots} with values,
  1701. % or \funref{slot-makunbound} for \term{slots} without values,
  1702. % or using other \term{functions} of equivalent effect.
  1703. % \funref{make-load-form-saving-slots} works for any \term{object}
  1704. % of \term{metaclass} \typeref{standard-class} or \typeref{structure-class}.
  1705. Returns \term{forms} that, when \term{evaluated}, will construct an
  1706. \term{object} equivalent to \param{object}, without \term{executing}
  1707. \term{initialization forms}. The \term{slots} in the new \term{object}
  1708. that correspond to initialized \term{slots} in \param{object} are
  1709. initialized using the values from \param{object}. Uninitialized \term{slots}
  1710. in \param{object} are not initialized in the new \term{object}.
  1711. \funref{make-load-form-saving-slots} works for any \term{instance} of
  1712. \typeref{standard-object} or \typeref{structure-object}.
  1713. \endissue{MAKE-LOAD-FORM-SAVING-SLOTS:NO-INITFORMS}
  1714. %Barmar: What does it return if object is a structure?
  1715. % MAKE-INSTANCE can't be used on structure classes, can it?
  1716. %KMP: I think that's what "functions of equivalent effect" is supposed to answer.
  1717. \param{Slot-names} is a \term{list} of the names of the
  1718. \term{slots} to preserve. If \param{slot-names} is not
  1719. supplied, its value is all of the \term{local slots}.
  1720. \funref{make-load-form-saving-slots} returns two values,
  1721. thus it can deal with circular structures.
  1722. Whether the result is useful in an application depends on
  1723. whether the \param{object}'s \term{type} and slot contents
  1724. fully capture the application's idea of the \param{object}'s state.
  1725. \param{Environment} is the environment in which the forms will be processed.
  1726. \label Examples:\None.
  1727. \label Side Effects:\None.
  1728. \label Affected By:\None.
  1729. \label Exceptional Situations:\None.
  1730. \label See Also::
  1731. \funref{make-load-form},
  1732. \funref{make-instance},
  1733. \macref{setf},
  1734. \funref{slot-value},
  1735. \funref{slot-makunbound}
  1736. \label Notes::
  1737. \funref{make-load-form-saving-slots} can be useful in user-written
  1738. \funref{make-load-form} methods.
  1739. % Barrett: Remember to put in end marker.
  1740. \endissue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  1741. \endissue{MAKE-LOAD-FORM-CONFUSION:REWRITE}
  1742. \issue{MAKE-LOAD-FORM-SAVING-SLOTS:NO-INITFORMS}
  1743. When the \term{object} is an \term{instance} of \typeref{standard-object},
  1744. \funref{make-load-form-saving-slots} could return a creation form that
  1745. \term{calls} \funref{allocate-instance} and an initialization form that
  1746. contains \term{calls} to \macref{setf} of \funref{slot-value} and
  1747. \funref{slot-makunbound}, though other \term{functions} of similar effect
  1748. might actually be used.
  1749. \endissue{MAKE-LOAD-FORM-SAVING-SLOTS:NO-INITFORMS}
  1750. \endcom
  1751. %%% ========== WITH-ACCESSORS
  1752. \begincom{with-accessors}\ftype{Macro}
  1753. \issue{DECLS-AND-DOC}
  1754. \label Syntax::
  1755. \DefmacWithValuesNewline with-accessors
  1756. {{\paren{\starparam{slot-entry}}}
  1757. instance-form
  1758. \starparam{declaration} \starparam{form}}
  1759. {\starparam{result}}
  1760. \auxbnf{slot-entry}{\paren{variable-name accessor-name}}
  1761. \label Arguments and Values::
  1762. \param{variable-name}---a \term{variable name}; \noeval.
  1763. \param{accessor-name}---a \term{function name}; \noeval.
  1764. \param{instance-form}---a \term{form}; \eval.
  1765. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  1766. \param{forms}---an \term{implicit progn}.
  1767. \param{results}---the \term{values} returned by the \param{forms}.
  1768. \label Description::
  1769. Creates a lexical environment in which
  1770. the slots specified by
  1771. \param{slot-entry} are lexically available through their accessors as if
  1772. they were variables. The macro \macref{with-accessors} invokes the
  1773. appropriate accessors to \param{access} the \term{slots} specified
  1774. by \param{slot-entry}. Both \macref{setf}
  1775. and \specref{setq} can be used to set the value of the \term{slot}.
  1776. \label Examples::
  1777. \code
  1778. (defclass thing ()
  1779. ((x :initarg :x :accessor thing-x)
  1780. (y :initarg :y :accessor thing-y)))
  1781. \EV #<STANDARD-CLASS THING 250020173>
  1782. (defmethod (setf thing-x) :before (new-x (thing thing))
  1783. (format t "~&Changing X from ~D to ~D in ~S.~%"
  1784. (thing-x thing) new-x thing))
  1785. (setq thing1 (make-instance 'thing :x 1 :y 2)) \EV #<THING 43135676>
  1786. (setq thing2 (make-instance 'thing :x 7 :y 8)) \EV #<THING 43147374>
  1787. (with-accessors ((x1 thing-x) (y1 thing-y))
  1788. thing1
  1789. (with-accessors ((x2 thing-x) (y2 thing-y))
  1790. thing2
  1791. (list (list x1 (thing-x thing1) y1 (thing-y thing1)
  1792. x2 (thing-x thing2) y2 (thing-y thing2))
  1793. (setq x1 (+ y1 x2))
  1794. (list x1 (thing-x thing1) y1 (thing-y thing1)
  1795. x2 (thing-x thing2) y2 (thing-y thing2))
  1796. (setf (thing-x thing2) (list x1))
  1797. (list x1 (thing-x thing1) y1 (thing-y thing1)
  1798. x2 (thing-x thing2) y2 (thing-y thing2)))))
  1799. \OUT Changing X from 1 to 9 in #<THING 43135676>.
  1800. \OUT Changing X from 7 to (9) in #<THING 43147374>.
  1801. \EV ((1 1 2 2 7 7 8 8)
  1802. 9
  1803. (9 9 2 2 7 7 8 8)
  1804. (9)
  1805. (9 9 2 2 (9) (9) 8 8))
  1806. \endcode
  1807. \label Affected By::
  1808. \macref{defclass}
  1809. \label Exceptional Situations::
  1810. The consequences are undefined if any \param{accessor-name} is not the name
  1811. of an accessor for the \param{instance}.
  1812. \label See Also::
  1813. \macref{with-slots},
  1814. \specref{symbol-macrolet}
  1815. \label Notes::
  1816. A \macref{with-accessors} expression of the form:
  1817. $$\openup1\jot\vbox{\settabs\+\cr
  1818. \+{\tt (with-accessors} (${\hbox{\i{slot-entry}}}\sub 1%
  1819. \ldots{\hbox{\i{slot-entry}}}\sub n$) \i{instance-form}
  1820. ${\hbox{\i{form}}}\sub 1%
  1821. \ldots{\hbox{\i{form}}}\sub k$)\cr}$$
  1822. \noindent expands into the equivalent of
  1823. $$\openup1\jot\vbox{\settabs\+\cr
  1824. \+{\tt (}&{\tt let ((}$in$ \i{instance-form}{\tt ))}\cr
  1825. \+&{\tt (symbol-macrolet (}${\hbox{\i{Q}}}\sub 1\ldots%
  1826. {\hbox{\i{Q}}}\sub n${\tt )} ${\hbox{\i{form}}}\sub 1%
  1827. \ldots{\hbox{\i{form}}}\sub k${\tt ))}\cr}$$
  1828. \noindent where ${\hbox{\i{Q}}}\sub i$ is
  1829. $${\vbox{\hbox{{\tt (}${\hbox{\i{variable-name}}}\sub i$ () %
  1830. {\tt (${\hbox{\i{accessor-name}}}\sub{i}\ in$))}}}}$$
  1831. \endissue{DECLS-AND-DOC}
  1832. \endcom
  1833. %%% ========== WITH-SLOTS
  1834. \begincom{with-slots}\ftype{Macro}
  1835. \issue{DECLS-AND-DOC}
  1836. \label Syntax::
  1837. \DefmacWithValuesNewline with-slots
  1838. {\paren{\starparam{slot-entry}}
  1839. instance-form
  1840. \starparam{declaration} \starparam{form}}
  1841. {\starparam{result}}
  1842. \auxbnf{slot-entry}{slot-name | \paren{variable-name slot-name}}
  1843. \label Arguments and Values::
  1844. \param{slot-name}---a \term{slot} \term{name}; \noeval.
  1845. \param{variable-name}---a \term{variable name}; \noeval.
  1846. \param{instance-form}---a \term{form}; evaluted to produce \param{instance}.
  1847. \param{instance}---an \term{object}.
  1848. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  1849. \param{forms}---an \term{implicit progn}.
  1850. \param{results}---the \term{values} returned by the \param{forms}.
  1851. \label Description::
  1852. The macro \macref{with-slots} \term{establishes} a
  1853. %lexical context
  1854. \term{lexical environment}
  1855. for referring to the \term{slots} in the \param{instance}
  1856. named by the given \param{slot-names}
  1857. as though they were \term{variables}. Within such a context
  1858. the value of the \term{slot} can be specified by using its slot name, as if
  1859. it were a lexically bound variable. Both \macref{setf} and \specref{setq}
  1860. can be used to set the value of the \term{slot}.
  1861. The macro \macref{with-slots} translates an appearance of the slot
  1862. name as a \term{variable} into a call to \funref{slot-value}.
  1863. \label Examples::
  1864. \code
  1865. (defclass thing ()
  1866. ((x :initarg :x :accessor thing-x)
  1867. (y :initarg :y :accessor thing-y)))
  1868. \EV #<STANDARD-CLASS THING 250020173>
  1869. (defmethod (setf thing-x) :before (new-x (thing thing))
  1870. (format t "~&Changing X from ~D to ~D in ~S.~%"
  1871. (thing-x thing) new-x thing))
  1872. (setq thing (make-instance 'thing :x 0 :y 1)) \EV #<THING 62310540>
  1873. (with-slots (x y) thing (incf x) (incf y)) \EV 2
  1874. (values (thing-x thing) (thing-y thing)) \EV 1, 2
  1875. (setq thing1 (make-instance 'thing :x 1 :y 2)) \EV #<THING 43135676>
  1876. (setq thing2 (make-instance 'thing :x 7 :y 8)) \EV #<THING 43147374>
  1877. (with-slots ((x1 x) (y1 y))
  1878. thing1
  1879. (with-slots ((x2 x) (y2 y))
  1880. thing2
  1881. (list (list x1 (thing-x thing1) y1 (thing-y thing1)
  1882. x2 (thing-x thing2) y2 (thing-y thing2))
  1883. (setq x1 (+ y1 x2))
  1884. (list x1 (thing-x thing1) y1 (thing-y thing1)
  1885. x2 (thing-x thing2) y2 (thing-y thing2))
  1886. (setf (thing-x thing2) (list x1))
  1887. (list x1 (thing-x thing1) y1 (thing-y thing1)
  1888. x2 (thing-x thing2) y2 (thing-y thing2)))))
  1889. \OUT Changing X from 7 to (9) in #<THING 43147374>.
  1890. \EV ((1 1 2 2 7 7 8 8)
  1891. 9
  1892. (9 9 2 2 7 7 8 8)
  1893. (9)
  1894. (9 9 2 2 (9) (9) 8 8))
  1895. \endcode
  1896. \label Affected By::
  1897. \macref{defclass}
  1898. \label Exceptional Situations::
  1899. The consequences are undefined if any \param{slot-name} is not the name
  1900. of a \term{slot} in the \param{instance}.
  1901. \label See Also::
  1902. \macref{with-accessors},
  1903. \funref{slot-value},
  1904. \specref{symbol-macrolet}
  1905. \label Notes::
  1906. A \macref{with-slots} expression of the form:
  1907. $$\openup1\jot\vbox{\settabs\+\cr
  1908. \+{\tt (with-slots} (${\hbox{\i{slot-entry}}}\sub 1%
  1909. \ldots{\hbox{\i{slot-entry}}}\sub n$) \i{instance-form}
  1910. ${\hbox{\i{form}}}\sub 1%
  1911. \ldots{\hbox{\i{form}}}\sub k$)\cr}$$
  1912. \noindent expands into the equivalent of
  1913. $$\openup1\jot\vbox{\settabs\+\cr
  1914. \+{\tt (}&{\tt let ((}$in$ \i{instance-form}{\tt ))}\cr
  1915. \+&{\tt (symbol-macrolet (}${\hbox{\i{Q}}}\sub 1\ldots%
  1916. {\hbox{\i{Q}}}\sub n${\tt )} ${\hbox{\i{form}}}\sub 1%
  1917. \ldots{\hbox{\i{form}}}\sub k${\tt ))}\cr}$$
  1918. \noindent where ${\hbox{\i{Q}}}\sub i$ is
  1919. $$\vbox{\hbox{{\tt (}${\hbox{\i{slot-entry}}}\sub i$ () %
  1920. {\tt (slot-value }$in$ '${\hbox{\i{slot-entry}}}\sub i${\tt ))}}}$$
  1921. \noindent if ${\hbox{\i{slot-entry}}}\sub i$ is a \term{symbol}
  1922. and is
  1923. $${\vbox{\hbox{{\tt (}${\hbox{\i{variable-name}}}\sub i$ () %
  1924. {\tt (slot-value }$in$ '${\hbox{\i{slot-name}}}\sub i${\tt ))}}}}$$
  1925. \noindent if ${\hbox{\i{slot-entry}}}\sub i$
  1926. is of the form
  1927. $$\vbox{\hbox{{\tt (}${\hbox{\i{variable-name}}}\sub i$ %
  1928. ${\hbox{\i{slot-name}}}\sub i${\tt )}}}$$
  1929. \endissue{DECLS-AND-DOC}
  1930. \endcom
  1931. %%% ========== DEFCLASS
  1932. \begincom{defclass}\ftype{Macro}
  1933. \label Syntax::
  1934. %%Syntax fixed per X3J13. -kmp 05-Oct-93
  1935. \DefmacWithValuesNewline defclass
  1936. {\param{class-name} \paren{\star{\curly{\param{superclass-name}}}}
  1937. \paren{\star{\curly{\i{slot-specifier}}}}
  1938. $\lbrack\!\lbrack\downarrow\!\hbox{\i{class-option}}\,\rbrack\!\rbrack$}
  1939. {new-class}
  1940. \settabs\+\hskip\leftskip&\cr
  1941. \+&\cleartabs\i{slot-specifier}::$=$ &\i{slot-name} $\vert$
  1942. (\i{slot-name}
  1943. $\lbrack\!\lbrack\downarrow\!\hbox{\i{slot-option}}\,\rbrack\!\rbrack$)\cr
  1944. \Vskip 1pc!
  1945. \+&\i{slot-name}::$=$ \term{symbol}\cr
  1946. \Vskip 1pc!
  1947. \+&\cleartabs\i{slot-option}::$=$ &\star{\curly{\kwd{reader}
  1948. \param{reader-function-name}}} $\vert$ \cr
  1949. \+&&\star{\curly{\kwd{writer} \param{writer-function-name}}} $\vert$ \cr
  1950. \+&&\star{\curly{\kwd{accessor} \param{reader-function-name}}} $\vert$ \cr
  1951. \+&&\curly{\kwd{allocation} \param{allocation-type}} $\vert$ \cr
  1952. \+&&\star{\curly{\kwd{initarg} \param{initarg-name}}} $\vert$ \cr
  1953. \+&&\curly{\kwd{initform} \param{form}} $\vert$ \cr
  1954. \+&&\curly{\kwd{type} \param{type-specifier}} $\vert$ \cr
  1955. \+&&\curly{\kwd{documentation} \term{string}} \cr
  1956. \Vskip 1pc!
  1957. \+&\i{function-name}::$=$ \curly{\term{symbol}
  1958. $\vert$ {\tt (setf \term{symbol})}}\cr
  1959. \Vskip 1pc!
  1960. \+&\cleartabs\param{class-option}::$=$ &(\kwd{default-initargs} \f{.}
  1961. \param{initarg-list}) $\vert$ \cr
  1962. \+&&(\kwd{documentation} \term{string}) $\vert$ \cr
  1963. \+&&(\kwd{metaclass} \param{class-name}) \cr
  1964. \Vskip 1pc!
  1965. \label Arguments and Values::
  1966. %!!! Treatment of documentation?
  1967. \param{Class-name}---a \term{non-nil} \term{symbol}.
  1968. \param{Superclass-name}--a \term{non-nil} \term{symbol}.
  1969. \param{Slot-name}--a \term{symbol}.
  1970. The \param{slot-name} argument is
  1971. %!!! Isn't there a more concise way to say this?
  1972. a \term{symbol} that is syntactically valid for use as a variable name.
  1973. \param{Reader-function-name}---a \term{non-nil} \term{symbol}.
  1974. \kwd{reader} can be supplied more than once for a given \term{slot}.
  1975. \param{Writer-function-name}---a \term{generic function} name.
  1976. \kwd{writer} can be supplied more than once for a given \term{slot}.
  1977. \param{Reader-function-name}---a \term{non-nil} \term{symbol}.
  1978. \kwd{accessor} can be supplied more than once for a given \term{slot}.
  1979. \param{Allocation-type}---(member \kwd{instance} \kwd{class}).
  1980. \kwd{allocation} can be supplied once at most for a given \term{slot}.
  1981. \param{Initarg-name}---a \term{symbol}.
  1982. \kwd{initarg} can be supplied more than once for a given \term{slot}.
  1983. \param{Form}---a \term{form}.
  1984. \kwd{init-form} can be supplied once at most for a given \term{slot}.
  1985. \param{Type-specifier}---a \term{type specifier}.
  1986. \kwd{type} can be supplied once at most for a given \term{slot}.
  1987. \param{Class-option}--- refers to the \term{class} as a whole or to all class \term{slots}.
  1988. \param{Initarg-list}---a \term{list} of alternating initialization argument
  1989. \term{names} and default initial value \term{forms}.
  1990. \kwd{default-initargs} can be supplied at most once.
  1991. \param{Class-name}---a \term{non-nil} \term{symbol}.
  1992. \kwd{metaclass} can be supplied once at most.
  1993. %The \i{class-name} argument is a \term{non-nil} symbol.
  1994. %Each \i{superclass-name} argument is a \term{non-nil} symbol.
  1995. %Each \i{slot-specifier} argument is the name of the slot or a list
  1996. %consisting of the slot name followed by zero or more slot options.
  1997. %The \i{reader-function-name} argument is a \term{non-nil} symbol.
  1998. %The \i{writer-function-name} argument is a function specifier.
  1999. %The \i{initarg-name} argument is a symbol.
  2000. %!!! Ugh. Surely this should not be so. -kmp 24-Apr-91
  2001. \param{new-class}---the new \term{class} \term{object}.
  2002. \label Description::
  2003. The macro \macref{defclass} defines a new named \term{class}. It returns
  2004. the new \term{class} \term{object} as its result.
  2005. The syntax of \macref{defclass} provides options for specifying
  2006. initialization arguments for \term{slots}, for specifying default
  2007. initialization values for \term{slots}, and for requesting that
  2008. \term{methods} on specified \term{generic functions} be automatically
  2009. generated for reading and writing the values of \term{slots}.
  2010. No reader or writer functions are defined by default;
  2011. their generation must be explicitly requested. However,
  2012. \term{slots} can always be \term{accessed} using \funref{slot-value}.
  2013. Defining a new \term{class} also causes a \term{type} of the same name to be
  2014. defined. The predicate \f{(typep \param{object} \param{class-name})} returns
  2015. true if the \term{class} of the given \param{object} is
  2016. the \term{class} named by \param{class-name} itself or
  2017. a subclass of the class \param{class-name}. A \term{class} \term{object}
  2018. can be used as a \term{type specifier}.
  2019. Thus \f{(typep \param{object} \param{class})} returns \term{true}
  2020. if the \term{class} of the \param{object} is
  2021. \param{class} itself or a subclass of \param{class}.
  2022. The \param{class-name} argument specifies the \term{proper name}
  2023. of the new \term{class}.
  2024. %If a \term{class}
  2025. %with the same proper name already exists and that
  2026. %\term{class} is an \term{instance} of \typeref{standard-class}, and if the
  2027. %\macref{defclass} form for the definition of the new \term{class}
  2028. %specifies a \term{class} of class \typeref{standard-class}, the
  2029. %definition of the existing \term{class} is replaced.
  2030. If a \term{class} with the same \term{proper name} already exists
  2031. and that \term{class} is an \term{instance} of \typeref{standard-class},
  2032. and if the \macref{defclass} form for the definition of the new \term{class}
  2033. specifies a \term{class} of \term{class} \typeref{standard-class},
  2034. the existing \term{class} is redefined,
  2035. and instances of it (and its \term{subclasses}) are updated
  2036. to the new definition at the time that they are next \term{accessed}.
  2037. For details, \seesection\ClassReDef.
  2038. % addressed in the packages chapter. --sjl 5 Mar 92
  2039. %\issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2040. %The consequences are undefined if a \term{symbol} in \thepackage{common-lisp}
  2041. %is used as the \param{class-name} argument.
  2042. %\endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2043. Each \param{superclass-name} argument
  2044. specifies a direct \term{superclass} of the new \term{class}.
  2045. %% gray addition
  2046. If the \term{superclass} list is empty, then the \term{superclass}
  2047. defaults depending on the \term{metaclass},
  2048. with \typeref{standard-object} being the
  2049. default for \typeref{standard-class}.
  2050. The new \term{class} will
  2051. inherit \term{slots} and \term{methods}
  2052. from each of its direct \term{superclasses}, from
  2053. their direct \term{superclasses}, and so on.
  2054. For a discussion of how \term{slots} and \term{methods} are inherited,
  2055. \seesection\Inheritance.
  2056. %Each \i{slot-specifier} argument is the \term{name} of the slot or a list
  2057. %consisting of the slot name followed by zero or more slot options.
  2058. %The \i{slot-name} argument is a symbol that is syntactically valid
  2059. %for use as a Common Lisp variable name. If there are any duplicate
  2060. %slot names, an error is signaled.
  2061. The following slot options are available:
  2062. \beginlist
  2063. \itemitem{\bull}
  2064. The \kwd{reader} slot option specifies that an \term{unqualified method} is
  2065. to be defined on the \term{generic function} named \param{reader-function-name}
  2066. to read the value of the given \term{slot}.
  2067. \itemitem{\bull}
  2068. The \kwd{writer} slot option specifies that an \term{unqualified method} is
  2069. to be defined on the \term{generic function} named \param{writer-function-name}
  2070. to write the value of the \term{slot}.
  2071. \itemitem{\bull}
  2072. The \kwd{accessor} slot option specifies that an \term{unqualified method}
  2073. is to be defined on the generic function named \param{reader-function-name}
  2074. to read the value of the given \term{slot}
  2075. and that an \term{unqualified method} is to be defined on the
  2076. \term{generic function} named \f{(setf \param{reader-function-name})} to be
  2077. used with \macref{setf} to modify the value of the \term{slot}.
  2078. \itemitem{\bull}
  2079. The \kwd{allocation} slot option is used to specify where storage is
  2080. to be allocated for the given \term{slot}. Storage for a
  2081. \term{slot} can be located
  2082. in each instance or in the \term{class} \term{object} itself.
  2083. The value of the \param{allocation-type} argument can be
  2084. either the keyword \kwd{instance}
  2085. or the keyword \kwd{class}. If the \kwd{allocation}
  2086. slot option is not specified, the effect is the same as specifying
  2087. \f{:allocation :instance}.
  2088. \beginlist
  2089. \itemitem{--}
  2090. If \param{allocation-type} is \kwd{instance}, a \term{local slot} of
  2091. the name \param{slot-name} is allocated in each instance of the
  2092. \term{class}.
  2093. \itemitem{--}
  2094. If \param{allocation-type} is \kwd{class}, a shared
  2095. \term{slot} of the given
  2096. name is allocated in the \term{class} \term{object} created by this \macref{defclass}
  2097. form. The value of the \term{slot} is shared by all
  2098. \term{instances} of the \term{class}.
  2099. If a class $C\sub1$ defines such a \term{shared slot}, any
  2100. subclass $C\sub2$ of
  2101. $C\sub1$ will share this single \term{slot} unless the \macref{defclass} form
  2102. for $C\sub2$ specifies a \term{slot} of the same \term{name} or there is a
  2103. superclass of $C\sub2$ that precedes $C\sub1$ in the class precedence
  2104. list of $C\sub2$ and that defines a \term{slot} of the same \term{name}.
  2105. \endlist
  2106. \itemitem{\bull} The \kwd{initform} slot option is used to provide a default
  2107. initial value form to be used in the initialization of the \term{slot}. This
  2108. \term{form} is evaluated every time it is used to initialize the
  2109. \term{slot}. The
  2110. lexical environment in which this \term{form} is evaluated is the lexical
  2111. environment in which the \macref{defclass} form was evaluated.
  2112. Note that the lexical environment refers both to variables and to
  2113. functions. For \term{local slots}, the dynamic environment is the dynamic
  2114. environment in which \funref{make-instance} is called; for shared
  2115. \term{slots}, the dynamic environment is the dynamic environment in which the
  2116. \macref{defclass} form was evaluated.
  2117. \Seesection\ObjectCreationAndInit.
  2118. No implementation is permitted to extend the syntax of \macref{defclass}
  2119. to allow \f{(\param{slot-name} \param{form})} as an abbreviation for
  2120. \f{(\param{slot-name} :initform \param{form})}.
  2121. \reviewer{Barmar: Can you extend this to mean something else?}
  2122. \itemitem{\bull}
  2123. The \kwd{initarg} slot option declares an initialization
  2124. argument named \param{initarg-name} and specifies that this
  2125. initialization argument initializes the given \term{slot}. If the
  2126. initialization argument has a value in the call to
  2127. \funref{initialize-instance}, the value will be stored into the given \term{slot},
  2128. and the slot's \kwd{initform} slot option, if any, is not
  2129. evaluated. If none of the initialization arguments specified for a
  2130. given \term{slot} has a value, the \term{slot} is initialized according to the
  2131. \kwd{initform} slot option, if specified.
  2132. \itemitem{\bull}
  2133. The \kwd{type} slot option specifies that the contents of the
  2134. \term{slot} will always be of the specified data type. It effectively
  2135. declares the result type of the reader generic function when applied
  2136. to an \term{object} of this \term{class}. The consequences of attempting to store in a
  2137. \term{slot} a value that does not satisfy the type of the \term{slot} are undefined.
  2138. The \kwd{type} slot option is further discussed in
  2139. \secref\SlotInheritance.
  2140. \itemitem{\bull}
  2141. The \kwd{documentation} slot option provides a \term{documentation string}
  2142. for the \term{slot}. \kwd{documentation} can be supplied once at most
  2143. for a given \term{slot}. \reviewer{Barmar: How is this retrieved?}
  2144. \endlist
  2145. Each class option is an option that refers to the \term{class} as a whole.
  2146. %!!! Barmar alleges that there are none of these:
  2147. %or to all class \term{slots}.
  2148. The following class options are available:
  2149. \beginlist
  2150. \itemitem{\bull}
  2151. The \kwd{default-initargs} class option is followed by a list of
  2152. alternating initialization argument \term{names} and default initial value
  2153. forms. If any of these initialization arguments does not appear in
  2154. the initialization argument list supplied to \funref{make-instance}, the
  2155. corresponding default initial value form is evaluated, and the
  2156. initialization argument \term{name} and the \term{form}'s value are added to the end
  2157. of the initialization argument list before the instance is created;
  2158. \seesection\ObjectCreationAndInit.
  2159. The default initial value form is evaluated each time it is used. The lexical
  2160. environment in which this \term{form} is evaluated is the lexical environment
  2161. in which the \macref{defclass} form was evaluated. The dynamic
  2162. environment is the dynamic environment in which \funref{make-instance}
  2163. was called. If an initialization argument \term{name} appears more than once
  2164. in a \kwd{default-initargs} class option, an error is signaled.
  2165. \itemitem{\bull}
  2166. \issue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  2167. The \kwd{documentation} class option causes a \term{documentation string}
  2168. to be attached with the \term{class} \term{object},
  2169. and attached with kind \misc{type} to the \param{class-name}.
  2170. \kwd{documentation} can be supplied once at most.
  2171. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  2172. \itemitem{\bull}
  2173. The \kwd{metaclass} class option is used to specify that
  2174. instances of the \term{class} being defined are to have a different metaclass
  2175. than the default provided by the system (\theclass{standard-class}).
  2176. \endlist
  2177. Note the following rules of \macref{defclass} for \term{standard classes}:
  2178. \beginlist
  2179. \itemitem{\bull}
  2180. It is not required that the \term{superclasses} of a \term{class} be defined before
  2181. the \macref{defclass} form for that \term{class} is evaluated.
  2182. \itemitem{\bull}
  2183. All the \term{superclasses} of a \term{class} must be defined before
  2184. an \term{instance} of the \term{class} can be made.
  2185. \itemitem{\bull}
  2186. A \term{class} must be defined before it can be used as a parameter
  2187. specializer in a \macref{defmethod} form.
  2188. \endlist
  2189. The \OS\ can be extended to cover situations where these rules are not
  2190. obeyed.
  2191. Some slot options are inherited by a \term{class} from its
  2192. \term{superclasses}, and
  2193. some can be shadowed or altered by providing a local slot description.
  2194. No class options except \kwd{default-initargs} are inherited. For a
  2195. detailed description of how \term{slots} and slot options are inherited,
  2196. \seesection\SlotInheritance.
  2197. The options to \macref{defclass} can be extended. It is required that
  2198. all implementations signal an error if they observe a class option or
  2199. a slot option that is not implemented locally.
  2200. It is valid to specify more than one reader, writer, accessor, or
  2201. initialization argument for a \term{slot}. No other slot option can
  2202. appear
  2203. more than once in a single slot description, or an error is
  2204. signaled.
  2205. If no reader, writer, or accessor is specified for a \term{slot},
  2206. the \term{slot} can only be \term{accessed} by \thefunction{slot-value}.
  2207. %The macro \macref{defclass} defines a new named \term{class}.
  2208. %Defining a new \term{class} also causes a
  2209. %\term{type} of the same \term{name} to be defined.
  2210. %The \kwd{reader} slot option causes an \term{unqualified method}
  2211. %to be defined on the \term{generic function} named
  2212. %\param{reader-function-name} to read the value of the given \term{slot}.
  2213. %The \kwd{writer} slot option causes an \term{unqualified method}
  2214. %to be defined on the \term{generic function} named
  2215. %\param{writer-function-name} to write the value of the \term{slot}.
  2216. %The \kwd{accessor} slot option causes an \term{unqualified method}
  2217. %to be defined on the \term{generic function} named
  2218. %\param{reader-function-name} to read the value of the given \term{slot}
  2219. %and an \term{unqualified method} to be defined on the
  2220. %\term{generic function} named {\tt (setf \param{reader-function-name})} to be
  2221. %used with \macref{setf} to modify the value of the \term{slot}.
  2222. %The \kwd{initarg} slot option declares an initialization argument
  2223. %named \param{initarg-name}.
  2224. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  2225. % added qualification about top-level-ness --sjl 5 Mar 92
  2226. If a \macref{defclass} \term{form} appears as a \term{top level form},
  2227. the \term{compiler} must make the \term{class} \term{name} be recognized as a
  2228. valid \term{type} \term{name} in subsequent declarations (as for \macref{deftype})
  2229. and be recognized as a valid \term{class} \term{name} for \macref{defmethod}
  2230. \term{parameter specializers} and for use as the \kwd{metaclass} option of a
  2231. subsequent \macref{defclass}. The \term{compiler} must make
  2232. %%!!! this doesn't look right. maybe "a class object"? -kmp 7-Jun-91
  2233. the \term{class} definition
  2234. available to be returned by \funref{find-class} when its \param{environment}
  2235. \term{argument} is a value received as the \term{environment parameter} of a \term{macro}.
  2236. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  2237. \label Examples:\None.
  2238. \label Affected By:\None.
  2239. \label Exceptional Situations::
  2240. If there are any duplicate slot names,
  2241. an error \oftype{program-error} is signaled.
  2242. If an initialization argument \term{name} appears more than once in
  2243. \kwd{default-initargs} class option,
  2244. an error \oftype{program-error} is signaled.
  2245. If any of the following slot options appears more than once in a
  2246. single slot description, an error \oftype{program-error}
  2247. is signaled: \kwd{allocation},
  2248. \kwd{initform}, \kwd{type}, \kwd{documentation}.
  2249. It is required that all implementations signal
  2250. an error \oftype{program-error} if they observe a class option
  2251. or a slot option that is not implemented locally.
  2252. %%gray's annotation
  2253. %>Other possible errors are an undefined metaclass or attempting to
  2254. %>redefine the name of an existing type with an incompatible metaclass
  2255. %>{e.g. DEFCLASS for a name previously defined by DEFSTRUCT or DEFTYPE}.
  2256. \label See Also::
  2257. \funref{documentation},
  2258. \funref{initialize-instance},
  2259. \funref{make-instance},
  2260. \funref{slot-value},
  2261. {\secref\Classes},
  2262. {\secref\Inheritance},
  2263. {\secref\ClassReDef},
  2264. {\secref\DeterminingtheCPL},
  2265. {\secref\ObjectCreationAndInit}
  2266. \label Notes:\None.
  2267. \endcom
  2268. %%% ========== DEFGENERIC
  2269. \begincom{defgeneric}\ftype{Macro}
  2270. \issue{DECLS-AND-DOC}
  2271. \label Syntax::
  2272. \DefmacWithValuesNewline defgeneric
  2273. {function-name gf-lambda-list
  2274. \interleave{\down{option} | \stardown{method-description}}}
  2275. {new-generic}
  2276. \auxbnf{option}{\paren{\kwd{argument-precedence-order} \plusparam{parameter-name}} |\CR
  2277. \paren{\misc{declare} \plusparam{gf-declaration}} |\CR
  2278. \paren{\kwd{documentation} \param{gf-documentation}} |\CR
  2279. \paren{\kwd{method-combination}
  2280. \param{method-combination}
  2281. \starparam{method-combination-argument}} |\CR
  2282. \paren{\kwd{generic-function-class} \param{generic-function-class}} |\CR
  2283. \paren{\kwd{method-class} \param{method-class}}}
  2284. \auxbnf{method-description}{\lparen\kwd{method}
  2285. \vtop{\hbox{\starparam{method-qualifier}
  2286. \param{specialized-lambda-list}}
  2287. \hbox{{\DeclsAndDoc}
  2288. \starparam{form}\rparen}}}
  2289. \label Arguments and Values::
  2290. \param{function-name}---a \term{function name}.
  2291. \param{generic-function-class}---a \term{non-nil} \term{symbol} naming a \term{class}.
  2292. \param{gf-declaration}---an \declref{optimize} \term{declaration specifier};
  2293. other \term{declaration specifiers} are not permitted.
  2294. %% Barmar: What's the theory here?
  2295. %% Are \declref{ignore} and \declref{dynamic-extent} in or out?}
  2296. % \declref{special}, \declref{ftype}, \declref{function},
  2297. % \declref{inline}, \declref{notinline}, and \declref{declaration}
  2298. % declarations are not permitted.
  2299. \param{gf-documentation}---a \term{string}; \noeval.
  2300. \param{gf-lambda-list}---a \term{generic function lambda list}.
  2301. \param{method-class}---a \term{non-nil} \term{symbol} naming a \term{class}.
  2302. \param{method-combination-argument}---an \term{object.}
  2303. %% Barmar: Redundant with info to follow.
  2304. %suitable as \term{arguments} to the \param{method-combination-name};
  2305. %the standard method combination type does not support
  2306. %any \term{arguments}.
  2307. %All types of method combination defined by the
  2308. %short form of \macref{define-method-combination} accept
  2309. %\kwd{order}, which defaults to \kwd{most-specific-first}.
  2310. \param{method-combination-name}---a \term{symbol}
  2311. naming a \term{method combination} \term{type}.
  2312. \param{method-qualifiers},
  2313. \param{specialized-lambda-list},
  2314. \param{declarations},
  2315. \param{documentation},
  2316. \param{forms}---as per \macref{defmethod}.
  2317. \param{new-generic}---the \term{generic function} \term{object}.
  2318. \param{parameter-name}---a \term{symbol} that names a \term{required parameter}
  2319. in the \param{lambda-list}.
  2320. (If the \kwd{argument-precedence-order} option is specified,
  2321. each \term{required parameter} in the \param{lambda-list}
  2322. must be used exactly once as a \param{parameter-name}.)
  2323. \label Description::
  2324. The macro \macref{defgeneric} is used to define a \term{generic function}
  2325. or to specify options and declarations that pertain
  2326. to a \term{generic function} as a whole.
  2327. %!!! Rewrite in terms of "fboundp" to avoid function calls?
  2328. If \param{function-name} is a
  2329. \term{list} it must be of the form {\tt (setf \i{symbol})}.
  2330. If \f{(fboundp \param{function-name})} is \term{false}, a new
  2331. \term{generic function} is created.
  2332. \issue{FUNCTION-NAME:LARGE}
  2333. If \f{(fdefinition \param{function-name})} is a \term{generic function}, that
  2334. \endissue{FUNCTION-NAME:LARGE}
  2335. \term{generic function}
  2336. is modified. If \param{function-name} names
  2337. an \term{ordinary function},
  2338. a \term{macro}, or a \term{special operator},
  2339. an error is signaled.
  2340. The effect of the \macref{defgeneric} macro is as if the following three
  2341. steps were performed: first,
  2342. \term{methods} defined by previous \macref{defgeneric} \term{forms} are removed;
  2343. \reviewer{Barmar: Shouldn't this (second) be first?}
  2344. second, \funref{ensure-generic-function}
  2345. is called; and finally, \term{methods} specified by the current
  2346. \macref{defgeneric} \term{form} are added to the \term{generic function}.
  2347. Each \param{method-description} defines a \term{method} on the \term{generic function}.
  2348. The \term{lambda list} of each \term{method} must be congruent with the
  2349. \term{lambda list}
  2350. specified by the \param{gf-lambda-list} option.
  2351. If no \term{method} descriptions are specified and a \term{generic function} of the same
  2352. name does not already exist, a \term{generic function} with no
  2353. \term{methods} is created.
  2354. The \param{gf-lambda-list} argument of \macref{defgeneric} specifies the shape of
  2355. \term{lambda lists} for the \term{methods} on this \term{generic function}.
  2356. All \term{methods} on the resulting
  2357. \term{generic function} must have
  2358. \term{lambda lists} that are congruent with this shape. If a \macref{defgeneric}
  2359. form is evaluated and some
  2360. \term{methods} for that \term{generic function}
  2361. have \term{lambda lists} that are not congruent with that given in
  2362. the \macref{defgeneric} form, an error is signaled. For further details
  2363. on method congruence, \seesection\GFMethodLambdaListCongruency.
  2364. The \term{generic function} passes to the
  2365. \term{method} all the argument values passed to
  2366. it, and only those; default values are not supported.
  2367. Note that optional and keyword arguments in method definitions, however,
  2368. can have default initial value forms and can use supplied-p parameters.
  2369. The following options are provided.
  2370. \issue{DEFGENERIC-DECLARE:ALLOW-MULTIPLE}
  2371. Except as otherwise noted,
  2372. \endissue{DEFGENERIC-DECLARE:ALLOW-MULTIPLE}
  2373. a given option may occur only once.
  2374. \beginlist
  2375. \itemitem{\bull}
  2376. The \kwd{argument-precedence-order} option is used to specify the
  2377. order in which the required arguments in a call to the \term{generic function}
  2378. are tested for specificity when selecting a particular
  2379. \term{method}. Each required argument, as specified in the \param{gf-lambda-list}
  2380. argument, must be included exactly once as a \param{parameter-name}
  2381. so that the full and unambiguous precedence order is
  2382. supplied. If this condition is not met, an error is signaled.
  2383. \reviewer{Barmar: What is the default order?}
  2384. \itemitem{\bull}
  2385. The \misc{declare} option is used to specify declarations that pertain
  2386. to the \term{generic function}.
  2387. An \declref{optimize} \term{declaration specifier} is allowed.
  2388. It specifies whether method selection should be optimized for
  2389. speed or space, but it has no effect on \term{methods}.
  2390. To control how a \term{method} is optimized, an \declref{optimize}
  2391. declaration must be placed directly in the \macref{defmethod} \term{form}
  2392. or method description. The optimization qualities \misc{speed} and
  2393. \misc{space} are the only qualities this standard requires, but an
  2394. implementation can extend the \CLOS\ to recognize other qualities.
  2395. A simple implementation that has only one method selection technique
  2396. and ignores \declref{optimize} \term{declaration specifiers} is valid.
  2397. The \declref{special}, \declref{ftype}, \declref{function}, \declref{inline},
  2398. \declref{notinline}, and \declref{declaration} declarations are not permitted.
  2399. Individual implementations can extend the \misc{declare} option to
  2400. support additional declarations.
  2401. \editornote{KMP: Does ``additional'' mean including special, ftype, etc.?
  2402. Or only other things that are not mentioned here?}
  2403. If an implementation notices a \term{declaration specifier} that it does
  2404. not support and that has not been proclaimed as a non-standard
  2405. \term{declaration identifier} name in a \declref{declaration} \term{proclamation},
  2406. it should issue a warning. \editornote{KMP: The wording of this previous sentence,
  2407. particularly the word ``and'' suggests to me that you can `proclaim declaration'
  2408. of an unsupported declaration (e.g., ftype) in order to suppress the warning.
  2409. That seems wrong. Perhaps it instead means to say ``does not support or
  2410. is both undefined and not proclaimed declaration.''}
  2411. \issue{DEFGENERIC-DECLARE:ALLOW-MULTIPLE}
  2412. The \misc{declare} option may be specified more than once.
  2413. The effect is the same as if the lists of \term{declaration specifiers}
  2414. had been appended together into a single list and specified as a
  2415. single \misc{declare} option.
  2416. \endissue{DEFGENERIC-DECLARE:ALLOW-MULTIPLE}
  2417. \itemitem{\bull}
  2418. The \kwd{documentation} argument is a \term{documentation string}
  2419. to be attached to the \term{generic function} \term{object},
  2420. and to be attached with kind \misc{function} to the \param{function-name}.
  2421. \itemitem{\bull}
  2422. The \kwd{generic-function-class} option may be used to specify that
  2423. the \term{generic function} is to have a different \term{class} than
  2424. the default provided by the system (\theclass{standard-generic-function}).
  2425. The \param{class-name} argument is the name of a \term{class} that can be the
  2426. \term{class} of a \term{generic function}. If \param{function-name} specifies
  2427. an existing \term{generic function} that has a different value for the
  2428. \kwd{generic-function-class} argument and the new generic function
  2429. \term{class} is compatible with the old, \funref{change-class} is called
  2430. to change the \term{class} of the \term{generic function};
  2431. otherwise an error is signaled.
  2432. \itemitem{\bull}
  2433. The \kwd{method-class} option is used to specify that all \term{methods} on
  2434. this \term{generic function} are to have a different \term{class} from the
  2435. default provided by the system (\theclass{standard-method}).
  2436. The \param{class-name} argument is the name of a \term{class} that is capable
  2437. of being the \term{class} of a \term{method}.
  2438. \reviewer{Barmar: Is \funref{change-class} called on existing methods?}
  2439. \itemitem{\bull}
  2440. The \kwd{method-combination} option is followed by a symbol that
  2441. names a type of method combination. The arguments (if any) that
  2442. follow that symbol depend on the type of method combination. Note
  2443. that the standard method combination type does not support any
  2444. arguments. However, all types of method combination defined by the
  2445. short form of \macref{define-method-combination} accept an optional
  2446. argument named \param{order}, defaulting to \kwd{most-specific-first},
  2447. where a value of \kwd{most-specific-last} reverses
  2448. the order of the primary \term{methods} without affecting the order of the
  2449. auxiliary \term{methods}.
  2450. \endlist
  2451. The \param{method-description} arguments define \term{methods} that will
  2452. be associated with the \term{generic function}. The \param{method-qualifier}
  2453. and \param{specialized-lambda-list} arguments in a method description
  2454. are the same as for \macref{defmethod}.
  2455. The \param{form} arguments specify the method body. The body of the
  2456. \term{method} is enclosed in an \term{implicit block}.
  2457. If \param{function-name} is a \term{symbol}, this block bears the same name as
  2458. the \term{generic function}. If \param{function-name} is a
  2459. \term{list} of the
  2460. form {\tt (setf \param{symbol})}, the name of the block is \param{symbol}.
  2461. Implementations can extend \macref{defgeneric} to include other options.
  2462. It is required that an implementation signal an error if
  2463. it observes an option that is not implemented locally.
  2464. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  2465. \macref{defgeneric} is not required to perform any compile-time side effects.
  2466. In particular, the \term{methods} are not installed for invocation during
  2467. compilation. An \term{implementation} may choose to store information about
  2468. the \term{generic function} for the purposes of compile-time error-checking
  2469. (such as checking the number of arguments on calls, or noting that a definition
  2470. for the function name has been seen).
  2471. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  2472. \label Examples::
  2473. \label Affected By:\None.
  2474. \label Exceptional Situations::
  2475. If \param{function-name} names an \term{ordinary function}, a \term{macro},
  2476. or a \term{special operator}, an error \oftype{program-error} is signaled.
  2477. Each required argument, as specified in the \param{gf-lambda-list}
  2478. argument, must be included exactly once as a \param{parameter-name},
  2479. or an error \oftype{program-error} is signaled.
  2480. The \term{lambda list} of each \term{method} specified by a
  2481. \param{method-description} must be congruent with the \term{lambda list} specified
  2482. by the \param{gf-lambda-list} option, or
  2483. an error \oftype{error} is signaled.
  2484. If a \macref{defgeneric} form is evaluated and some \term{methods} for
  2485. that \term{generic function} have \term{lambda lists} that are not congruent with
  2486. that given in the \macref{defgeneric} form,
  2487. an error \oftype{error} is signaled.
  2488. A given \param{option} may occur only once,
  2489. or an error \oftype{program-error} is signaled.
  2490. \reviewer{Barmar: This says that an error is signaled if you specify the same generic
  2491. function class as it already has!}
  2492. If \param{function-name} specifies an existing \term{generic function}
  2493. that has a different value for the \kwd{generic-function-class}
  2494. argument and the new generic function \term{class} is compatible with the
  2495. old, \funref{change-class} is called to change the \term{class} of
  2496. the \term{generic function}; otherwise an error \oftype{error} is signaled.
  2497. Implementations can extend \macref{defgeneric} to include other options.
  2498. It is required that an implementation
  2499. signal an error \oftype{program-error} if
  2500. it observes an option that is not implemented locally.
  2501. \label See Also::
  2502. \macref{defmethod},
  2503. \funref{documentation},
  2504. \funref{ensure-generic-function},
  2505. \issue{GENERIC-FUNCTION-POORLY-DESIGNED:DELETE}
  2506. %\macref{generic-function},
  2507. \typeref{generic-function},
  2508. \endissue{GENERIC-FUNCTION-POORLY-DESIGNED:DELETE}
  2509. {\secref\GFMethodLambdaListCongruency}
  2510. \label Notes:\None.
  2511. \endissue{DECLS-AND-DOC}
  2512. \endcom
  2513. %%% ========== DEFMETHOD
  2514. \begincom{defmethod}\ftype{Macro}
  2515. \issue{DECLS-AND-DOC}
  2516. \label Syntax::
  2517. %!!! Barmar: \macref{defun} and \macref{defmacro} don't bother to show this detail
  2518. % for the specialized lambda list, so why does \macref{defmethod}?
  2519. \DefmacWithValuesNewline {defmethod}
  2520. {\vtop{\hbox{\i{function-name}
  2521. \star{\curly{\i{method-qualifier}}}
  2522. \i{specialized-lambda-list}}
  2523. \hbox{{\DeclsAndDoc} \starparam{form}}}}
  2524. {new-method}
  2525. \Vskip1pc!\null
  2526. \i{function-name}::$=$ \curly{\term{symbol}
  2527. $\vert$ {\tt (setf \term{symbol})}}
  2528. \Vskip1pc!\null
  2529. \i{method-qualifier}::$=$ \term{non-list}
  2530. \Vskip1pc!\null
  2531. \settabs\+\hskip\leftskip&\cr
  2532. \+&\i{specialized-lambda-list}::$=$
  2533. (&\star{\curly{\param{var} $\vert$ {\rm (}{\param{var}
  2534. \i{parameter-specializer-name}}{\rm )}}} \cr
  2535. \+&&\ttbrac{{\opt}
  2536. \star{\curly{\param{var} $\vert$ {\rm (}var
  2537. \ttbrac{\param{initform} {\brac{\param{supplied-p-parameter}}} }{\rm )}}}} \cr
  2538. \+&&\ttbrac{{\tt\&rest} \param{var}} \cr
  2539. \+&&{\tt \lbracket}{\key{}}&\star{\curly{\param{var} $\vert$
  2540. {\rm (}\curly{\param{var} $\vert$ {\rm (}\term{keyword}\param{var}{\rm )}}
  2541. \ttbrac{\param{initform} \brac{\param{supplied-p-parameter}} }{\rm )}}}\cr
  2542. \+&&&\brac{\keyref{allow-other-keys}} {\tt \rbracket} \cr
  2543. \+&&\ttbrac{{\tt\&aux}
  2544. \star{\curly{\param{var} $\vert$ {\rm (}\param{var}
  2545. \brac{\param{initform}} {\rm )}}}} {\rm )} \cr
  2546. \Vskip1pc!\null
  2547. \+&\i{parameter-specializer-name}::$=$ \term{symbol}
  2548. $\vert$ {\rm (}{\tt eql} \param{eql-specializer-form}{\rm )}\cr
  2549. \Vskip 1pc!
  2550. \label Arguments and Values::
  2551. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  2552. \param{documentation}---a \term{string}; \noeval.
  2553. \param{var}---a \term{variable} \term{name}.
  2554. \param{eql-specializer-form}---a \term{form}.
  2555. \param{Form}---a \term{form}.
  2556. \param{Initform}---a \term{form}.
  2557. \param{Supplied-p-parameter}---variable name.
  2558. \param{new-method}---the new \term{method} \term{object}.
  2559. \label Description::
  2560. The macro \macref{defmethod} defines a \term{method} on a
  2561. \term{generic function}.
  2562. %!!! Rewrite to use "fbound" ?
  2563. If {\tt (fboundp \i{function-name})} is \nil, a
  2564. \term{generic function} is created with default values for
  2565. the argument precedence order
  2566. (each argument is more specific than the arguments to its right
  2567. in the argument list),
  2568. for the generic function class (\theclass{standard-generic-function}),
  2569. for the method class (\theclass{standard-method}),
  2570. and for the method combination type (the standard method combination type).
  2571. The \term{lambda list} of the \term{generic function} is
  2572. congruent with the \term{lambda list} of the
  2573. \term{method} being defined; if the
  2574. \macref{defmethod} form mentions keyword arguments, the \term{lambda list} of
  2575. the \term{generic function}
  2576. will mention {\tt &key} (but no keyword
  2577. arguments). If \i{function-name} names
  2578. an \term{ordinary function},
  2579. a \term{macro}, or a \term{special operator},
  2580. an error is signaled.
  2581. If a \term{generic function} is currently named by {\it function-name},
  2582. the \term{lambda list} of the
  2583. \term{method} must be congruent with the \term{lambda list} of the
  2584. \term{generic function}.
  2585. If this condition does not hold, an error is signaled.
  2586. For a definition of congruence in this context, \seesection\GFMethodLambdaListCongruency.
  2587. %% gray says redundant with syntax spec.
  2588. %If \i{function-name} is a \term{list},
  2589. %it must be of the form {\tt (setf \i{symbol})}.
  2590. %\i{Function-name} names the \term{generic function}
  2591. %on which the \term{method} is defined.
  2592. Each \i{method-qualifier} argument is an \term{object} that is used by
  2593. method combination to identify the given \term{method}.
  2594. The method combination type might further
  2595. restrict what a method \term{qualifier} can be.
  2596. The standard method combination type allows for \term{unqualified methods} and
  2597. \term{methods} whose sole
  2598. \term{qualifier} is one of the keywords \kwd{before}, \kwd{after}, or \kwd{around}.
  2599. The \i{specialized-lambda-list} argument is like an ordinary
  2600. \term{lambda list} except that the \term{names} of required parameters can
  2601. be replaced by specialized parameters. A specialized parameter is a
  2602. list of the form
  2603. \f{(\param{var} \i{parameter-specializer-name})}.
  2604. Only required parameters can be
  2605. specialized. If \i{parameter-specializer-name} is a \term{symbol} it names a
  2606. \term{class}; if it is a \term{list},
  2607. it is of the form \f{(eql \param{eql-specializer-form})}. The parameter
  2608. specializer name \f{(eql \param{eql-specializer-form})} indicates
  2609. that the corresponding argument must be \funref{eql} to the \term{object} that
  2610. is the value of \param{eql-specializer-form} for the \term{method} to be applicable.
  2611. %%gray/moon addition
  2612. The \param{eql-specializer-form} is evaluated at the time
  2613. that the expansion of the \macref{defmethod} macro is evaluated.
  2614. %%
  2615. If no \term{parameter specializer name} is specified for a given
  2616. required parameter, the \term{parameter specializer} defaults to
  2617. \theclass{t}.
  2618. For further discussion, \seesection\IntroToMethods.
  2619. The \param{form} arguments specify the method body.
  2620. The body of the \term{method} is enclosed in an \term{implicit block}. If
  2621. \i{function-name} is a \term{symbol},
  2622. this block bears the same \term{name} as the \term{generic function}.
  2623. If \i{function-name} is a \term{list} of the form
  2624. {\tt (setf \i{symbol})}, the \term{name} of the block is \i{symbol}.
  2625. The \term{class} of the \term{method} \term{object} that is created is that given by the
  2626. method class option of the \term{generic function}
  2627. on which the \term{method} is defined.
  2628. If the \term{generic function} already has a \term{method} that agrees with the
  2629. \term{method} being defined on \term{parameter specializers} and \term{qualifiers},
  2630. \macref{defmethod} replaces the existing \term{method} with the one now being
  2631. defined.
  2632. For a definition of agreement in this context.
  2633. \seesection\SpecializerQualifierAgreement.
  2634. The \term{parameter specializers} are derived from
  2635. the \term{parameter specializer names} as described in
  2636. \secref\IntroToMethods.
  2637. The expansion of the \macref{defmethod} macro ``refers to'' each
  2638. specialized parameter (see the description of \declref{ignore}
  2639. within the description of \misc{declare}).
  2640. This includes parameters that
  2641. have an explicit \term{parameter specializer name} of \t. This means
  2642. that a compiler warning does not occur if the body of the \term{method} does
  2643. not refer to a specialized parameter, while a warning might occur
  2644. if the body of the \term{method} does not refer to an unspecialized parameter.
  2645. For this reason, a parameter that specializes on \t\ is not quite synonymous
  2646. with an unspecialized parameter in this context.
  2647. \issue{DEFMETHOD-DECLARATION-SCOPE:CORRESPONDS-TO-BINDINGS}
  2648. Declarations at the head of the method body that apply to the
  2649. method's \term{lambda variables} are treated as \term{bound declarations}
  2650. whose \term{scope} is the same as the corresponding \term{bindings}.
  2651. Declarations at the head of the method body that apply to the
  2652. functional bindings of \funref{call-next-method} or \funref{next-method-p}
  2653. apply to references to those functions within the method body \param{forms}.
  2654. Any outer \term{bindings} of the \term{function names} \funref{call-next-method} and
  2655. \funref{next-method-p}, and declarations associated with such \term{bindings}
  2656. are \term{shadowed}\meaning{2} within the method body \param{forms}.
  2657. The \term{scope} of \term{free declarations} at the head of the method body
  2658. is the entire method body,
  2659. which includes any implicit local function definitions
  2660. but excludes \term{initialization forms} for the \term{lambda variables}.
  2661. \endissue{DEFMETHOD-DECLARATION-SCOPE:CORRESPONDS-TO-BINDINGS}
  2662. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  2663. \macref{defmethod} is not required to perform any compile-time side effects.
  2664. In particular, the \term{methods} are not installed for invocation during
  2665. compilation. An \term{implementation} may choose to store information about
  2666. the \term{generic function} for the purposes of compile-time error-checking
  2667. (such as checking the number of arguments on calls, or noting that a definition
  2668. for the function name has been seen).
  2669. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  2670. \issue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  2671. \param{Documentation} is attached as a \term{documentation string}
  2672. to the \term{method} \term{object}.
  2673. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  2674. \label Examples:\None.
  2675. \label Affected By::
  2676. The definition of the referenced \term{generic function}.
  2677. \label Exceptional Situations::
  2678. If \i{function-name} names an \term{ordinary function},
  2679. a \term{macro}, or a \term{special operator},
  2680. an error \oftype{error} is signaled.
  2681. If a \term{generic function} is currently named by {\it function-name},
  2682. the \term{lambda list} of the
  2683. \term{method} must be congruent with the \term{lambda list} of the
  2684. \term{generic function}, or
  2685. an error \oftype{error} is signaled.
  2686. %% gray addition
  2687. %Also get an error for an undefined specializer class.
  2688. \label See Also::
  2689. \macref{defgeneric},
  2690. \funref{documentation},
  2691. {\secref\IntroToMethods},
  2692. {\secref\GFMethodLambdaListCongruency},
  2693. {\secref\SpecializerQualifierAgreement},
  2694. {\secref\DocVsDecls}
  2695. \label Notes:\None.
  2696. \endissue{DECLS-AND-DOC}
  2697. \endcom
  2698. %%% ========== FIND-CLASS
  2699. \begincom{find-class}\ftype{Accessor}
  2700. \label Syntax::
  2701. \DefunWithValues find-class {symbol {\opt} errorp environment} {class}
  2702. \Defsetf find-class {symbol {\opt} errorp environment} {new-class}
  2703. \label Arguments and Values::
  2704. \param{symbol}---a \term{symbol}.
  2705. \param{errorp}---a \term{generalized boolean}.
  2706. \Default{\term{true}}
  2707. \param{environment} -- same as the \keyref{environment} argument to
  2708. macro expansion functions and is used to distinguish between
  2709. compile-time and run-time environments.
  2710. \issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  2711. The \keyref{environment} argument has
  2712. \term{dynamic extent}; the consequences are undefined if
  2713. the \keyref{environment} argument is
  2714. referred to outside the \term{dynamic extent}
  2715. of the macro expansion function.
  2716. \endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  2717. %!!! Default?
  2718. \param{class}---a \term{class} \term{object}, or \nil.
  2719. \label Description::
  2720. Returns the \term{class} \term{object} named by the \param{symbol}
  2721. in the \param{environment}. If there is no such \term{class},
  2722. \nil\ is returned if \param{errorp} is \term{false}; otherwise,
  2723. if \param{errorp} is \term{true}, an error is signaled.
  2724. The \term{class} associated with a particular \term{symbol} can be changed by using
  2725. \macref{setf} with \funref{find-class};
  2726. \issue{SETF-FIND-CLASS:ALLOW-NIL}
  2727. or, if the new \term{class} given to \macref{setf} is \nil,
  2728. the \term{class} association is removed
  2729. (but the \term{class} \term{object} itself is not affected).
  2730. \endissue{SETF-FIND-CLASS:ALLOW-NIL}
  2731. The results are undefined if the user attempts to change
  2732. \issue{SETF-FIND-CLASS:ALLOW-NIL}
  2733. or remove
  2734. \endissue{SETF-FIND-CLASS:ALLOW-NIL}
  2735. the \term{class} associated with a
  2736. \term{symbol} that is defined as a \term{type specifier} in this standard.
  2737. \Seesection\IntegratingTypesAndClasses.
  2738. When using \SETFof{find-class}, any \term{errorp} argument is \term{evaluated}
  2739. for effect, but any \term{values} it returns are ignored; the \param{errorp}
  2740. \term{parameter} is permitted primarily so that the \param{environment} \term{parameter}
  2741. can be used.
  2742. The \param{environment} might be used to distinguish between a compile-time and a
  2743. run-time environment.
  2744. \label Examples:\None.
  2745. \label Affected By:\None.
  2746. \label Exceptional Situations::
  2747. If there is no such \term{class} and \param{errorp} is \term{true},
  2748. \funref{find-class} signals an error \oftype{error}.
  2749. \label See Also::
  2750. \macref{defmacro},
  2751. {\secref\IntegratingTypesAndClasses}
  2752. \label Notes:\None.
  2753. \endcom
  2754. %%% ========== NEXT-METHOD-P
  2755. \begincom{next-method-p}\ftype{Local Function}
  2756. \label Syntax::
  2757. \DefunWithValues next-method-p {\noargs} {generalized-boolean}
  2758. \label Arguments and Values::
  2759. \param{generalized-boolean}---a \term{generalized boolean}.
  2760. \label Description::
  2761. The locally defined function \funref{next-method-p} can be used
  2762. \issue{METHOD-INITFORM:FORBID-CALL-NEXT-METHOD}
  2763. within the body \term{forms} (but not the \term{lambda list})
  2764. \endissue{METHOD-INITFORM:FORBID-CALL-NEXT-METHOD}
  2765. defined by a \term{method-defining form} to determine
  2766. whether a next \term{method} exists.
  2767. \Thefunction{next-method-p} has \term{lexical scope} and \term{indefinite extent}.
  2768. \issue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  2769. Whether or not \funref{next-method-p} is \term{fbound} in the
  2770. \term{global environment} is \term{implementation-dependent};
  2771. however, the restrictions on redefinition and \term{shadowing} of
  2772. \funref{next-method-p} are the same as for \term{symbols} in \thepackage{common-lisp}
  2773. which are \term{fbound} in the \term{global environment}.
  2774. The consequences of attempting to use \funref{next-method-p} outside
  2775. of a \term{method-defining form} are undefined.
  2776. \endissue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  2777. \label Examples:\None.
  2778. \label Affected By:\None.
  2779. \label Exceptional Situations:\None.
  2780. \label See Also::
  2781. \funref{call-next-method},
  2782. \macref{defmethod},
  2783. \macref{call-method}
  2784. \label Notes:\None.
  2785. \endcom
  2786. %%% ========== CALL-METHOD
  2787. %%% ========== MAKE-METHOD
  2788. %!!! ACW wonders if one of these is a Local Function.
  2789. \begincom{call-method, make-method}\ftype{Local Macro}
  2790. \label Syntax::
  2791. \DefmacWithValues call-method {method {\optional} next-method-list} {\starparam{result}}
  2792. \DefmacWithValues make-method {form} {method-object}
  2793. \label Arguments and Values::
  2794. % Moon notes that arguments are not evaluated.
  2795. \param{method}---a \term{method} \term{object},
  2796. or a \term{list} (see below); \noeval.
  2797. \param{method-object}---a \term{method} \term{object}.
  2798. \param{next-method-list}---a \term{list} of \param{method} \term{objects}; \noeval.
  2799. \param{results}---the \term{values} returned by the \term{method} invocation.
  2800. \label Description::
  2801. The macro \macref{call-method} is used in method combination. It hides
  2802. the \term{implementation-dependent} details of how
  2803. \term{methods} are called. The
  2804. macro \macref{call-method} has \term{lexical scope} and
  2805. can only be used within
  2806. an \term{effective method} \term{form}.
  2807. \editornote{KMP: This next paragraph still needs some work.}%!!!
  2808. \issue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  2809. Whether or not \macref{call-method} is \term{fbound} in the
  2810. \term{global environment} is \term{implementation-dependent};
  2811. however, the restrictions on redefinition and \term{shadowing} of
  2812. \macref{call-method} are the same as for \term{symbols} in \thepackage{common-lisp}
  2813. which are \term{fbound} in the \term{global environment}.
  2814. The consequences of attempting to use \macref{call-method} outside
  2815. of an \term{effective method} \term{form} are undefined.
  2816. \endissue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  2817. % Description of arguments in this paragraph changed by Moon:
  2818. % Description of next-methods in this paragraph shortened by Moon:
  2819. The macro \macref{call-method} invokes the specified \term{method},
  2820. supplying it with arguments and with definitions for
  2821. \funref{call-next-method} and for \funref{next-method-p}.
  2822. If the invocation of \macref{call-method} is lexically inside
  2823. of a \funref{make-method}, the arguments are those that
  2824. were supplied to that method. Otherwise the arguments are
  2825. those that were supplied to the generic function.
  2826. The definitions
  2827. of \funref{call-next-method} and \funref{next-method-p} rely on
  2828. the specified \param{next-method-list}.
  2829. If \param{method} is a \term{list}, the first element of the \term{list}
  2830. must be the symbol \funref{make-method} and the second element must be
  2831. a \term{form}. Such a \term{list} specifies a \term{method} \term{object}
  2832. whose \term{method} function has a body that is the given \term{form}.
  2833. \param{Next-method-list} can contain \term{method} \term{objects} or \term{lists},
  2834. the first element of which must be the symbol \funref{make-method} and the
  2835. second element of which must be a \term{form}.
  2836. % Added by Moon:
  2837. Those are the only two places where \funref{make-method} can be used.
  2838. The \term{form} used with \funref{make-method} is evaluated in
  2839. the \term{null lexical environment} augmented with a local macro definition
  2840. for \macref{call-method} and with bindings named by
  2841. symbols not \term{accessible} from \thepackage{common-lisp-user}.
  2842. The \funref{call-next-method} function available to \param{method}
  2843. will call the first \term{method} in \param{next-method-list}.
  2844. The \funref{call-next-method} function
  2845. available in that \term{method}, in turn, will call the second
  2846. \term{method} in \param{next-method-list}, and so on, until
  2847. the list of next \term{methods} is exhausted.
  2848. %%--Changed in drafting committee by Moon
  2849. If \param{next-method-list} is not supplied, the
  2850. \funref{call-next-method} function available to
  2851. \param{method} signals an error \oftype{control-error}
  2852. and the \funref{next-method-p} function
  2853. available to \param{method} returns {\nil}.
  2854. \label Examples::
  2855. %!!! Barmar: This desperately needs examples.
  2856. % I have a hard time understanding the use of MAKE-METHOD.
  2857. \label Affected By:\None.
  2858. \label Exceptional Situations:\None.
  2859. \label See Also::
  2860. \funref{call-next-method},
  2861. \macref{define-method-combination},
  2862. \funref{next-method-p}
  2863. \label Notes:\None.
  2864. \endcom
  2865. %%% ========== CALL-NEXT-METHOD
  2866. \begincom{call-next-method}\ftype{Local Function}
  2867. \label Syntax::
  2868. \DefunWithValues call-next-method {{\rest} args} {\starparam{result}}
  2869. \label Arguments and Values::
  2870. \param{arg}---an \term{object}.
  2871. % These are objects that are appropriate as args to the methods.
  2872. \param{results}---the \term{values} returned by the \term{method} it calls.
  2873. \label Description::
  2874. \Thefunction{call-next-method} can be used
  2875. \issue{METHOD-INITFORM:FORBID-CALL-NEXT-METHOD}
  2876. within the body \term{forms} (but not the \term{lambda list})
  2877. \endissue{METHOD-INITFORM:FORBID-CALL-NEXT-METHOD}
  2878. of a \term{method} defined by a \term{method-defining form} to call the
  2879. \term{next method}.
  2880. If there is no next \term{method}, the generic function
  2881. \funref{no-next-method} is called.
  2882. The type of method combination used determines which \term{methods}
  2883. can invoke \funref{call-next-method}. The standard
  2884. \term{method combination} type allows \funref{call-next-method}
  2885. to be used within primary \term{methods} and \term{around methods}.
  2886. %%Barmar thinks this is not needed because it is said elsewhere (ch4.1). -kmp 22-Dec-90
  2887. % The standard
  2888. % \term{method combination}
  2889. % type defines the next \term{method} as follows:
  2890. %
  2891. % \beginlist
  2892. % \itemitem{\bull}
  2893. % If \funref{call-next-method} is used in an \term{around method},
  2894. % the next \term{method} is the next most specific \term{around method}, if one is
  2895. % applicable.
  2896. %
  2897. % \itemitem{\bull}
  2898. % If there are no \term{around methods} at all or if
  2899. % \funref{call-next-method} is called by the least specific \term{around method},
  2900. % other \term{methods} are called as follows:
  2901. % \beginlist
  2902. % \itemitem{--} All the \term{before methods} are called, in
  2903. % most-specific-first order. \Thefunction{call-next-method}
  2904. % cannot be used in \term{before methods}.
  2905. %
  2906. % \itemitem{--}
  2907. % The most specific primary \term{method} is called. Inside the body of a
  2908. % primary \term{method}, \funref{call-next-method} can be used to pass control to
  2909. % the next most specific primary \term{method}. The generic function
  2910. % \funref{no-next-method} is called if \funref{call-next-method} is used and there
  2911. % are no more primary \term{methods}.
  2912. %
  2913. % \itemitem{--} All the \term{after methods} are called in
  2914. % most-specific-last order. \Thefunction{call-next-method}
  2915. % cannot be used in \term{after methods}.
  2916. %
  2917. % \endlist
  2918. % \endlist
  2919. %
  2920. For generic functions using a type of method combination defined by
  2921. the short form of \macref{define-method-combination},
  2922. \funref{call-next-method} can be used in \term{around methods} only.
  2923. When \funref{call-next-method} is called with no arguments, it passes the
  2924. current \term{method}'s original arguments to the next \term{method}. Neither
  2925. argument defaulting, nor using \specref{setq}, nor rebinding variables
  2926. with the same \term{names} as parameters of the \term{method} affects the values
  2927. \funref{call-next-method} passes to the \term{method} it calls.
  2928. % A sentence was removed here by Moon since it was duplicated below, and another
  2929. % sentence was moved to be next to the duplicate:
  2930. When \funref{call-next-method} is called with arguments, the
  2931. \term{next method} is called with those arguments.
  2932. If \funref{call-next-method} is called with arguments but omits
  2933. optional arguments, the \term{next method} called defaults those arguments.
  2934. % Further computation is possible after \funref{call-next-method} returns.
  2935. \Thefunction{call-next-method} returns any \term{values} that are
  2936. returned by the \term{next method}.
  2937. \Thefunction{call-next-method} has \term{lexical scope} and
  2938. \term{indefinite extent} and can only be used within the body of a
  2939. \term{method} defined by a \term{method-defining form}.
  2940. \issue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  2941. Whether or not \funref{call-next-method} is \term{fbound} in the
  2942. \term{global environment} is \term{implementation-dependent};
  2943. however, the restrictions on redefinition and \term{shadowing} of
  2944. \funref{call-next-method} are the same as for \term{symbols} in \thepackage{common-lisp}
  2945. which are \term{fbound} in the \term{global environment}.
  2946. The consequences of attempting to use \funref{call-next-method} outside
  2947. of a \term{method-defining form} are undefined.
  2948. \endissue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  2949. \label Examples:\None.
  2950. \label Affected By::
  2951. \macref{defmethod}, \macref{call-method}, \funref{define-method-combination}.
  2952. \label Exceptional Situations::
  2953. % Grammar improved by Moon:
  2954. %% Removed per X3J13. -kmp 05-Oct-93
  2955. % If \funref{call-next-method} is used in a \term{method} whose
  2956. % \term{method combination} does not support it,
  2957. % an error \oftype{control-error} is \term{signaled}.
  2958. When providing arguments to \funref{call-next-method},
  2959. the following rule must be satisfied or an error \oftype{error}
  2960. %% "is" => "should be" per X3J13. -kmp 05-Oct-93
  2961. %is
  2962. should be
  2963. signaled:
  2964. the ordered set of \term{applicable methods} for a changed set of arguments
  2965. for \funref{call-next-method} must be the same as the ordered set of
  2966. \term{applicable methods} for the original arguments to the
  2967. \term{generic function}.
  2968. Optimizations of the error checking are possible, but they must not change
  2969. the semantics of \funref{call-next-method}.
  2970. \label See Also::
  2971. \macref{define-method-combination},
  2972. \macref{defmethod},
  2973. \funref{next-method-p},
  2974. \funref{no-next-method},
  2975. \macref{call-method},
  2976. {\secref\MethodSelectionAndCombination},
  2977. {\secref\StdMethComb},
  2978. {\secref\BuiltInMethCombTypes}
  2979. \label Notes:\None.
  2980. \endcom
  2981. %%% ========== COMPUTE-APPLICABLE-METHODS
  2982. \begincom{compute-applicable-methods}\ftype{Standard Generic Function}
  2983. \issue{COMPUTE-APPLICABLE-METHODS:GENERIC}
  2984. \label Syntax::
  2985. \DefgenWithValues compute-applicable-methods {generic-function function-arguments} {methods}
  2986. \label Method Signatures::
  2987. \Defmeth compute-applicable-methods {\specparam{generic-function}{standard-generic-function}}
  2988. \endissue{COMPUTE-APPLICABLE-METHODS:GENERIC}
  2989. \label Arguments and Values::
  2990. \param{generic-function}---a \term{generic function}.
  2991. \param{function-arguments}---a \term{list} of arguments for the \param{generic-function}.
  2992. \param{methods}---a \term{list} of \term{method} \term{objects}.
  2993. \label Description::
  2994. Given a \param{generic-function} and a set of
  2995. \param{function-arguments}, the function
  2996. \funref{compute-applicable-methods} returns the set of \term{methods}
  2997. that are applicable for those arguments
  2998. sorted according to precedence order.
  2999. \Seesection\MethodSelectionAndCombination.
  3000. \label Affected By::
  3001. \macref{defmethod}
  3002. \label Exceptional Situations:\None.
  3003. \label See Also::
  3004. {\secref\MethodSelectionAndCombination}
  3005. \label Notes:\None.
  3006. \endcom
  3007. %%% ========== DEFINE-METHOD-COMBINATION
  3008. \begincom{define-method-combination}\ftype{Macro}
  3009. \issue{DECLS-AND-DOC}
  3010. \label Syntax::
  3011. % 88-002R p.2-34 said "new method combination object" was returned, but it's wrong,
  3012. % method-combination objects are created by the defgeneric :method-combination option.
  3013. % See 88-002R p.1-28. --Moon
  3014. % The "name" is returned.
  3015. % Barrett didn't believe this at first, but now does.
  3016. % Consensus comes slowly.
  3017. \DefmacWithValuesNewline define-method-combination
  3018. {name \interleave{\down{short-form-option}}}
  3019. {name}
  3020. \DefmacWithValuesNewline define-method-combination
  3021. {\vtop{\hbox{name lambda-list}
  3022. \hbox{\paren{\starparam{method-group-specifier}}}
  3023. \hbox{\brac{\paren{\kwd{arguments} . args-lambda-list}}}
  3024. \hbox{\brac{\paren{\kwd{generic-function}
  3025. generic-function-symbol}}}
  3026. \hbox{\DeclsAndDoc}
  3027. \hbox{\starparam{form}}}}
  3028. {name}
  3029. \auxbnf{short-form-option}{\kwd{documentation} \param{documentation} | \CR
  3030. \kwd{identity-with-one-argument}
  3031. \param{identity-with-one-argument} |\CR
  3032. \kwd{operator} \param{operator}}
  3033. \auxbnf{method-group-specifier}{\paren{name
  3034. \curly{\plusparam{qualifier-pattern} $\vert$ predicate}
  3035. \interleave{\down{long-form-option}}}}
  3036. \auxbnf{long-form-option}{\kwd{description} \param{description} |\CR
  3037. \kwd{order} \param{order} |\CR
  3038. \kwd{required} \param{required-p}}
  3039. \label Arguments and Values::
  3040. \param{args-lambda-list}---%
  3041. %Moon thought :arguments for DEFINE-METHOD-COMBINATION took an ordinary lambda list,
  3042. %but Barrett (comment #3, first public review) observes that &whole is permissible.
  3043. %Time to make a new kind of list.
  3044. a \term{define-method-combination arguments lambda list}.
  3045. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  3046. \param{description}---a \term{format control}.
  3047. \param{documentation}---a \term{string}; \noeval.
  3048. \param{forms}---an \term{implicit progn}
  3049. that must compute and return the \term{form} that specifies how
  3050. the \term{methods} are combined, that is, the \term{effective method}.
  3051. \param{generic-function-symbol}---a \term{symbol}.
  3052. \param{identity-with-one-argument}---a \term{generalized boolean}.
  3053. \param{lambda-list}---\term{ordinary lambda list}.
  3054. \param{name}---a \term{symbol}.
  3055. Non-\term{keyword}, \term{non-nil} \term{symbols} are usually used.
  3056. \param{operator}---an \term{operator}.
  3057. \param{Name} and \param{operator} are often the \term{same} \term{symbol}.
  3058. This is the default, but it is not required.
  3059. \param{order}---\kwd{most-specific-first} or \kwd{most-specific-last}; \eval.
  3060. %Not a function designator?
  3061. \param{predicate}---a \term{symbol} that names a \term{function} of one argument
  3062. that returns a \term{generalized boolean}.
  3063. \param{qualifier-pattern}---a \term{list},
  3064. or the \term{symbol} \misc{*}.
  3065. \param{required-p}---a \term{generalized boolean}.
  3066. \label Description::
  3067. The macro \macref{define-method-combination} is used to define new types
  3068. of method combination.
  3069. There are two forms of \macref{define-method-combination}. The short
  3070. form is a simple facility for the cases that are expected
  3071. to be most commonly needed. The long form is more powerful but more
  3072. verbose. It resembles \macref{defmacro} in that the body is an
  3073. expression, usually using backquote, that computes a \term{form}. Thus
  3074. arbitrary control structures can be implemented. The long form also
  3075. allows arbitrary processing of method \term{qualifiers}.
  3076. %In both the short and long forms, \param{name} is a symbol. By convention,
  3077. %non-keyword, \term{non-nil} symbols are usually used.
  3078. \beginlist
  3079. \itemitem{{\bf Short Form}}
  3080. The short form syntax of \macref{define-method-combination} is recognized
  3081. when the second \term{subform} is a \term{non-nil} symbol or is not present.
  3082. When the short form is used, \param{name} is defined as a type of
  3083. method combination that produces a Lisp form
  3084. \f{({\param{operator} \param{method-call} \param{method-call} $\ldots$})}.
  3085. The \param{operator} is a \term{symbol} that can be the \term{name} of a
  3086. \term{function}, \term{macro}, or \term{special operator}.
  3087. The \param{operator} can be supplied by a keyword option;
  3088. it defaults to \param{name}.
  3089. Keyword options for the short form are the following:
  3090. \beginlist
  3091. \itemitem{\bull}
  3092. The \kwd{documentation} option is used to document the method-combination type;
  3093. see description of long form below.
  3094. \itemitem{\bull}
  3095. The \kwd{identity-with-one-argument} option enables an optimization
  3096. when its value is \term{true} (the default is \term{false}). If there is
  3097. exactly one applicable method and it is a primary method, that method
  3098. serves as the effective method and \param{operator} is not called.
  3099. This optimization avoids the need to create a new effective method and
  3100. avoids the overhead of a \term{function} call. This option is designed to be
  3101. used with operators such as \specref{progn}, \macref{and}, \funref{$+$}, and
  3102. \funref{max}.
  3103. \itemitem{\bull}
  3104. The \kwd{operator} option specifies the \term{name} of the operator. The
  3105. \param{operator} argument is a \term{symbol} that can be the
  3106. \term{name} of a \term{function},
  3107. \term{macro}, or
  3108. \term{special form}.
  3109. %By convention, \param{name} and
  3110. %\param{operator} are often the same symbol. This is the default,
  3111. %but it is not required.
  3112. \endlist
  3113. %None of the \term{subforms} is evaluated.
  3114. These types of method combination require exactly one \term{qualifier} per
  3115. method. An error is signaled if there are applicable methods with no
  3116. \term{qualifiers} or with \term{qualifiers} that are not supported by
  3117. the method combination type.
  3118. A method combination procedure defined in this way recognizes two
  3119. roles for methods. A method whose one \term{qualifier} is the symbol naming
  3120. this type of method combination is defined to be a primary method. At
  3121. least one primary method must be applicable or an error is signaled.
  3122. A method with \kwd{around} as its one \term{qualifier} is an auxiliary
  3123. method that behaves the same as an \term{around method} in standard
  3124. method combination. \Thefunction{call-next-method} can only be
  3125. used in \term{around methods}; it cannot be used in primary methods
  3126. defined by the short form of the \macref{define-method-combination} macro.
  3127. A method combination procedure defined in this way accepts an optional
  3128. argument named \param{order}, which defaults to
  3129. \kwd{most-specific-first}. A value of \kwd{most-specific-last} reverses
  3130. the order of the primary methods without affecting the order of the
  3131. auxiliary methods.
  3132. The short form automatically includes error checking and support for
  3133. \term{around methods}.
  3134. For a discussion of built-in method combination types,
  3135. \seesection\BuiltInMethCombTypes.
  3136. \itemitem{{\bf Long Form}}
  3137. The long form syntax of \macref{define-method-combination} is recognized
  3138. when the second \term{subform} is a list.
  3139. The \param{lambda-list}
  3140. receives any arguments provided after the \term{name} of the method
  3141. combination type in the \kwd{method-combination} option to
  3142. \macref{defgeneric}.
  3143. A list of method group specifiers follows. Each specifier selects a subset
  3144. of the applicable methods to play a particular role, either by matching
  3145. their \term{qualifiers} against some patterns or by testing their \term{qualifiers} with
  3146. a \param{predicate}.
  3147. These method group specifiers define all method \term{qualifiers}
  3148. that can be used with this type of method combination.
  3149. % Removed by Moon as the same information is repeated below
  3150. %If an applicable
  3151. %method does not fall into any method group, the system signals the error
  3152. %that the method is invalid for the kind of method combination in use.
  3153. %%Rewritten per Barmar. -kmp 28-Dec-90
  3154. %Each method group specifier names a variable.
  3155. The \term{car} of each \param{method-group-specifier} is a \term{symbol}
  3156. which \term{names} a \term{variable}.
  3157. During the execution of
  3158. the \term{forms} in the body of \macref{define-method-combination}, this
  3159. \term{variable} is bound to a list of the \term{methods} in the method group. The
  3160. \term{methods} in this list occur in the order specified by the
  3161. \kwd{order} option.
  3162. If \param{qualifier-pattern} is a \term{symbol} it must be \misc{*}.
  3163. A method matches
  3164. a \param{qualifier-pattern} if the method's
  3165. list of \term{qualifiers} is \funref{equal}
  3166. to the \param{qualifier-pattern} (except that the symbol \misc{*} in a
  3167. \param{qualifier-pattern} matches anything). Thus
  3168. a \param{qualifier-pattern} can be one of the
  3169. following:
  3170. the \term{empty list}, which matches \term{unqualified methods};
  3171. the symbol \misc{*}, which matches all methods;
  3172. a true list, which matches methods with the same number of \term{qualifiers}
  3173. as the length of the list when each \term{qualifier} matches
  3174. the corresponding list element; or
  3175. a dotted list that ends in the symbol \misc{*}
  3176. (the \misc{*} matches any number of additional \term{qualifiers}).
  3177. Each applicable method is tested against the \param{qualifier-patterns} and
  3178. \param{predicates} in left-to-right order.
  3179. As soon as a \param{qualifier-pattern} matches
  3180. or a \param{predicate} returns true, the method becomes a member of the
  3181. corresponding method group and no further tests are made. Thus if a method
  3182. could be a member of more than one method group, it joins only the first
  3183. such group. If a method group has more than one
  3184. \param{qualifier-pattern}, a
  3185. method need only satisfy one of the \param{qualifier-patterns} to be a member of
  3186. the group.
  3187. The \term{name} of a \param{predicate} function can appear instead of
  3188. \param{qualifier-patterns} in a method group specifier.
  3189. The \param{predicate} is called for
  3190. each method that has not been assigned to an earlier method group; it
  3191. is called with one argument, the method's \term{qualifier} \term{list}.
  3192. The \param{predicate} should return true if the method is to be a member of the
  3193. method group. A \param{predicate} can be distinguished from a
  3194. \param{qualifier-pattern}
  3195. because it is a \term{symbol} other than \nil\ or \misc{*}.
  3196. % Wording improved --Moon
  3197. If there is an applicable method that does not fall into any method group,
  3198. \thefunction{invalid-method-error} is called.
  3199. Method group specifiers can have keyword options following the
  3200. \term{qualifier} patterns or predicate. Keyword options can be distinguished from
  3201. additional \term{qualifier} patterns because they are neither lists nor the symbol
  3202. \misc{*}. The keyword options are as follows:
  3203. \beginlist
  3204. \itemitem{\bull}
  3205. The \kwd{description} option is used to provide a description of the
  3206. role of methods in the method group. Programming environment tools
  3207. use
  3208. {\tt (apply \#'format stream \param{format-control} (method-qualifiers \param{method}))}
  3209. to print this description, which
  3210. is expected to be concise. This keyword
  3211. option allows the description of a method \term{qualifier} to be defined in
  3212. the same module that defines the meaning of the
  3213. method \term{qualifier}. In most cases, \param{format-control} will not contain any
  3214. \funref{format} directives, but they are available for generality.
  3215. If \kwd{description} is not supplied, a default description is generated
  3216. based on the variable name and the \term{qualifier} patterns and on whether
  3217. this method group includes the \term{unqualified methods}.
  3218. \itemitem{\bull}
  3219. The \kwd{order} option specifies the order of methods. The \param{order}
  3220. argument is a \term{form} that evaluates to
  3221. \kwd{most-specific-first} or \kwd{most-specific-last}. If it evaluates
  3222. to any other value, an error is signaled.
  3223. %This keyword option is a
  3224. %convenience and does not add any expressive power.
  3225. If \kwd{order} is not supplied, it defaults to
  3226. \kwd{most-specific-first}.
  3227. \itemitem{\bull}
  3228. The \kwd{required} option specifies whether at least one method in
  3229. this method group is required.
  3230. If its value is \term{true} and the method group is empty
  3231. (that is, no applicable methods match the \term{qualifier} patterns
  3232. or satisfy the predicate),
  3233. an error is signaled.
  3234. %This keyword option is a convenience and does not
  3235. %add any expressive power.
  3236. If \kwd{required} is not supplied,
  3237. it defaults to \nil.
  3238. \endlist
  3239. The use of method group specifiers provides a convenient syntax to
  3240. select methods, to divide them among the possible roles, and to perform the
  3241. necessary error checking. It is possible to perform further filtering
  3242. of methods in the body \term{forms} by using normal list-processing operations
  3243. and the functions \funref{method-qualifiers} and
  3244. \funref{invalid-method-error}. It is permissible to use \specref{setq} on the
  3245. variables named in the method group specifiers and to bind additional
  3246. variables. It is also possible to bypass the method group specifier
  3247. mechanism and do everything in the body \term{forms}. This is accomplished
  3248. by writing a single method group with \misc{*} as its only
  3249. \param{qualifier-pattern};
  3250. the variable is then bound to a \term{list} of all of the
  3251. \term{applicable methods}, in most-specific-first order.
  3252. % Modified by Moon to clarify lexical environment:
  3253. The body \param{forms} compute and return the \term{form} that specifies
  3254. how the methods are combined, that is, the effective method.
  3255. The effective method is evaluated in
  3256. the \term{null lexical environment} augmented with a local macro definition
  3257. for \funref{call-method} and with bindings named by
  3258. symbols not \term{accessible} from \thepackage{common-lisp-user}.
  3259. Given a method object in one of the
  3260. \term{lists} produced by the method group
  3261. specifiers and a \term{list} of next methods,
  3262. \funref{call-method}
  3263. will invoke the method such that \funref{call-next-method} has available
  3264. the next methods.
  3265. When an effective method has no effect other than to call a single
  3266. method, some implementations employ an optimization that uses the
  3267. single method directly as the effective method, thus avoiding the need
  3268. to create a new effective method. This optimization is active when
  3269. the effective method form consists entirely of an invocation of
  3270. the \funref{call-method} macro whose first \term{subform} is a method object and
  3271. whose second \term{subform} is \nil\ or unsupplied. Each
  3272. \macref{define-method-combination} body is responsible for stripping off
  3273. redundant invocations of \specref{progn}, \macref{and},
  3274. \macref{multiple-value-prog1}, and the like, if this optimization is desired.
  3275. % One sentence was removed and replaced by Moon, since the specification
  3276. % about congruence was excessively vague. Also discuss the consequences
  3277. % of modifying arguments:
  3278. The list {\tt (:arguments . \param{lambda-list})} can appear before
  3279. any declarations or \term{documentation string}. This form is useful when
  3280. the method combination type performs some specific behavior as part of
  3281. the combined method and that behavior needs access to the arguments to
  3282. the \term{generic function}. Each parameter variable defined by
  3283. \param{lambda-list} is bound to a \term{form} that can be inserted into the
  3284. effective method. When this \term{form} is evaluated during execution of the
  3285. effective method, its value is the corresponding argument to the
  3286. \term{generic function}; the consequences of using such a \term{form} as
  3287. the \param{place} in a \macref{setf} \term{form} are undefined.
  3288. \issue{METHOD-COMBINATION-ARGUMENTS:CLARIFY}
  3289. %If \param{lambda-list} is not congruent to the
  3290. %generic function's \term{lambda list}, additional ignored parameters are
  3291. %automatically inserted until it is congruent.
  3292. % If the arguments supplied to the \term{generic function} do not
  3293. % match \param{lambda-list}, extra arguments are ignored and missing
  3294. % arguments are defaulted to \nil\.
  3295. % Thus it is permissible
  3296. % for \param{lambda-list} to receive fewer arguments than the number of
  3297. % required arguments for the \term{generic function}.
  3298. Argument correspondence is computed by dividing the \kwd{arguments} \param{lambda-list}
  3299. and the \term{generic function} \param{lambda-list} into three sections:
  3300. the \term{required parameters},
  3301. the \term{optional parameters},
  3302. and the \term{keyword} and \term{rest parameters}.
  3303. The \term{arguments} supplied to the \term{generic function} for a particular \term{call}
  3304. are also divided into three sections;
  3305. the required \term{arguments} section contains as many \term{arguments}
  3306. as the \term{generic function} has \term{required parameters},
  3307. the optional \term{arguments} section contains as many arguments
  3308. as the \term{generic function} has \term{optional parameters},
  3309. and the keyword/rest \term{arguments} section contains the remaining arguments.
  3310. Each \term{parameter} in the required and optional sections of the
  3311. \kwd{arguments} \param{lambda-list} accesses the argument at the same position
  3312. in the corresponding section of the \term{arguments}.
  3313. If the section of the \kwd{arguments} \param{lambda-list} is shorter,
  3314. extra \term{arguments} are ignored.
  3315. If the section of the \kwd{arguments} \param{lambda-list} is longer,
  3316. excess \term{required parameters} are bound to forms that evaluate to \nil\
  3317. and excess \term{optional parameters} are \term{bound} to their initforms.
  3318. The \term{keyword parameters} and \term{rest parameters} in the \kwd{arguments}
  3319. \param{lambda-list} access the keyword/rest section of the \term{arguments}.
  3320. If the \kwd{arguments} \param{lambda-list} contains \keyref{key}, it behaves as
  3321. if it also contained \keyref{allow-other-keys}.
  3322. In addition, \keyref{whole} \param{var} can be placed first in the \kwd{arguments}
  3323. \param{lambda-list}. It causes \param{var} to be \term{bound} to a \term{form}
  3324. that \term{evaluates} to a \term{list} of all of the \term{arguments} supplied
  3325. to the \term{generic function}. This is different from \keyref{rest} because it
  3326. accesses all of the arguments, not just the keyword/rest \term{arguments}.
  3327. \endissue{METHOD-COMBINATION-ARGUMENTS:CLARIFY}
  3328. Erroneous conditions detected by the body should be reported with
  3329. \funref{method-combination-error} or \funref{invalid-method-error}; these
  3330. \term{functions}
  3331. add any necessary contextual information to the error message and will
  3332. signal the appropriate error.
  3333. The body \param{forms} are evaluated inside of the \term{bindings} created by
  3334. the
  3335. \term{lambda list} and method group specifiers.
  3336. \reviewer{Barmar: Are they inside or outside the :ARGUMENTS bindings?}
  3337. Declarations at the head of
  3338. the body are positioned directly inside of \term{bindings} created by the
  3339. \term{lambda list} and outside of the \term{bindings} of the method group variables.
  3340. Thus method group variables cannot be declared in this way. \specref{locally} may be used
  3341. around the body, however.
  3342. Within the body \param{forms}, \param{generic-function-symbol}
  3343. is bound to the \term{generic function} \term{object}.
  3344. \issue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  3345. \param{Documentation} is attached as a \term{documentation string}
  3346. to \param{name} (as kind \specref{method-combination})
  3347. and to the \term{method combination} \term{object}.
  3348. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  3349. % Removed by Moon, appears to be redundant with what was stated earlier:
  3350. %The functions \funref{method-combination-error} and
  3351. %\funref{invalid-method-error} can be called from the body \param{forms} or
  3352. %from \term{functions} called by the body \param{forms}. The actions of these
  3353. %two \term{functions} can depend on \term{implementation-dependent} dynamic variables
  3354. %automatically bound before the generic function
  3355. %\funref{compute-effective-method} is called.
  3356. Note that two methods with identical specializers, but with different
  3357. \term{qualifiers}, are not ordered by the algorithm described in Step 2 of
  3358. the method selection and combination process described in
  3359. \secref\MethodSelectionAndCombination. Normally the two methods play
  3360. different roles in the effective method because they have different
  3361. \term{qualifiers}, and no matter how they are ordered in the result of Step
  3362. 2, the effective method is the same. If the two methods play the same
  3363. role and their order matters,
  3364. \reviewer{Barmar: How does the system know when the order matters?}
  3365. an error is signaled. This happens as
  3366. part of the \term{qualifier} pattern matching in
  3367. \macref{define-method-combination}.
  3368. \endlist
  3369. \issue{DEFINE-METHOD-COMBINATION:CLARIFY}
  3370. If a \macref{define-method-combination} \term{form} appears as a
  3371. \term{top level form}, the \term{compiler} must make the
  3372. \term{method combination} \term{name} be recognized as a valid
  3373. \term{method combination} \term{name} in subsequent \macref{defgeneric}
  3374. \term{forms}. However, the \term{method combination} is executed
  3375. no earlier than when the \macref{define-method-combination} \term{form}
  3376. is executed, and possibly as late as the time that \term{generic functions}
  3377. that use the \term{method combination} are executed.
  3378. \endissue{DEFINE-METHOD-COMBINATION:CLARIFY}
  3379. \label Examples::
  3380. %% Examples changed by Moon to reflect that the second argument of
  3381. %% call-method is unsupplied when call-next-method is not allowed
  3382. Most examples of the long form of \macref{define-method-combination} also
  3383. illustrate the use of the related \term{functions} that are provided as part
  3384. of the declarative method combination facility.
  3385. \code
  3386. ;;; Examples of the short form of define-method-combination
  3387. (define-method-combination and :identity-with-one-argument t)
  3388. (defmethod func and ((x class1) y) ...)
  3389. ;;; The equivalent of this example in the long form is:
  3390. (define-method-combination and
  3391. (&optional (order :most-specific-first))
  3392. ((around (:around))
  3393. (primary (and) :order order :required t))
  3394. (let ((form (if (rest primary)
  3395. `(and ,@(mapcar #'(lambda (method)
  3396. `(call-method ,method))
  3397. primary))
  3398. `(call-method ,(first primary)))))
  3399. (if around
  3400. `(call-method ,(first around)
  3401. (,@(rest around)
  3402. (make-method ,form)))
  3403. form)))
  3404. ;;; Examples of the long form of define-method-combination
  3405. ;The default method-combination technique
  3406. (define-method-combination standard ()
  3407. ((around (:around))
  3408. (before (:before))
  3409. (primary () :required t)
  3410. (after (:after)))
  3411. (flet ((call-methods (methods)
  3412. (mapcar #'(lambda (method)
  3413. `(call-method ,method))
  3414. methods)))
  3415. (let ((form (if (or before after (rest primary))
  3416. `(multiple-value-prog1
  3417. (progn ,@(call-methods before)
  3418. (call-method ,(first primary)
  3419. ,(rest primary)))
  3420. ,@(call-methods (reverse after)))
  3421. `(call-method ,(first primary)))))
  3422. (if around
  3423. `(call-method ,(first around)
  3424. (,@(rest around)
  3425. (make-method ,form)))
  3426. form))))
  3427. ;A simple way to try several methods until one returns non-nil
  3428. (define-method-combination or ()
  3429. ((methods (or)))
  3430. `(or ,@(mapcar #'(lambda (method)
  3431. `(call-method ,method))
  3432. methods)))
  3433. ;A more complete version of the preceding
  3434. (define-method-combination or
  3435. (&optional (order ':most-specific-first))
  3436. ((around (:around))
  3437. (primary (or)))
  3438. ;; Process the order argument
  3439. (case order
  3440. (:most-specific-first)
  3441. (:most-specific-last (setq primary (reverse primary)))
  3442. (otherwise (method-combination-error "~S is an invalid order.~@
  3443. :most-specific-first and :most-specific-last are the possible values."
  3444. order)))
  3445. ;; Must have a primary method
  3446. (unless primary
  3447. (method-combination-error "A primary method is required."))
  3448. ;; Construct the form that calls the primary methods
  3449. (let ((form (if (rest primary)
  3450. `(or ,@(mapcar #'(lambda (method)
  3451. `(call-method ,method))
  3452. primary))
  3453. `(call-method ,(first primary)))))
  3454. ;; Wrap the around methods around that form
  3455. (if around
  3456. `(call-method ,(first around)
  3457. (,@(rest around)
  3458. (make-method ,form)))
  3459. form)))
  3460. ;The same thing, using the :order and :required keyword options
  3461. (define-method-combination or
  3462. (&optional (order ':most-specific-first))
  3463. ((around (:around))
  3464. (primary (or) :order order :required t))
  3465. (let ((form (if (rest primary)
  3466. `(or ,@(mapcar #'(lambda (method)
  3467. `(call-method ,method))
  3468. primary))
  3469. `(call-method ,(first primary)))))
  3470. (if around
  3471. `(call-method ,(first around)
  3472. (,@(rest around)
  3473. (make-method ,form)))
  3474. form)))
  3475. ;This short-form call is behaviorally identical to the preceding
  3476. (define-method-combination or :identity-with-one-argument t)
  3477. ;Order methods by positive integer qualifiers
  3478. ;:around methods are disallowed to keep the example small
  3479. (define-method-combination example-method-combination ()
  3480. ((methods positive-integer-qualifier-p))
  3481. `(progn ,@(mapcar #'(lambda (method)
  3482. `(call-method ,method))
  3483. (stable-sort methods #'<
  3484. :key #'(lambda (method)
  3485. (first (method-qualifiers method)))))))
  3486. (defun positive-integer-qualifier-p (method-qualifiers)
  3487. (and (= (length method-qualifiers) 1)
  3488. (typep (first method-qualifiers) '(integer 0 *))))
  3489. ;;; Example of the use of :arguments
  3490. (define-method-combination progn-with-lock ()
  3491. ((methods ()))
  3492. (:arguments object)
  3493. `(unwind-protect
  3494. (progn (lock (object-lock ,object))
  3495. ,@(mapcar #'(lambda (method)
  3496. `(call-method ,method))
  3497. methods))
  3498. (unlock (object-lock ,object))))
  3499. \endcode
  3500. \label Affected By:\None.
  3501. \label Side Effects::
  3502. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  3503. The \term{compiler} is not required to perform any compile-time side-effects.
  3504. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  3505. \label Exceptional Situations::
  3506. Method combination types defined with the short form require exactly
  3507. one \term{qualifier} per method.
  3508. An error \oftype{error} is signaled if there are
  3509. applicable methods with no \term{qualifiers} or with \term{qualifiers} that are not
  3510. supported by the method combination type.
  3511. At least one primary method must be applicable or
  3512. an error \oftype{error} is signaled.
  3513. If an applicable method does not fall into any method group, the
  3514. system signals an error \oftype{error}
  3515. indicating that the method is invalid for the kind of
  3516. method combination in use.
  3517. If the value of the \kwd{required} option is \term{true}
  3518. and the method group is empty (that is, no applicable
  3519. methods match the \term{qualifier} patterns or satisfy the predicate),
  3520. an error \oftype{error} is signaled.
  3521. If the \kwd{order} option evaluates to a value other than
  3522. \kwd{most-specific-first} or \kwd{most-specific-last},
  3523. an error \oftype{error} is signaled.
  3524. \label See Also::
  3525. \funref{call-method},
  3526. \funref{call-next-method},
  3527. \funref{documentation},
  3528. \funref{method-qualifiers},
  3529. \funref{method-combination-error},
  3530. \funref{invalid-method-error},
  3531. \macref{defgeneric},
  3532. {\secref\MethodSelectionAndCombination},
  3533. {\secref\BuiltInMethCombTypes},
  3534. {\secref\DocVsDecls}
  3535. \label Notes::
  3536. % Added phrase to the end of this paragraph --Moon:
  3537. The \kwd{method-combination} option of \macref{defgeneric} is used to
  3538. specify that a \term{generic function} should use a particular method
  3539. combination type. The first argument to the \kwd{method-combination}
  3540. option is the \term{name} of a method combination type and the remaining
  3541. arguments are options for that type.
  3542. \endissue{DECLS-AND-DOC}
  3543. \endcom
  3544. %%% ========== FIND-METHOD
  3545. \begincom{find-method}\ftype{Standard Generic Function}
  3546. \label Syntax::
  3547. \DefgenWithValuesNewline find-method
  3548. {generic-function method-qualifiers specializers {\opt} errorp}
  3549. {method}
  3550. \label Method Signatures::
  3551. \Defmeth find-method
  3552. {\vtop{\hbox{\specparam{generic-function}{standard-generic-function}}
  3553. \hbox{method-qualifiers specializers {\opt} errorp}}}
  3554. \label Arguments and Values::
  3555. \param{generic-function}---a \term{generic function}.
  3556. \param{method-qualifiers}---a \term{list}.
  3557. \param{specializers}---a \term{list}.
  3558. \param{errorp}---a \term{generalized boolean}.
  3559. \Default{\term{true}}
  3560. \param{method}---a \term{method} \term{object}, or \nil.
  3561. \label Description::
  3562. The \term{generic function} \funref{find-method} takes a \term{generic function}
  3563. and returns the \term{method} \term{object} that agrees on \term{qualifiers}
  3564. and \term{parameter specializers} with the \param{method-qualifiers} and
  3565. \param{specializers} arguments of \funref{find-method}.
  3566. \param{Method-qualifiers} contains the
  3567. method \term{qualifiers} for the \term{method}.
  3568. The order of the method \term{qualifiers}
  3569. is significant.
  3570. For a definition of agreement in this context,
  3571. \seesection\SpecializerQualifierAgreement.
  3572. The \param{specializers} argument contains the parameter
  3573. specializers for the \term{method}. It must correspond in length to
  3574. the number of required arguments of the \term{generic function}, or
  3575. an error is signaled. This means that to obtain the
  3576. default \term{method} on a given \param{generic-function},
  3577. a \term{list} whose elements are \theclass{t} must be given.
  3578. If there is no such \term{method} and \param{errorp} is \term{true},
  3579. \funref{find-method} signals an error.
  3580. If there is no such \term{method} and \param{errorp} is \term{false},
  3581. \funref{find-method} returns \nil.
  3582. \label Examples::
  3583. \code
  3584. (defmethod some-operation ((a integer) (b float)) (list a b))
  3585. \EV #<STANDARD-METHOD SOME-OPERATION (INTEGER FLOAT) 26723357>
  3586. (find-method #'some-operation '() (mapcar #'find-class '(integer float)))
  3587. \EV #<STANDARD-METHOD SOME-OPERATION (INTEGER FLOAT) 26723357>
  3588. (find-method #'some-operation '() (mapcar #'find-class '(integer integer)))
  3589. \OUT Error: No matching method
  3590. (find-method #'some-operation '() (mapcar #'find-class '(integer integer)) nil)
  3591. \EV NIL
  3592. \endcode
  3593. \label Affected By::
  3594. \funref{add-method},
  3595. \macref{defclass},
  3596. \macref{defgeneric},
  3597. \macref{defmethod}
  3598. \label Exceptional Situations::
  3599. If the \param{specializers} argument does not correspond in length to
  3600. the number of required arguments of the \param{generic-function}, an
  3601. an error \oftype{error} is signaled.
  3602. If there is no such \term{method} and \param{errorp} is \term{true},
  3603. \funref{find-method} signals an error \oftype{error}.
  3604. \label See Also::
  3605. {\secref\SpecializerQualifierAgreement}
  3606. \label Notes:\None.
  3607. \endcom
  3608. %%% ========== ADD-METHOD
  3609. \begincom{add-method}\ftype{Standard Generic Function}
  3610. \label Syntax::
  3611. \DefgenWithValues add-method {generic-function method} {generic-function}
  3612. \label Method Signatures::
  3613. \Defmeth add-method {\vtop{\hbox{\specparam{generic-function}{standard-generic-function}}
  3614. \hbox{\specparam{method}{method}}}}
  3615. \label Arguments and Values::
  3616. \param{generic-function}---a \term{generic function} \term{object}.
  3617. \param{method}---a \term{method} \term{object}.
  3618. \label Description::
  3619. The generic function \funref{add-method} adds a \term{method}
  3620. to a \term{generic function}.
  3621. If \param{method} agrees with an existing \term{method} of \param{generic-function}
  3622. on \term{parameter specializers} and \term{qualifiers},
  3623. the existing \term{method} is replaced.
  3624. %% Per X3J13. -kmp 05-Oct-93
  3625. \label Examples:\None.
  3626. %!!!
  3627. \label Affected By:\None.
  3628. \label Exceptional Situations::
  3629. The \term{lambda list} of the method function of \param{method} must be
  3630. congruent with the \term{lambda list} of \param{generic-function},
  3631. or an error \oftype{error} is signaled.
  3632. If \param{method} is a \term{method} \term{object} of
  3633. another \term{generic function}, an error \oftype{error} is signaled.
  3634. \label See Also::
  3635. \macref{defmethod},
  3636. \macref{defgeneric},
  3637. \funref{find-method},
  3638. \funref{remove-method},
  3639. {\secref\SpecializerQualifierAgreement}
  3640. \label Notes:\None.
  3641. \endcom
  3642. %%% ========== INITIALIZE-INSTANCE
  3643. \begincom{initialize-instance}\ftype{Standard Generic Function}
  3644. \label Syntax::
  3645. \issue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  3646. \DefgenWithValues initialize-instance
  3647. {instance {\rest} initargs {\key} {\allowotherkeys}}
  3648. {instance}
  3649. \endissue{INITIALIZATION-FUNCTION-KEYWORD-CHECKING}
  3650. \label Method Signatures::
  3651. \Defmeth initialize-instance {\specparam{instance}{standard-object} {\rest} initargs}
  3652. \label Arguments and Values::
  3653. \param{instance}---an \term{object}.
  3654. \param{initargs}---a \term{defaulted initialization argument list}.
  3655. \label Description::
  3656. Called by \funref{make-instance} to initialize a newly created \term{instance}.
  3657. The generic function is called with the new \param{instance}
  3658. and the \term{defaulted initialization argument list}.
  3659. The system-supplied primary \term{method} on \funref{initialize-instance}
  3660. initializes the \term{slots} of the \param{instance} with values according
  3661. to the \param{initargs} and the \kwd{initform} forms of the \term{slots}.
  3662. It does this by calling the generic function \funref{shared-initialize}
  3663. with the following arguments: the \param{instance}, \t\ (this indicates
  3664. that all \term{slots} for which no initialization arguments are provided
  3665. should be initialized according to their \kwd{initform} forms), and
  3666. the \param{initargs}.
  3667. Programmers can define \term{methods} for \funref{initialize-instance} to
  3668. specify actions to be taken when an instance is initialized. If only
  3669. \term{after methods} are defined, they will be run after the
  3670. system-supplied primary \term{method} for initialization and therefore will
  3671. not interfere with the default behavior of \funref{initialize-instance}.
  3672. \label Examples:\None.
  3673. \label Affected By:\None.
  3674. \label Exceptional Situations:\None.
  3675. \label See Also::
  3676. \funref{shared-initialize},
  3677. \funref{make-instance},
  3678. \funref{slot-boundp},
  3679. \funref{slot-makunbound},
  3680. {\secref\ObjectCreationAndInit},
  3681. {\secref\InitargRules},
  3682. {\secref\DeclaringInitargValidity}
  3683. \label Notes:\None.
  3684. \endcom
  3685. %%% ========== CLASS-NAME
  3686. \begincom{class-name}\ftype{Standard Generic Function}
  3687. \label Syntax::
  3688. \DefgenWithValues class-name {class} {name}
  3689. \label Method Signatures::
  3690. \Defmeth class-name {\specparam{class}{class}}
  3691. \label Arguments and Values::
  3692. \param{class}---a \term{class} \term{object}.
  3693. \param{name}---a \term{symbol}.
  3694. \label Description::
  3695. Returns the \term{name} of the given \param{class}.
  3696. \label Examples:\None.
  3697. \label Affected By:\None.
  3698. \label Exceptional Situations:\None.
  3699. \label See Also::
  3700. \funref{find-class},
  3701. {\secref\Classes}
  3702. \label Notes::
  3703. If $S$ is a \term{symbol} such that $S =${\tt (class-name $C$)}
  3704. and $C =${\tt (find-class $S$)}, then $S$ is the proper name of $C$.
  3705. For further discussion, \seesection\Classes.
  3706. The name of an anonymous \term{class} is \nil.
  3707. \endcom
  3708. %%% ========== (SETF CLASS-NAME)
  3709. \begincom{(setf class-name)}\ftype{Standard Generic Function}
  3710. \label Syntax::
  3711. \DefgenWithValues {(setf class-name)} {new-value class} {new-value}
  3712. \label Method Signatures::
  3713. \Defmeth {(setf class-name)} {new-value \specparam{class}{class}}
  3714. \label Arguments and Values::
  3715. \param{new-value}---a \term{symbol}.
  3716. \param{class}---a \term{class}.
  3717. \label Description::
  3718. The generic function \f{(setf class-name)} sets the name of
  3719. a \param{class} object.
  3720. %The name of \param{class} is set to \param{new-value}.
  3721. \label Examples:\None.
  3722. \label Affected By:\None.
  3723. \label Exceptional Situations:\None.
  3724. \label See Also::
  3725. \funref{find-class},
  3726. \term{proper name},
  3727. {\secref\Classes}
  3728. %% Per X3J13. -kmp 05-Oct-93
  3729. \label Notes:\None.
  3730. %This info is in the glossary and elsewhere. I added a cross reference above. -kmp 14-May-91
  3731. % If \i{S} is a symbol such that
  3732. % \f{\i{S} = (class-name \i{C})}
  3733. % and \f{\i{C} = (find-class \i{S})},
  3734. % then \i{S} is the \term{proper name} of \i{C}.
  3735. %For further discussion, \seesection\Classes.
  3736. \endcom
  3737. %%% ========== CLASS-OF
  3738. \begincom{class-of}\ftype{Function}
  3739. \label Syntax::
  3740. \DefunWithValues class-of {object} {class}
  3741. \label Arguments and Values::
  3742. \param{object}---an \term{object}.
  3743. \param{class}---a \term{class} \term{object}.
  3744. \label Description::
  3745. Returns the \term{class} of which the \param{object} is
  3746. %"an instance" -> "a direct instance" -kmp 15-Jan-91
  3747. a \term{direct instance}.
  3748. \label Examples::
  3749. \code
  3750. (class-of 'fred) \EV #<BUILT-IN-CLASS SYMBOL 610327300>
  3751. (class-of 2/3) \EV #<BUILT-IN-CLASS RATIO 610326642>
  3752. (defclass book () ()) \EV #<STANDARD-CLASS BOOK 33424745>
  3753. (class-of (make-instance 'book)) \EV #<STANDARD-CLASS BOOK 33424745>
  3754. (defclass novel (book) ()) \EV #<STANDARD-CLASS NOVEL 33424764>
  3755. (class-of (make-instance 'novel)) \EV #<STANDARD-CLASS NOVEL 33424764>
  3756. (defstruct kons kar kdr) \EV KONS
  3757. (class-of (make-kons :kar 3 :kdr 4)) \EV #<STRUCTURE-CLASS KONS 250020317>
  3758. \endcode
  3759. \label Affected By:\None!
  3760. \label Exceptional Situations:\None!
  3761. \label See Also::
  3762. \funref{make-instance},
  3763. \funref{type-of}
  3764. \label Notes:\None.
  3765. \endcom
  3766. %--------------------Object Errors--------------------
  3767. \begincom{unbound-slot}\ftype{Condition Type}
  3768. \issue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  3769. \label Class Precedence List::
  3770. \typeref{unbound-slot},
  3771. \typeref{cell-error},
  3772. \typeref{error},
  3773. \typeref{serious-condition},
  3774. \typeref{condition},
  3775. \typeref{t}
  3776. \label Description::
  3777. The \term{object} having the unbound slot is initialized by
  3778. \theinitkeyarg{instance} to \funref{make-condition},
  3779. and is \term{accessed} by \thefunction{unbound-slot-instance}.
  3780. % \Thetype{unbound-slot} has an instance slot that can be
  3781. % initialized using the \kwd{instance} keyword to \funref{make-condition}.
  3782. \endissue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  3783. The name of the cell (see \typeref{cell-error}) is the name of the slot.
  3784. \label See Also::
  3785. \funref{cell-error-name},
  3786. \funref{unbound-slot-object},
  3787. {\secref\ConditionSystemConcepts}
  3788. \endcom%{unbound-slot}\ftype{Condition Type}
  3789. %%% ========== UNBOUND-SLOT-INSTANCE
  3790. \begincom{unbound-slot-instance}\ftype{Function}
  3791. \issue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  3792. \label Syntax::
  3793. \DefunWithValues unbound-slot-instance {condition} {instance}
  3794. \label Arguments and Values::
  3795. \param{condition}---a \term{condition} \oftype{unbound-slot}.
  3796. \param{instance}---an \term{object}.
  3797. \label Description::
  3798. Returns the instance which had the unbound slot in the \term{situation}
  3799. represented by the \param{condition}.
  3800. \label Examples:\None.
  3801. \label Affected By:\None.
  3802. \label Exceptional Situations:\None.
  3803. \label See Also::
  3804. \funref{cell-error-name},
  3805. \typeref{unbound-slot},
  3806. {\secref\ConditionSystemConcepts}
  3807. \label Notes:\None.
  3808. %Shouldn't be needed.
  3809. %It is an error to use \macref{setf} with \funref{unbound-slot-instance}.
  3810. \endissue{UNDEFINED-VARIABLES-AND-FUNCTIONS:COMPROMISE}
  3811. \endcom