dict-conses.tex 129 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662
  1. % -*- Mode: TeX -*-
  2. \def\SatisfyTest#1#2{The \param{test}, \param{test-not}, and \param{key}
  3. affect how it is determined whether \param{#1} is the same as #2.
  4. For details, \seesection\SatisfyingTheTwoArgTest.\par}
  5. % Cons
  6. % Trees
  7. % Lists
  8. % List Elements
  9. % List Tails
  10. % List Mapping
  11. % Alists
  12. % Plists
  13. % Sets
  14. %-------------------- Conses, lists, atoms, ... --------------------
  15. \begincom{list}\ftype{System Class}
  16. \label Class Precedence List::
  17. \typeref{list},
  18. \typeref{sequence},
  19. \typeref{t}
  20. \label Description::
  21. A \newterm{list} is a chain of \term{conses} in which the \term{car} of each
  22. \term{cons} is an \term{element} of the \term{list}, and the \term{cdr} of
  23. each \term{cons} is either the next link in the chain or a terminating
  24. \term{atom}.
  25. A \newterm{proper list} is a chain of \term{conses} terminated by
  26. the \newterm{empty list}, \empty, which is itself a \term{proper list}.
  27. A \newterm{dotted list} is a \term{list} which has a terminating \term{atom}
  28. that is not the \term{empty list}.
  29. A \newterm{circular list} is a chain of \term{conses} that has no termination
  30. because some \term{cons} in the chain is the \term{cdr} of a later \term{cons}.
  31. \term{Dotted lists} and \term{circular lists} are also \term{lists}, but usually
  32. the unqualified term ``list'' within this specification means \term{proper list}.
  33. Nevertheless, \thetype{list} unambiguously includes \term{dotted lists}
  34. and \term{circular lists}.
  35. For each \term{element} of a \term{list} there is a \term{cons}.
  36. The \term{empty list} has no \term{elements} and is not a \term{cons}.
  37. %% 2.15.0 14
  38. \Thetypes{cons} and \typeref{null} form an \term{exhaustive partition}
  39. of the \term{type} \typeref{list}.
  40. \label See Also::
  41. {\secref\LeftParen},
  42. {\secref\PrintingListsAndConses}
  43. \endcom%{list}\ftype{System Class}
  44. \begincom{null}\ftype{System Class}
  45. \label Class Precedence List::
  46. \typeref{null},
  47. \typeref{symbol},
  48. \typeref{list},
  49. \typeref{sequence},
  50. \typeref{t}
  51. \label Description::
  52. %% 2.15.0 13
  53. The only \term{object} \oftype{null} is \nil,
  54. which represents the \term{empty list} and can also be notated \empty.
  55. \label See Also::
  56. {\secref\SymbolTokens},
  57. {\secref\LeftParen},
  58. {\secref\PrintingSymbols}
  59. \endcom%{null}\ftype{System Class}
  60. \begincom{cons}\ftype{System Class}
  61. \label Class Precedence List::
  62. \typeref{cons},
  63. \typeref{list},
  64. \typeref{sequence},
  65. \typeref{t}
  66. \label Description::
  67. A \term{cons} is a compound \term{object} having two components,
  68. called the \term{car} and \term{cdr}. These form a \term{dotted pair}.
  69. Each component can be any \term{object}.
  70. \issue{CONS-TYPE-SPECIFIER:ADD}
  71. \label Compound Type Specifier Kind::
  72. Specializing.
  73. \label Compound Type Specifier Syntax::
  74. \Deftype{cons}{\ttbrac{car-typespec \brac{cdr-typespec}}}
  75. \label Compound Type Specifier Arguments::
  76. \param{car-typespec}---a \term{type specifier},
  77. or the \term{symbol} \misc{*}.
  78. \Default{the \term{symbol} \misc{*}}
  79. \param{cdr-typespec}---a \term{type specifier},
  80. or the \term{symbol} \misc{*}.
  81. \Default{the \term{symbol} \misc{*}}
  82. \label Compound Type Specifier Description::
  83. This denotes the set of \term{conses}
  84. whose \term{car} is constrained to be of \term{type} \param{car-typespec} and
  85. whose \term{cdr} is constrained to be of \term{type} \param{cdr-typespec}.
  86. (If either \param{car-typespec} or \param{cdr-typespec} is \misc{*},
  87. it is as if \thetype{t} had been denoted.)
  88. \endissue{CONS-TYPE-SPECIFIER:ADD}
  89. \label See Also::
  90. {\secref\LeftParen},
  91. {\secref\PrintingListsAndConses}
  92. \endcom%{cons}\ftype{System Class}
  93. \begincom{atom}\ftype{Type}
  94. %Added per Barrett's suggestion. -kmp 23-Oct-90
  95. \label Supertypes::
  96. \typeref{atom},
  97. \typeref{t}
  98. \label Description::
  99. It is equivalent to {\tt (not cons)}.
  100. \endcom%{atom}\ftype{Type}
  101. %-------------------- Cons --------------------
  102. %%% ========== CONS
  103. \begincom{cons}\ftype{Function}
  104. \label Syntax::
  105. \DefunWithValues cons {object-1 object-2} {cons}
  106. \label Arguments and Values::
  107. \param{object-1}---an \term{object}.
  108. \param{object-2}---an \term{object}.
  109. \param{cons}---a \term{cons}.
  110. \label Description::
  111. %% 15.1.0 8
  112. Creates a \term{fresh} \term{cons}, the \term{car} of which is \param{object-1}
  113. and the \term{cdr} of which is \param{object-2}.
  114. \label Examples::
  115. \code
  116. (cons 1 2) \EV (1 . 2)
  117. (cons 1 nil) \EV (1)
  118. (cons nil 2) \EV (NIL . 2)
  119. (cons nil nil) \EV (NIL)
  120. (cons 1 (cons 2 (cons 3 (cons 4 nil)))) \EV (1 2 3 4)
  121. (cons 'a 'b) \EV (A . B)
  122. (cons 'a (cons 'b (cons 'c '\empty))) \EV (A B C)
  123. (cons 'a '(b c d)) \EV (A B C D)
  124. \endcode
  125. \label Side Effects:\None.
  126. %% Sandra thinks this is excessive.
  127. %Creates an \term{object}.
  128. \label Affected By:\None.
  129. \label Exceptional Situations:\None.
  130. %% Sandra thinks this is excessive.
  131. %Might signal \typeref{storage-condition}.
  132. \label See Also::
  133. \funref{list}
  134. \label Notes::
  135. If \param{object-2} is a \term{list}, \funref{cons} can be thought of as
  136. producing a new \term{list} which is like it but has \param{object-1} prepended.
  137. \endcom
  138. %%% ========== CONSP
  139. \begincom{consp}\ftype{Function}
  140. \label Syntax::
  141. \DefunWithValues consp {object} {generalized-boolean}
  142. \label Arguments and Values::
  143. \param{object}---an \term{object}.
  144. \param{generalized-boolean}---a \term{generalized boolean}.
  145. \label Description::
  146. %% 6.2.2 8
  147. \TypePredicate{object}{cons}
  148. \label Examples::
  149. \code
  150. (consp nil) \EV \term{false}
  151. (consp (cons 1 2)) \EV \term{true}
  152. \endcode
  153. The \term{empty list} is not a \term{cons}, so
  154. \code
  155. (consp '()) \EQ (consp 'nil) \EV \term{false}
  156. \endcode
  157. \label Side Effects:\None!
  158. \label Affected By:\None!
  159. \label Exceptional Situations:\None!
  160. \label See Also::
  161. \funref{listp}
  162. \label Notes::
  163. \code
  164. (consp \param{object}) \EQ (typep \param{object} 'cons) \EQ (not (typep \param{object} 'atom)) \EQ (typep \param{object} '(not atom))
  165. \endcode
  166. \endcom
  167. %%% ========== ATOM
  168. \begincom{atom}\ftype{Function}
  169. \label Syntax::
  170. \DefunWithValues atom {object} {generalized-boolean}
  171. \label Arguments and Values::
  172. \param{object}---an \term{object}.
  173. \param{generalized-boolean}---a \term{generalized boolean}.
  174. \label Description::
  175. %% 6.2.2 6
  176. \TypePredicate{object}{atom}
  177. \label Examples::
  178. \code
  179. (atom 'sss) \EV \term{true}
  180. (atom (cons 1 2)) \EV \term{false}
  181. (atom nil) \EV \term{true}
  182. (atom '()) \EV \term{true}
  183. (atom 3) \EV \term{true}
  184. \endcode
  185. \label Affected By:\None!
  186. \label Exceptional Situations:\None!
  187. \label See Also:\None.
  188. \label Notes::
  189. \code
  190. (atom \param{object}) \EQ (typep \param{object} 'atom) \EQ (not (consp \param{object}))
  191. \EQ (not (typep \param{object} 'cons)) \EQ (typep \param{object} '(not cons))
  192. \endcode
  193. \endcom
  194. %%% ========== RPLACA
  195. %%% ========== RPLACD
  196. \begincom{rplaca, rplacd}\ftype{Function}
  197. \label Syntax::
  198. \DefunMultiWithValues {cons object} {cons}
  199. {\entry{rplaca}
  200. \entry{rplacd}}
  201. \label Pronunciation::
  202. \funref{rplaca}: \pronounced{\stress{r\harde}\Stress{plak}\schwa}
  203. or \pronounced{\stress{r\schwa}\Stress{plak}\schwa}
  204. \funref{rplacd}: \pronounced{\stress{r\harde}\Stress{plak}d\schwa}
  205. or \pronounced{\stress{r\schwa}\Stress{plak}d\schwa}
  206. or \pronounced{\stress{r\harde}\Stress{plak}d\harde}
  207. or \pronounced{\stress{r\schwa}\Stress{plak}d\harde}
  208. \label Arguments and Values::
  209. \param{cons}---a \term{cons}.
  210. \param{object}---an \term{object}.
  211. \label Description::
  212. %% 15.3.0 4
  213. \funref{rplaca} replaces the \term{car} of the \param{cons} with \param{object}.
  214. %and then returns the modified \param{cons}.
  215. \funref{rplacd} replaces the \term{cdr} of the \param{cons} with \param{object}.
  216. %and then returns the modified \param{cons}.
  217. \label Examples::
  218. %% 15.3.0 3
  219. \code
  220. (defparameter *some-list* (list* 'one 'two 'three 'four)) \EV *some-list*
  221. *some-list* \EV (ONE TWO THREE . FOUR)
  222. (rplaca *some-list* 'uno) \EV (UNO TWO THREE . FOUR)
  223. *some-list* \EV (UNO TWO THREE . FOUR)
  224. (rplacd (last *some-list*) (list 'IV)) \EV (THREE IV)
  225. *some-list* \EV (UNO TWO THREE IV)
  226. \endcode
  227. \label Side Effects::
  228. %% 15.3.0 1
  229. %% 15.3.0 2
  230. The \param{cons} is modified.
  231. \label Affected By:\None!
  232. \label Exceptional Situations:\None.
  233. %!!! Issue: read-only structure might be enforced. -kmp
  234. \Shouldchecktype{cons}{a \term{cons}}
  235. \label See Also:\None.
  236. \label Notes:\None.
  237. %%What else would they be used for? -kmp 15-Feb-91
  238. % \funref{rplaca} and \funref{rplacd} may be used to make alterations
  239. % in an already existing list structure, that is,
  240. % to change the \term{car} or \term{cdr} of an existing \term{cons}.
  241. \endcom
  242. %%% ========== CAR
  243. %%% ========== CDR
  244. %%% ========== CAAR
  245. %%% ========== CADR
  246. %%% ========== CDAR
  247. %%% ========== CDDR
  248. %%% ========== CAAAR
  249. %%% ========== CAADR
  250. %%% ========== CADAR
  251. %%% ========== CADDR
  252. %%% ========== CDAAR
  253. %%% ========== CDADR
  254. %%% ========== CDDAR
  255. %%% ========== CDDDR
  256. %%% ========== CAAAAR
  257. %%% ========== CAAADR
  258. %%% ========== CAADAR
  259. %%% ========== CAADDR
  260. %%% ========== CADAAR
  261. %%% ========== CADADR
  262. %%% ========== CADDAR
  263. %%% ========== CADDDR
  264. %%% ========== CDAAAR
  265. %%% ========== CDAADR
  266. %%% ========== CDADAR
  267. %%% ========== CDADDR
  268. %%% ========== CDDAAR
  269. %%% ========== CDDADR
  270. %%% ========== CDDDAR
  271. %%% ========== CDDDDR
  272. \begincom{car, cdr,
  273. caar, cadr, cdar, cddr,
  274. caaar, caadr, cadar, caddr, cdaar, cdadr, cddar, cdddr,
  275. caaaar, caaadr, caadar, caaddr, cadaar, cadadr, caddar, cadddr,
  276. cdaaar, cdaadr, cdadar, cdaddr, cddaar, cddadr, cdddar, cddddr}\ftype{Accessor}
  277. \label Syntax::
  278. \DefunMultiAccessorWithValues {x} {object} {new-object}
  279. {\entry{car}
  280. \entry{cdr}
  281. \blankline
  282. \entry{caar}
  283. \entry{cadr}
  284. \entry{cdar}
  285. \entry{cddr}
  286. \blankline
  287. \entry{caaar}
  288. \entry{caadr}
  289. \entry{cadar}
  290. \entry{caddr}
  291. \entry{cdaar}
  292. \entry{cdadr}
  293. \entry{cddar}
  294. \entry{cdddr}
  295. \blankline
  296. \entry{caaaar}
  297. \entry{caaadr}
  298. \entry{caadar}
  299. \entry{caaddr}
  300. \entry{cadaar}
  301. \entry{cadadr}
  302. \entry{caddar}
  303. \entry{cadddr}
  304. \entry{cdaaar}
  305. \entry{cdaadr}
  306. \entry{cdadar}
  307. \entry{cdaddr}
  308. \entry{cddaar}
  309. \entry{cddadr}
  310. \entry{cdddar}
  311. \entry{cddddr}}
  312. \label Pronunciation::
  313. \funref{cadr}: \pronounced{\Stress{ka}\stress{d\schwa r}}
  314. \funref{caddr}: \pronounced{\Stress{kad}\schwa \stress{d\schwa r}}
  315. or \pronounced{\Stress{ka}\stress{d\.ud\schwa r}}
  316. \funref{cdr}: \pronounced{\Stress{k\.u}\stress{d\schwa r}}
  317. \funref{cddr}: \pronounced{\Stress{k\.ud}\schwa \stress{d\schwa r}}
  318. or \pronounced{\Stress{k\schwa}\stress{d\.ud\schwa r}}
  319. \label Arguments and Values::
  320. \param{x}---a \term{list}.
  321. \param{object}---an \term{object}.
  322. \param{new-object}---an \term{object}.
  323. \label Description::
  324. %% 15.1.0 3
  325. If \param{x} is a \term{cons}, \funref{car} returns the \term{car}
  326. of that \term{cons}. If \param{x} is \nil, \funref{car} returns \nil.
  327. %% 15.1.0 4
  328. If \param{x} is a \term{cons}, \funref{cdr} returns the \term{cdr}
  329. of that \term{cons}. If \param{x} is \nil, \funref{cdr} returns \nil.
  330. \term{Functions} are provided which perform compositions of up to four
  331. \funref{car} and \funref{cdr} operations. Their \term{names} consist of
  332. a \f{C}, followed by two, three, or four occurrences of \f{A} or \f{D},
  333. and finally an \f{R}. The series of \f{A}'s and \f{D}'s in each
  334. \term{function}'s \term{name} is chosen to identify the series of
  335. \funref{car} and \funref{cdr} operations that is performed by the function.
  336. The order in which the \f{A}'s and \f{D}'s appear is the inverse of the
  337. order in which the corresponding operations are performed. \Thenextfigure\
  338. defines the relationships precisely.
  339. \tablefigtwo{CAR and CDR variants}{This \term{place} $\ldots$}{Is equivalent to this \term{place} $\ldots$}{
  340. \f{(caar \param{x})}&\f{(car (car \param{x}))}\cr
  341. \f{(cadr \param{x})}&\f{(car (cdr \param{x}))}\cr
  342. \f{(cdar \param{x})}&\f{(cdr (car \param{x}))}\cr
  343. \f{(cddr \param{x})}&\f{(cdr (cdr \param{x}))}\cr
  344. \f{(caaar \param{x})}&\f{(car (car (car \param{x})))}\cr
  345. \f{(caadr \param{x})}&\f{(car (car (cdr \param{x})))}\cr
  346. \f{(cadar \param{x})}&\f{(car (cdr (car \param{x})))}\cr
  347. \f{(caddr \param{x})}&\f{(car (cdr (cdr \param{x})))}\cr
  348. \f{(cdaar \param{x})}&\f{(cdr (car (car \param{x})))}\cr
  349. \f{(cdadr \param{x})}&\f{(cdr (car (cdr \param{x})))}\cr
  350. \f{(cddar \param{x})}&\f{(cdr (cdr (car \param{x})))}\cr
  351. \f{(cdddr \param{x})}&\f{(cdr (cdr (cdr \param{x})))}\cr
  352. \f{(caaaar \param{x})}&\f{(car (car (car (car \param{x}))))}\cr
  353. \f{(caaadr \param{x})}&\f{(car (car (car (cdr \param{x}))))}\cr
  354. \f{(caadar \param{x})}&\f{(car (car (cdr (car \param{x}))))}\cr
  355. \f{(caaddr \param{x})}&\f{(car (car (cdr (cdr \param{x}))))}\cr
  356. \f{(cadaar \param{x})}&\f{(car (cdr (car (car \param{x}))))}\cr
  357. \f{(cadadr \param{x})}&\f{(car (cdr (car (cdr \param{x}))))}\cr
  358. \f{(caddar \param{x})}&\f{(car (cdr (cdr (car \param{x}))))}\cr
  359. \f{(cadddr \param{x})}&\f{(car (cdr (cdr (cdr \param{x}))))}\cr
  360. \f{(cdaaar \param{x})}&\f{(cdr (car (car (car \param{x}))))}\cr
  361. \f{(cdaadr \param{x})}&\f{(cdr (car (car (cdr \param{x}))))}\cr
  362. \f{(cdadar \param{x})}&\f{(cdr (car (cdr (car \param{x}))))}\cr
  363. \f{(cdaddr \param{x})}&\f{(cdr (car (cdr (cdr \param{x}))))}\cr
  364. \f{(cddaar \param{x})}&\f{(cdr (cdr (car (car \param{x}))))}\cr
  365. \f{(cddadr \param{x})}&\f{(cdr (cdr (car (cdr \param{x}))))}\cr
  366. \f{(cdddar \param{x})}&\f{(cdr (cdr (cdr (car \param{x}))))}\cr
  367. \f{(cddddr \param{x})}&\f{(cdr (cdr (cdr (cdr \param{x}))))}\cr
  368. }
  369. \macref{setf} can also be used with any of these functions to change an
  370. existing component of \param{x}, but \macref{setf} will not make new
  371. components. So, for example, the \term{car} of a \term{cons}
  372. can be assigned with \macref{setf} of \funref{car},
  373. but the \term{car} of \nil\ cannot be assigned with \macref{setf} of \funref{car}.
  374. Similarly, the \term{car} of the \term{car} of a \term{cons} whose \term{car}
  375. is a \term{cons} can be assigned with \macref{setf} of \funref{caar},
  376. but neither \nil nor a \term{cons} whose car is \nil\ can be assigned
  377. with \macref{setf} of \funref{caar}.
  378. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  379. The argument \param{x} is permitted to be a \term{dotted list}
  380. or a \term{circular list}.
  381. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  382. \label Examples::
  383. \code
  384. (car nil) \EV NIL
  385. (cdr '(1 . 2)) \EV 2
  386. (cdr '(1 2)) \EV (2)
  387. (cadr '(1 2)) \EV 2
  388. (car '(a b c)) \EV A
  389. (cdr '(a b c)) \EV (B C)
  390. \endcode
  391. \label Affected By:\None.
  392. \label Exceptional Situations::
  393. The functions \funref{car} and \funref{cdr}
  394. should signal \typeref{type-error} if they receive an argument which is not a
  395. \term{list}. The other functions (\funref{caar}, \funref{cadr},
  396. $\ldots$ \funref{cddddr}) should behave for the purpose of
  397. error checking as if defined by appropriate calls to \funref{car} and
  398. \funref{cdr}.
  399. \label See Also::
  400. \funref{rplaca}, \funref{first}, \funref{rest}
  401. \label Notes::
  402. %% 15.1.0 7
  403. The \term{car} of a \term{cons} can also be altered by using \funref{rplaca},
  404. and the \term{cdr} of a \term{cons} can be altered by using \funref{rplacd}.
  405. \code
  406. (car \i{x}) \EQ (first \i{x})
  407. (cadr \i{x}) \EQ (second \i{x}) \EQ (car (cdr \i{x}))
  408. (caddr \i{x}) \EQ (third \i{x}) \EQ (car (cdr (cdr \i{x})))
  409. (cadddr \i{x}) \EQ (fourth \i{x}) \EQ (car (cdr (cdr (cdr \i{x}))))
  410. \endcode
  411. \endcom
  412. %-------------------- Trees --------------------
  413. %%% ========== COPY-TREE
  414. \begincom{copy-tree}\ftype{Function}
  415. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  416. \label Syntax::
  417. \DefunWithValues copy-tree {tree} {new-tree}
  418. \label Arguments and Values::
  419. \param{tree}---a \term{tree}.
  420. \param{new-tree}---a \term{tree}.
  421. \label Description::
  422. %% 15.2.0 25
  423. Creates a \term{copy} of a \term{tree} of \term{conses}.
  424. If \param{tree} is not a \term{cons}, it is returned;
  425. otherwise, the result is a new \term{cons} of the results of calling \funref{copy-tree}
  426. on the \term{car} and \term{cdr} of \param{tree}.
  427. In other words, all \term{conses} in the \term{tree} represented by \param{tree}
  428. are copied recursively, stopping only when non-\term{conses} are encountered.
  429. \funref{copy-tree} does not preserve circularities and the sharing of substructure.
  430. %!!! And consequently might fail to return in the case of circularity? -kmp 09-Apr-91
  431. \label Examples::
  432. \code
  433. (setq object (list (cons 1 "one")
  434. (cons 2 (list 'a 'b 'c))))
  435. \EV ((1 . "one") (2 A B C))
  436. (setq object-too object) \EV ((1 . "one") (2 A B C))
  437. (setq copy-as-list (copy-list object))
  438. (setq copy-as-alist (copy-alist object))
  439. (setq copy-as-tree (copy-tree object))
  440. (eq object object-too) \EV \term{true}
  441. (eq copy-as-tree object) \EV \term{false}
  442. (eql copy-as-tree object) \EV \term{false}
  443. (equal copy-as-tree object) \EV \term{true}
  444. (setf (first (cdr (second object))) "a"
  445. (car (second object)) "two"
  446. (car object) '(one . 1)) \EV (ONE . 1)
  447. object \EV ((ONE . 1) ("two" "a" B C))
  448. object-too \EV ((ONE . 1) ("two" "a" B C))
  449. copy-as-list \EV ((1 . "one") ("two" "a" B C))
  450. copy-as-alist \EV ((1 . "one") (2 "a" B C))
  451. copy-as-tree \EV ((1 . "one") (2 A B C))
  452. \endcode
  453. \label Side Effects:\None.
  454. \label Affected By:\None.
  455. \label Exceptional Situations:\None.
  456. \label See Also::
  457. \funref{tree-equal}
  458. \label Notes:\None.
  459. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  460. \endcom
  461. %%% ========== NSUBLIS
  462. %%% ========== SUBLIS
  463. \begincom{sublis, nsublis}\ftype{Function}
  464. \label Syntax::
  465. \DefunWithValues sublis {alist tree {\key} key test test-not} {new-tree}
  466. \DefunWithValues nsublis {alist tree {\key} key test test-not} {new-tree}
  467. \label Arguments and Values::
  468. \param{alist}---an \term{association list}.
  469. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  470. \param{tree}---a \term{tree}.
  471. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  472. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  473. that returns a \term{generalized boolean}.
  474. \param{test-not}---a \term{designator} for
  475. a \term{function} of two \term{arguments}
  476. that returns a \term{generalized boolean}.
  477. \param{key}---a \term{designator} for a \term{function} of one argument,
  478. or \nil.
  479. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  480. \param{new-tree}---a \term{tree}.
  481. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  482. \label Description::
  483. %% 15.4.0 9
  484. \funref{sublis} makes substitutions for \term{objects} in \param{tree}
  485. (a structure of \term{conses}).
  486. %% 15.4.0 10
  487. \funref{nsublis} is like \funref{sublis}
  488. but destructively modifies the relevant
  489. parts of the \param{tree}.
  490. \funref{sublis} looks at all subtrees and leaves of \param{tree};
  491. if a subtree or leaf appears as a key in \param{alist}
  492. (that is, the key and the subtree or leaf \term{satisfy the test}),
  493. it is replaced by the \term{object} with which that key is associated.
  494. This operation is non-destructive. In effect, \funref{sublis} can
  495. perform several \funref{subst} operations simultaneously.
  496. %% Implied by "satisfy the test." -kmp 15-Feb-92
  497. % The first argument to the \kwd{test} or \kwd{test-not}
  498. % function is a key appearing in \param{alist};
  499. % the second argument is
  500. % the part of an element of \param{tree} extracted by the
  501. % \kwd{key} function (if supplied).
  502. %
  503. % The argument to the \kwd{key}
  504. % function is a \param{tree} element; the return value is part of
  505. % the supplied \param{tree} element.
  506. % If \kwd{key} is not supplied or \nil,
  507. % the \param{tree} element itself is
  508. % supplied to the \kwd{test} or \kwd{test-not}
  509. % function.
  510. If \funref{sublis} succeeds, a new copy of \param{tree} is returned in
  511. which each occurrence of such a subtree or leaf is replaced by the
  512. \term{object} with which it is associated. If no changes are made, the
  513. original tree is returned. The original \param{tree} is left unchanged,
  514. but the result tree may share cells with it.
  515. \funref{nsublis} is permitted to modify \param{tree}
  516. but otherwise returns the same values as \funref{sublis}.
  517. \label Examples::
  518. \code
  519. (sublis '((x . 100) (z . zprime))
  520. '(plus x (minus g z x p) 4 . x))
  521. \EV (PLUS 100 (MINUS G ZPRIME 100 P) 4 . 100)
  522. (sublis '(((+ x y) . (- x y)) ((- x y) . (+ x y)))
  523. '(* (/ (+ x y) (+ x p)) (- x y))
  524. :test #'equal)
  525. \EV (* (/ (- X Y) (+ X P)) (+ X Y))
  526. (setq tree1 '(1 (1 2) ((1 2 3)) (((1 2 3 4)))))
  527. \EV (1 (1 2) ((1 2 3)) (((1 2 3 4))))
  528. (sublis '((3 . "three")) tree1)
  529. \EV (1 (1 2) ((1 2 "three")) (((1 2 "three" 4))))
  530. (sublis '((t . "string"))
  531. (sublis '((1 . "") (4 . 44)) tree1)
  532. :key #'stringp)
  533. \EV ("string" ("string" 2) (("string" 2 3)) ((("string" 2 3 44))))
  534. tree1 \EV (1 (1 2) ((1 2 3)) (((1 2 3 4))))
  535. (setq tree2 '("one" ("one" "two") (("one" "Two" "three"))))
  536. \EV ("one" ("one" "two") (("one" "Two" "three")))
  537. (sublis '(("two" . 2)) tree2)
  538. \EV ("one" ("one" "two") (("one" "Two" "three")))
  539. tree2 \EV ("one" ("one" "two") (("one" "Two" "three")))
  540. (sublis '(("two" . 2)) tree2 :test 'equal)
  541. \EV ("one" ("one" 2) (("one" "Two" "three")))
  542. (nsublis '((t . 'temp))
  543. tree1
  544. :key #'(lambda (x) (or (atom x) (< (list-length x) 3))))
  545. \EV ((QUOTE TEMP) (QUOTE TEMP) QUOTE TEMP)
  546. \endcode
  547. \label Side Effects::
  548. \funref{nsublis} modifies \param{tree}.
  549. \label Affected By:\None.
  550. \label Exceptional Situations:\None.
  551. \label See Also::
  552. \funref{subst},
  553. \issue{CONSTANT-MODIFICATION:DISALLOW}
  554. {\secref\ConstantModification},
  555. \endissue{CONSTANT-MODIFICATION:DISALLOW}
  556. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  557. {\secref\TraversalRules}
  558. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  559. \label Notes::
  560. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  561. The \kwd{test-not} parameter is deprecated.
  562. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  563. Because the side-effecting variants (\eg \funref{nsublis}) potentially
  564. change the path that is being traversed, their effects in the presence
  565. of shared or circular structure structure may vary in surprising ways
  566. when compared to their non-side-effecting alternatives. To see this,
  567. consider the following side-effect behavior, which might be exhibited by
  568. some implementations:
  569. \code
  570. (defun test-it (fn)
  571. (let* ((shared-piece (list 'a 'b))
  572. (data (list shared-piece shared-piece)))
  573. (funcall fn '((a . b) (b . a)) data)))
  574. (test-it #'sublis) \EV ((B A) (B A))
  575. (test-it #'nsublis) \EV ((A B) (A B))
  576. \endcode
  577. \endcom
  578. %%% ========== NSUBST
  579. %%% ========== NSUBST-IF
  580. %%% ========== NSUBST-IF-NOT
  581. %%% ========== SUBST
  582. %%% ========== SUBST-IF
  583. %%% ========== SUBST-IF-NOT
  584. \begincom{subst, subst-if, subst-if-not, nsubst, nsubst-if, nsubst-if-not}\ftype{Function}
  585. \label Syntax::
  586. \DefunWithValues subst {new old tree {\key} key test test-not} {new-tree}
  587. \DefunWithValues subst-if {new predicate tree {\key} key} {new-tree}
  588. \DefunWithValues subst-if-not {new predicate tree {\key} key} {new-tree}
  589. \DefunWithValues nsubst {new old tree {\key} key test test-not} {new-tree}
  590. \DefunWithValues nsubst-if {new predicate tree {\key} key} {new-tree}
  591. \DefunWithValues nsubst-if-not {new predicate tree {\key} key} {new-tree}
  592. \label Arguments and Values::
  593. \param{new}---an \term{object}.
  594. \param{old}---an \term{object}.
  595. \param{predicate}---a \term{symbol} that names a \term{function},
  596. or a \term{function} of one argument
  597. that returns a \term{generalized boolean} value.
  598. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  599. \param{tree}---a \term{tree}.
  600. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  601. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  602. that returns a \term{generalized boolean}.
  603. \param{test-not}---a \term{designator} for
  604. a \term{function} of two \term{arguments}
  605. that returns a \term{generalized boolean}.
  606. \param{key}---a \term{designator} for a \term{function} of one argument,
  607. or \nil.
  608. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  609. \param{new-tree}---a \term{tree}.
  610. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  611. \label Description::
  612. \funref{subst}, \funref{subst-if}, and \funref{subst-if-not} perform
  613. substitution operations on \param{tree}.
  614. Each function searches \param{tree} for occurrences of a
  615. particular \param{old} item of an element or subexpression that
  616. \term{satisfies the test}.
  617. \funref{nsubst}, \funref{nsubst-if}, and \funref{nsubst-if-not} are
  618. like \funref{subst},
  619. \funref{subst-if}, and \funref{subst-if-not} respectively, except that the
  620. original \param{tree} is modified.
  621. %% 15.4.0 4
  622. \funref{subst} makes a copy of \param{tree},
  623. substituting \param{new} for every subtree or leaf of \param{tree}
  624. (whether the subtree or leaf is a \term{car} or a \term{cdr} of its parent)
  625. such that \param{old} and the subtree or leaf \term{satisfy the test}.
  626. %% 15.4.0 7
  627. \funref{nsubst} is a destructive version of \funref{subst}.
  628. The list structure of
  629. \param{tree} is altered by destructively replacing with \param{new}
  630. each leaf of the \param{tree} such that \param{old} and the leaf
  631. \term{satisfy the test}.
  632. %% Implied by "satisfy the test".
  633. % Either \kwd{test} or \kwd{test-not} can
  634. % be used to supply a test function other than the default.
  635. % The first argument to the \kwd{test} or \kwd{test-not} function
  636. % is \param{old};
  637. % the second argument is
  638. % the part of an element of \param{tree}
  639. % extracted by the \kwd{key} function (if supplied).
  640. % The argument to the \kwd{key} function is an
  641. % element of \param{tree}; the return value is part of the supplied
  642. % argument.
  643. % If \kwd{key} is not supplied, the element from
  644. % \param{tree} is supplied to the \kwd{test} or \kwd{test-not} function.
  645. For \funref{subst}, \funref{subst-if},
  646. and \funref{subst-if-not},
  647. if the functions succeed, a new
  648. copy of the tree is returned in which each occurrence of such an
  649. element is replaced by the
  650. \param{new} element or subexpression. If no changes are made, the original
  651. \param{tree} may be returned.
  652. The original \param{tree} is left unchanged, but the result tree
  653. may share storage with it.
  654. For \funref{nsubst}, \funref{nsubst-if},
  655. and \funref{nsubst-if-not}
  656. the original \param{tree} is modified and returned as the function result,
  657. but the result may not be \funref{eq} to \param{tree}.
  658. %!!! Barmar: Huh??? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  659. \label Examples::
  660. %% 15.4.0 6
  661. \code
  662. (setq tree1 '(1 (1 2) (1 2 3) (1 2 3 4))) \EV (1 (1 2) (1 2 3) (1 2 3 4))
  663. (subst "two" 2 tree1) \EV (1 (1 "two") (1 "two" 3) (1 "two" 3 4))
  664. (subst "five" 5 tree1) \EV (1 (1 2) (1 2 3) (1 2 3 4))
  665. (eq tree1 (subst "five" 5 tree1)) \EV \term{implementation-dependent}
  666. (subst 'tempest 'hurricane
  667. '(shakespeare wrote (the hurricane)))
  668. \EV (SHAKESPEARE WROTE (THE TEMPEST))
  669. (subst 'foo 'nil '(shakespeare wrote (twelfth night)))
  670. \EV (SHAKESPEARE WROTE (TWELFTH NIGHT . FOO) . FOO)
  671. (subst '(a . cons) '(old . pair)
  672. '((old . spice) ((old . shoes) old . pair) (old . pair))
  673. :test #'equal)
  674. \EV ((OLD . SPICE) ((OLD . SHOES) A . CONS) (A . CONS))
  675. (subst-if 5 #'listp tree1) \EV 5
  676. (subst-if-not '(x) #'consp tree1)
  677. \EV (1 X)
  678. tree1 \EV (1 (1 2) (1 2 3) (1 2 3 4))
  679. (nsubst 'x 3 tree1 :key #'(lambda (y) (and (listp y) (third y))))
  680. \EV (1 (1 2) X X)
  681. tree1 \EV (1 (1 2) X X)
  682. \endcode
  683. \label Side Effects::
  684. %% 15.4.0 7
  685. \funref{nsubst}, \funref{nsubst-if}, and \funref{nsubst-if-not}
  686. might alter the \term{tree structure} of \param{tree}.
  687. \label Affected By:\None.
  688. \label Exceptional Situations:\None.
  689. \label See Also::
  690. \funref{substitute},
  691. \funref{nsubstitute},
  692. \issue{CONSTANT-MODIFICATION:DISALLOW}
  693. {\secref\ConstantModification},
  694. \endissue{CONSTANT-MODIFICATION:DISALLOW}
  695. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  696. {\secref\TraversalRules}
  697. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  698. \label Notes::
  699. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  700. The \kwd{test-not} parameter is deprecated.
  701. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  702. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  703. The functions \funref{subst-if-not} and \funref{nsubst-if-not} are deprecated.
  704. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  705. One possible definition of \funref{subst}:
  706. %% Indentation fixed per Boyer/Kaufmann/Moore #13 (by X3J13 vote at May 4-5, 1994 meeting)
  707. %% -kmp 9-May-94
  708. \code
  709. (defun subst (old new tree &rest x &key test test-not key)
  710. (cond ((satisfies-the-test old tree :test test
  711. :test-not test-not :key key)
  712. new)
  713. ((atom tree) tree)
  714. (t (let ((a (apply #'subst old new (car tree) x))
  715. (d (apply #'subst old new (cdr tree) x)))
  716. (if (and (eql a (car tree))
  717. (eql d (cdr tree)))
  718. tree
  719. (cons a d))))))
  720. \endcode
  721. \endcom
  722. %%% ========== TREE-EQUAL
  723. \begincom{tree-equal}\ftype{Function}
  724. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  725. \label Syntax::
  726. \DefunWithValues tree-equal {tree-1 tree-2 {\key} test test-not} {generalized-boolean}
  727. \label Arguments and Values::
  728. \param{tree-1}---a \term{tree}.
  729. \param{tree-2}---a \term{tree}.
  730. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  731. that returns a \term{generalized boolean}.
  732. \param{test-not}---a \term{designator} for
  733. a \term{function} of two \term{arguments}
  734. that returns a \term{generalized boolean}.
  735. \param{generalized-boolean}---a \term{generalized boolean}.
  736. \label Description::
  737. %% 15.1.0 8
  738. \funref{tree-equal} tests whether two trees are of the same shape
  739. and have the same leaves.
  740. \funref{tree-equal} returns \term{true} if \param{tree-1} and \param{tree-2} are
  741. both \term{atoms} and \term{satisfy the test},
  742. or if they are both \term{conses} and
  743. the \term{car} of \param{tree-1} is \funref{tree-equal} to
  744. the \term{car} of \param{tree-2} and
  745. the \term{cdr} of \param{tree-1} is \funref{tree-equal} to
  746. the \term{cdr} of \param{tree-2}.
  747. Otherwise, \funref{tree-equal} returns \term{false}.
  748. \funref{tree-equal} recursively compares \term{conses} but not any
  749. other \term{objects} that have components.
  750. The first argument to the \kwd{test} or \kwd{test-not}
  751. function is \param{tree-1} or a \term{car} or \term{cdr} of \param{tree-1};
  752. the second argument is \param{tree-2} or a \term{car}
  753. or \term{cdr} of \param{tree-2}.
  754. \label Examples::
  755. \code
  756. (setq tree1 '(1 (1 2))
  757. tree2 '(1 (1 2))) \EV (1 (1 2))
  758. (tree-equal tree1 tree2) \EV \term{true}
  759. (eql tree1 tree2) \EV \term{false}
  760. (setq tree1 '('a ('b 'c))
  761. tree2 '('a ('b 'c))) \EV ('a ('b 'c))
  762. \EV ((QUOTE A) ((QUOTE B) (QUOTE C)))
  763. (tree-equal tree1 tree2 :test 'eq) \EV \term{true}
  764. \endcode
  765. \label Side Effects:\None.
  766. \label Affected By:\None.
  767. \label Exceptional Situations::
  768. The consequences are undefined
  769. if both \param{tree-1} and \param{tree-2} are circular.
  770. \label See Also::
  771. \funref{equal},
  772. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  773. {\secref\TraversalRules}
  774. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  775. \label Notes::
  776. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  777. The \kwd{test-not} parameter is deprecated.
  778. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  779. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  780. \endcom
  781. %-------------------- List --------------------
  782. %%% ========== COPY-LIST
  783. \begincom{copy-list}\ftype{Function}
  784. \label Syntax::
  785. \DefunWithValues copy-list {list} {copy}
  786. \label Arguments and Values::
  787. \param{list}---a \term{proper list} or a \term{dotted list}.
  788. \param{copy}---a \term{list}.
  789. \label Description::
  790. %% 15.2.0 23
  791. Returns a \term{copy} of \param{list}.
  792. If \param{list} is a \term{dotted list},
  793. the resulting \term{list} will also be a \term{dotted list}.
  794. Only the \term{list structure} of \param{list} is copied;
  795. the \term{elements} of the resulting list are
  796. the \term{same} as the corresponding \term{elements} of the given \param{list}.
  797. \label Examples::
  798. \code
  799. (setq lst (list 1 (list 2 3))) \EV (1 (2 3))
  800. (setq slst lst) \EV (1 (2 3))
  801. (setq clst (copy-list lst)) \EV (1 (2 3))
  802. (eq slst lst) \EV \term{true}
  803. (eq clst lst) \EV \term{false}
  804. (equal clst lst) \EV \term{true}
  805. (rplaca lst "one") \EV ("one" (2 3))
  806. slst \EV ("one" (2 3))
  807. clst \EV (1 (2 3))
  808. (setf (caadr lst) "two") \EV "two"
  809. lst \EV ("one" ("two" 3))
  810. slst \EV ("one" ("two" 3))
  811. clst \EV (1 ("two" 3))
  812. \endcode
  813. \label Side Effects:\None.
  814. \label Affected By:\None.
  815. \label Exceptional Situations::
  816. The consequences are undefined if \param{list} is a \term{circular list}.
  817. \label See Also::
  818. \funref{copy-alist},
  819. \funref{copy-seq},
  820. \funref{copy-tree}
  821. \label Notes::
  822. The copy created is \funref{equal} to \param{list}, but not \funref{eq}.
  823. \endcom
  824. %%% ========== LIST
  825. %%% ========== LIST*
  826. \begincom{list, list*}\ftype{Function}
  827. \label Syntax::
  828. \DefunWithValues {list} {{\rest} objects} {list}
  829. \DefunWithValues {list*} {{\rest} \plus{objects}} {result}
  830. \label Arguments and Values::
  831. \param{object}---an \term{object}.
  832. \param{list}---a \term{list}.
  833. \param{result}---an \term{object}.
  834. %A (possibly dotted) list, if at least 2 args are given.
  835. \label Description::
  836. %% 15.2.0 17
  837. \funref{list} returns a \term{list} containing the supplied \param{objects}.
  838. %% 15.2.0 18
  839. \funref{list*} is like \funref{list} except that
  840. the last \term{argument} to \funref{list} becomes
  841. the \term{car} of the last \term{cons} constructed, while
  842. the last \term{argument} to \funref{list*} becomes
  843. the \term{cdr} of the last \term{cons} constructed.
  844. Hence, any given call to \funref{list*} always produces one fewer \term{conses}
  845. than a call to \funref{list} with the same number of arguments.
  846. If the last \term{argument} to \funref{list*} is a \term{list},
  847. the effect is to construct a new \term{list} which is similar, but
  848. which has additional elements added to the front corresponding to
  849. the preceding \term{arguments} of \funref{list*}.
  850. If \funref{list*} receives only one \param{object},
  851. that \param{object} is returned, regardless of whether or not it is a \term{list}.
  852. \label Examples::
  853. \code
  854. (list 1) \EV (1)
  855. (list* 1) \EV 1
  856. (setq a 1) \EV 1
  857. (list a 2) \EV (1 2)
  858. '(a 2) \EV (A 2)
  859. (list 'a 2) \EV (A 2)
  860. (list* a 2) \EV (1 . 2)
  861. (list) \EV NIL ;\ie ()
  862. (setq a '(1 2)) \EV (1 2)
  863. (eq a (list* a)) \EV \term{true}
  864. (list 3 4 'a (car '(b . c)) (+ 6 -2)) \EV (3 4 A B 4)
  865. (list* 'a 'b 'c 'd) \EQ (cons 'a (cons 'b (cons 'c 'd))) \EV (A B C . D)
  866. (list* 'a 'b 'c '(d e f)) \EV (A B C D E F)
  867. \endcode
  868. \label Side Effects:\None.
  869. \label Affected By:\None.
  870. \label Exceptional Situations:\None.
  871. \label See Also::
  872. \funref{cons}
  873. \label Notes::
  874. \code
  875. (list* \param{x}) \EQ \param{x}
  876. \endcode
  877. \endcom
  878. %%% ========== LIST-LENGTH
  879. \begincom{list-length}\ftype{Function}
  880. \label Syntax::
  881. \DefunWithValues list-length {list} {length}
  882. \label Arguments and Values::
  883. \param{list}---a \term{proper list} or a \term{circular list}.
  884. \param{length}---a non-negative \term{integer}, or \nil.
  885. \label Description::
  886. %% 15.2.0 5
  887. Returns the \term{length} of \param{list} if \param{list} is a \term{proper list}.
  888. Returns \nil\ if \param{list} is a \term{circular list}.
  889. \label Examples::
  890. \code
  891. (list-length '(a b c d)) \EV 4
  892. (list-length '(a (b c) d)) \EV 3
  893. (list-length '()) \EV 0
  894. (list-length nil) \EV 0
  895. (defun circular-list (&rest elements)
  896. (let ((cycle (copy-list elements)))
  897. (nconc cycle cycle)))
  898. (list-length (circular-list 'a 'b)) \EV NIL
  899. (list-length (circular-list 'a)) \EV NIL
  900. (list-length (circular-list)) \EV 0
  901. \endcode
  902. \label Side Effects:\None.
  903. \label Affected By:\None.
  904. \label Exceptional Situations::
  905. \Shouldchecktype{list}{a \term{proper list} or a \term{circular list}}
  906. \label See Also::
  907. \funref{length}
  908. \label Notes::
  909. \funref{list-length} could be implemented as follows:
  910. \code
  911. (defun list-length (x)
  912. (do ((n 0 (+ n 2)) ;Counter.
  913. (fast x (cddr fast)) ;Fast pointer: leaps by 2.
  914. (slow x (cdr slow))) ;Slow pointer: leaps by 1.
  915. (nil)
  916. ;; If fast pointer hits the end, return the count.
  917. (when (endp fast) (return n))
  918. (when (endp (cdr fast)) (return (+ n 1)))
  919. ;; If fast pointer eventually equals slow pointer,
  920. ;; then we must be stuck in a circular list.
  921. ;; (A deeper property is the converse: if we are
  922. ;; stuck in a circular list, then eventually the
  923. ;; fast pointer will equal the slow pointer.
  924. ;; That fact justifies this implementation.)
  925. (when (and (eq fast slow) (> n 0)) (return nil))))
  926. \endcode
  927. \endcom
  928. %%% ========== LISTP
  929. \begincom{listp}\ftype{Function}
  930. \label Syntax::
  931. \DefunWithValues listp {object} {generalized-boolean}
  932. \label Arguments and Values::
  933. \param{object}---an \term{object}.
  934. \param{generalized-boolean}---a \term{generalized boolean}.
  935. \label Description::
  936. %% 6.2.2 10
  937. \TypePredicate{object}{list}
  938. \label Examples::
  939. \code
  940. (listp nil) \EV \term{true}
  941. (listp (cons 1 2)) \EV \term{true}
  942. (listp (make-array 6)) \EV \term{false}
  943. (listp t) \EV \term{false}
  944. \endcode
  945. \label Side Effects:\None.
  946. \label Affected By:\None.
  947. \label Exceptional Situations:\None!
  948. \label See Also::
  949. \funref{consp}
  950. \label Notes::
  951. %This is implied by type list, but still worth saying. -kmp
  952. If \param{object} is a \term{cons},
  953. \funref{listp} does not check whether \param{object} is a \term{proper list};
  954. it returns \term{true} for any kind of \term{list}.
  955. \code
  956. (listp \param{object}) \EQ (typep \param{object} 'list) \EQ (typep \param{object} '(or cons null))
  957. \endcode
  958. \endcom
  959. %%% ========== MAKE-LIST
  960. \begincom{make-list}\ftype{Function}
  961. \label Syntax::
  962. \DefunWithValues make-list {size {\key} initial-element} {list}
  963. \label Arguments and Values::
  964. \param{size}---a non-negative \term{integer}.
  965. \param{initial-element}---an \term{object}.
  966. \Default{\nil}
  967. \param{list}---a \term{list}.
  968. \label Description::
  969. %% 15.2.0 19
  970. Returns a \term{list} of \param{length} given by \term{size},
  971. each of the \term{elements} of which is \param{initial-element}.
  972. \label Examples::
  973. \code
  974. (make-list 5) \EV (NIL NIL NIL NIL NIL)
  975. (make-list 3 :initial-element 'rah) \EV (RAH RAH RAH)
  976. (make-list 2 :initial-element '(1 2 3)) \EV ((1 2 3) (1 2 3))
  977. (make-list 0) \EV NIL ;\ie ()
  978. (make-list 0 :initial-element 'new-element) \EV NIL
  979. \endcode
  980. \label Side Effects:\None.
  981. \label Affected By:\None.
  982. \label Exceptional Situations::
  983. \Shouldchecktype{size}{a non-negative \term{integer}}
  984. \label See Also::
  985. \funref{cons},
  986. \funref{list}
  987. \label Notes:\None.
  988. \endcom
  989. %-------------------- List Elements --------------------
  990. %%% ========== PUSH
  991. \begincom{push}\ftype{Macro}
  992. \label Syntax::
  993. \DefmacWithValues push {item place} {new-place-value}
  994. \label Arguments and Values::
  995. \param{item}---an \term{object}.
  996. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  997. \param{place}---a \term{place}, the \term{value} of which may be any \term{object}.
  998. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  999. \param{new-place-value}---a \term{list} (the new \term{value} of \param{place}).
  1000. \label Description::
  1001. \macref{push} prepends \param{item} to the \term{list} that is stored
  1002. in \param{place}, stores the resulting \term{list} in \param{place},
  1003. and returns the \term{list}.
  1004. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  1005. For information about the \term{evaluation} of \term{subforms} of \param{place},
  1006. \seesection\GenRefSubFormEval.
  1007. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  1008. \label Examples::
  1009. %% 15.2.0 31
  1010. \code
  1011. (setq llst '(nil)) \EV (NIL)
  1012. (push 1 (car llst)) \EV (1)
  1013. llst \EV ((1))
  1014. (push 1 (car llst)) \EV (1 1)
  1015. llst \EV ((1 1))
  1016. (setq x '(a (b c) d)) \EV (A (B C) D)
  1017. (push 5 (cadr x)) \EV (5 B C)
  1018. x \EV (A (5 B C) D)
  1019. \endcode
  1020. \label Side Effects::
  1021. The contents of \param{place} are modified.
  1022. \label Affected By:\None.
  1023. \label Exceptional Situations:\None.
  1024. \label See Also::
  1025. \macref{pop},
  1026. \macref{pushnew},
  1027. {\secref\GeneralizedReference}
  1028. \label Notes::
  1029. The effect of \f{(push \i{item} \i{place})}
  1030. is equivalent to
  1031. \code
  1032. (setf place (cons \i{item} \i{place}))
  1033. \endcode
  1034. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  1035. except that the \term{subforms} of \param{place}
  1036. are evaluated only once, and \param{item} is evaluated
  1037. before \param{place}.
  1038. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  1039. \endcom
  1040. %%% ========== POP
  1041. \begincom{pop}\ftype{Macro}
  1042. \label Syntax::
  1043. \DefmacWithValues pop {place} {element}
  1044. \label Arguments and Values::
  1045. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1046. \param{place}---a \term{place}, the \term{value} of which is a \term{list}
  1047. (possibly, but necessarily, a \term{dotted list} or \term{circular list}).
  1048. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1049. \param{element}---an \term{object} (the \term{car} of the contents of \param{place}).
  1050. \label Description::
  1051. %% 15.2.0 35
  1052. \macref{pop} \term{reads} the \term{value} of \param{place},
  1053. remembers the \term{car} of the \term{list} which was retrieved,
  1054. \term{writes} the \term{cdr} of the \term{list} back into the \param{place},
  1055. and finally \term{yields} the \term{car} of the originally retrieved \term{list}.
  1056. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  1057. For information about the \term{evaluation} of \term{subforms} of \param{place},
  1058. \seesection\GenRefSubFormEval.
  1059. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  1060. \label Examples::
  1061. \code
  1062. (setq stack '(a b c)) \EV (A B C)
  1063. (pop stack) \EV A
  1064. stack \EV (B C)
  1065. (setq llst '((1 2 3 4))) \EV ((1 2 3 4))
  1066. (pop (car llst)) \EV 1
  1067. llst \EV ((2 3 4))
  1068. \endcode
  1069. \label Side Effects::
  1070. The contents of \param{place} are modified.
  1071. \label Affected By:\None.
  1072. \label Exceptional Situations:\None.
  1073. \label See Also::
  1074. \macref{push},
  1075. \macref{pushnew},
  1076. {\secref\GeneralizedReference}
  1077. \label Notes::
  1078. The effect of \f{(pop \param{place})} is roughly equivalent to
  1079. \code
  1080. (prog1 (car \param{place}) (setf \param{place} (cdr \param{place})))
  1081. \endcode
  1082. except that the latter would evaluate any \term{subforms} of \param{place}
  1083. three times, while \macref{pop} evaluates them only once.
  1084. \endcom
  1085. %%% ========== FIRST
  1086. %%% ========== SECOND
  1087. %%% ========== THIRD
  1088. %%% ========== FOURTH
  1089. %%% ========== FIFTH
  1090. %%% ========== SIXTH
  1091. %%% ========== SEVENTH
  1092. %%% ========== EIGHTH
  1093. %%% ========== NINTH
  1094. %%% ========== TENTH
  1095. \begincom{first, second, third, fourth, fifth,
  1096. sixth, seventh, eighth, ninth, tenth}\ftype{Accessor}
  1097. \label Syntax::
  1098. \DefunMultiAccessorWithValues {list} {object} {new-object}
  1099. {\entry{first}
  1100. \entry{second}
  1101. \entry{third}
  1102. \entry{fourth}
  1103. \entry{fifth}
  1104. \entry{sixth}
  1105. \entry{seventh}
  1106. \entry{eighth}
  1107. \entry{ninth}
  1108. \entry{tenth}}
  1109. \label Arguments and Values::
  1110. \param{list}---a \term{list},
  1111. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1112. which might be a \term{dotted list} or a \term{circular list}.
  1113. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1114. \param{object}, \param{new-object}---an \param{object}.
  1115. \label Description::
  1116. The functions
  1117. %% 15.2.0 11
  1118. \funref{first},
  1119. \funref{second},
  1120. \funref{third},
  1121. \funref{fourth},
  1122. \funref{fifth},
  1123. \funref{sixth},
  1124. \funref{seventh},
  1125. \funref{eighth},
  1126. \funref{ninth},
  1127. and
  1128. \funref{tenth}
  1129. %% 15.2.0 12
  1130. \param{access} the first, second, third, fourth, fifth, sixth, seventh, eighth,
  1131. ninth, and tenth \term{elements} of \param{list}, respectively.
  1132. %% I changed this to be in terms of car/cdr because I felt this made
  1133. %% the error checking requirements more apparent. -kmp 27-Aug-93
  1134. % If there is no such \term{element} during a \term{read}, \nil\ is returned.
  1135. % The consequences are undefined if there is no such \term{element} during a \term{write}.
  1136. Specifically,
  1137. \code
  1138. (first \param{list}) \EQ (car \param{list})
  1139. (second \param{list}) \EQ (car (cdr \param{list}))
  1140. (third \param{list}) \EQ (car (cddr \param{list}))
  1141. (fourth \param{list}) \EQ (car (cdddr \param{list}))
  1142. (fifth \param{list}) \EQ (car (cddddr \param{list}))
  1143. (sixth \param{list}) \EQ (car (cdr (cddddr \param{list})))
  1144. (seventh \param{list}) \EQ (car (cddr (cddddr \param{list})))
  1145. (eighth \param{list}) \EQ (car (cdddr (cddddr \param{list})))
  1146. (ninth \param{list}) \EQ (car (cddddr (cddddr \param{list})))
  1147. (tenth \param{list}) \EQ (car (cdr (cddddr (cddddr \param{list}))))
  1148. \endcode
  1149. \macref{setf} can also be used with any of these functions to change an
  1150. existing component. The same equivalences apply. For example:
  1151. \code
  1152. (setf (fifth \param{list}) \param{new-object}) \EQ (setf (car (cddddr \param{list})) \param{new-object})
  1153. \endcode
  1154. \label Examples::
  1155. \code
  1156. (setq lst '(1 2 3 (4 5 6) ((V)) vi 7 8 9 10))
  1157. \EV (1 2 3 (4 5 6) ((V)) VI 7 8 9 10)
  1158. (first lst) \EV 1
  1159. (tenth lst) \EV 10
  1160. (fifth lst) \EV ((V))
  1161. (second (fourth lst)) \EV 5
  1162. (sixth '(1 2 3)) \EV NIL
  1163. (setf (fourth lst) "four") \EV "four"
  1164. lst \EV (1 2 3 "four" ((V)) VI 7 8 9 10)
  1165. \endcode
  1166. \label Side Effects:\None.
  1167. \label Affected By:\None.
  1168. \label Exceptional Situations:\None.
  1169. \label See Also::
  1170. \funref{car}, \funref{nth}
  1171. \label Notes::
  1172. \funref{first} is functionally equivalent to \funref{car},
  1173. \funref{second} is functionally equivalent to \funref{cadr},
  1174. \funref{third} is functionally equivalent to \funref{caddr}, and
  1175. \funref{fourth} is functionally equivalent to \funref{cadddr}.
  1176. The ordinal numbering used here is one-origin,
  1177. as opposed to the zero-origin numbering used by \funref{nth}:
  1178. \code
  1179. (fifth x) \EQ (nth 4 x)
  1180. \endcode
  1181. \endcom
  1182. %%% ========== NTH
  1183. \begincom{nth}\ftype{Accessor}
  1184. \label Syntax::
  1185. \DefunWithValues nth {n list} {object}
  1186. \Defsetf nth {n list} {new-object}
  1187. \label Arguments and Values::
  1188. \param{n}---a non-negative \term{integer}.
  1189. \param{list}---a \term{list},
  1190. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1191. which might be a \term{dotted list} or a \term{circular list}.
  1192. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1193. \param{object}---an \term{object}.
  1194. \param{new-object}---an \term{object}.
  1195. \label Description::
  1196. \funref{nth} locates the \param{n}th element of \param{list},
  1197. where the \term{car} of the \param{list} is the ``zeroth'' element.
  1198. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1199. % If the length of \param{list} is not greater than \param{n},
  1200. % then the result is \nil.
  1201. Specifically,
  1202. \code
  1203. (nth \param{n} \param{list}) \EQ (car (nthcdr \param{n} \param{list}))
  1204. \endcode
  1205. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1206. %% 15.2.0 8
  1207. \funref{nth} may be used to specify a \param{place} to \macref{setf}.
  1208. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1209. Specifically,
  1210. % when \funref{nth} is used in this way, \param{n} must be less
  1211. % than the length of the \param{list}.
  1212. \code
  1213. (setf (nth \param{n} \param{list}) \param{new-object}) \EQ (setf (car (nthcdr \param{n} \param{list})) \param{new-object})
  1214. \endcode
  1215. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1216. \label Examples::
  1217. %% 15.2.0 6
  1218. \code
  1219. (nth 0 '(foo bar baz)) \EV FOO
  1220. (nth 1 '(foo bar baz)) \EV BAR
  1221. (nth 3 '(foo bar baz)) \EV NIL
  1222. (setq 0-to-3 (list 0 1 2 3)) \EV (0 1 2 3)
  1223. (setf (nth 2 0-to-3) "two") \EV "two"
  1224. 0-to-3 \EV (0 1 "two" 3)
  1225. \endcode
  1226. \label Side Effects:\None.
  1227. \label Affected By:\None.
  1228. \label Exceptional Situations:\None.
  1229. \label See Also::
  1230. \funref{elt},
  1231. \funref{first},
  1232. \funref{nthcdr}
  1233. \label Notes:\None.
  1234. \endcom
  1235. %-------------------- List Tails --------------------
  1236. %%% ========== ENDP
  1237. \begincom{endp}\ftype{Function}
  1238. \label Syntax::
  1239. \DefunWithValues endp {list} {generalized-boolean}
  1240. \label Arguments and Values::
  1241. \param{list}---a \term{list},
  1242. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1243. which might be a \term{dotted list} or a \term{circular list}.
  1244. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1245. \param{generalized-boolean}---a \term{generalized boolean}.
  1246. \label Description::
  1247. %% 15.2.0 3
  1248. Returns \term{true} if \param{list} is the \term{empty list}.
  1249. Returns \term{false} if \param{list} is a \term{cons}.
  1250. \label Examples::
  1251. \code
  1252. (endp nil) \EV \term{true}
  1253. (endp '(1 2)) \EV \term{false}
  1254. (endp (cddr '(1 2))) \EV \term{true}
  1255. \endcode
  1256. \label Side Effects:\None.
  1257. \label Affected By:\None.
  1258. \label Exceptional Situations::
  1259. \Shouldchecktype{list}{a \term{list}}
  1260. \label See Also:\None.
  1261. \label Notes::
  1262. The purpose of \funref{endp} is to test for the end of \param{proper list}.
  1263. Since \funref{endp} does not descend into a \term{cons},
  1264. it is well-defined to pass it a \term{dotted list}.
  1265. However, if shorter ``lists'' are iteratively produced
  1266. by calling \funref{cdr} on such a \term{dotted list}
  1267. and those ``lists'' are tested with \funref{endp},
  1268. a situation that has undefined consequences will eventually result
  1269. when the \term{non-nil} \term{atom} (which is not in fact a \term{list})
  1270. finally becomes the argument to \funref{endp}.
  1271. Since this is the usual way in which \funref{endp} is used,
  1272. it is conservative programming style
  1273. and consistent with the intent of \funref{endp}
  1274. to treat \funref{endp} as simply a function on \term{proper lists}
  1275. which happens not to enforce an argument type of \term{proper list} except
  1276. when the argument is \term{atomic}.
  1277. \endcom
  1278. %%% ========== NULL
  1279. \begincom{null}\ftype{Function}
  1280. \issue{NOT-AND-NULL-RETURN-VALUE:X3J13-MAR-93}
  1281. \label Syntax::
  1282. \DefunWithValues null {object} {boolean}
  1283. \label Arguments and Values::
  1284. \param{object}---an \term{object}.
  1285. \param{boolean}---a \term{boolean}.
  1286. \label Description::
  1287. %% 6.2.2 3
  1288. \StrictPredicate{object}{the \term{empty list}}
  1289. \label Examples::
  1290. \code
  1291. (null '()) \EV T
  1292. (null nil) \EV T
  1293. (null t) \EV NIL
  1294. (null 1) \EV NIL
  1295. \endcode
  1296. \endissue{NOT-AND-NULL-RETURN-VALUE:X3J13-MAR-93}
  1297. \label Side Effects:\None.
  1298. \label Affected By:\None.
  1299. \label Exceptional Situations:\None!
  1300. \label See Also::
  1301. \funref{not}
  1302. \label Notes::
  1303. %% 6.4.0 4
  1304. \funref{null} is intended to be used to test for the \term{empty list}
  1305. whereas \funref{not} is intended to be used to invert a \term{boolean}
  1306. (or \term{generalized boolean}).
  1307. Operationally, \funref{null} and \funref{not} compute the same result;
  1308. which to use is a matter of style.
  1309. \code
  1310. (null \param{object}) \EQ (typep \param{object} 'null) \EQ (eq \param{object} '\empty)
  1311. \endcode
  1312. \endcom
  1313. %%% ========== NCONC
  1314. \begincom{nconc}\ftype{Function}
  1315. \label Syntax::
  1316. \DefunWithValues nconc {{\rest} lists} {concatenated-list}
  1317. \label Arguments and Values::
  1318. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1319. \param{list}---each but the last must be a \term{list}
  1320. (which might be a \param{dotted list} but must not be a \term{circular list});
  1321. the last \param{list} may be any \term{object}.
  1322. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1323. \param{concatenated-list}---a \term{list}.
  1324. \label Description::
  1325. % Note: Issue APPEND-DOTTED was repealed.
  1326. %% 15.2.0 28
  1327. Returns a \term{list} that is the concatenation of \param{lists}.
  1328. If no \param{lists} are supplied, \f{(nconc)} returns \nil.
  1329. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1330. \funref{nconc} is defined using the following recursive relationship:
  1331. \code
  1332. (nconc) \EV ()
  1333. (nconc nil . \param{lists}) \EQ (nconc . \param{lists})
  1334. (nconc \param{list}) \EV \param{list}
  1335. (nconc \param{list-1} \param{list-2}) \EQ (progn (rplacd (last \param{list-1}) \param{list-2}) \param{list-1})
  1336. (nconc \param{list-1} \param{list-2} . \param{lists}) \EQ (nconc (nconc \param{list-1} \param{list-2}) . \param{lists})
  1337. \endcode
  1338. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1339. \label Examples::
  1340. \code
  1341. (nconc) \EV NIL
  1342. (setq x '(a b c)) \EV (A B C)
  1343. (setq y '(d e f)) \EV (D E F)
  1344. (nconc x y) \EV (A B C D E F)
  1345. x \EV (A B C D E F)
  1346. \endcode
  1347. Note, in the example, that the value of \f{x} is now different,
  1348. since its last \term{cons}
  1349. has been \funref{rplacd}'d to the value of \f{y}.
  1350. If \f{(nconc x y)} were evaluated again,
  1351. it would yield a piece of a \term{circular list},
  1352. whose printed representation would be
  1353. \f{(A B C D E F D E F D E F ...)}, repeating forever;
  1354. if the \varref{*print-circle*} switch were \term{non-nil},
  1355. it would be printed as \f{(A B C . \#1=(D E F . \#1\#))}.
  1356. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1357. \code
  1358. (setq foo (list 'a 'b 'c 'd 'e)
  1359. bar (list 'f 'g 'h 'i 'j)
  1360. baz (list 'k 'l 'm)) \EV (K L M)
  1361. (setq foo (nconc foo bar baz)) \EV (A B C D E F G H I J K L M)
  1362. foo \EV (A B C D E F G H I J K L M)
  1363. bar \EV (F G H I J K L M)
  1364. baz \EV (K L M)
  1365. (setq foo (list 'a 'b 'c 'd 'e)
  1366. bar (list 'f 'g 'h 'i 'j)
  1367. baz (list 'k 'l 'm)) \EV (K L M)
  1368. (setq foo (nconc nil foo bar nil baz)) \EV (A B C D E F G H I J K L M)
  1369. foo \EV (A B C D E F G H I J K L M)
  1370. bar \EV (F G H I J K L M)
  1371. baz \EV (K L M)
  1372. \endcode
  1373. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1374. \label Side Effects::
  1375. The \param{lists} are modified rather than copied.
  1376. \label Affected By:\None.
  1377. \label Exceptional Situations:\None?
  1378. \label See Also::
  1379. \funref{append}, \funref{concatenate}
  1380. \label Notes:\None.
  1381. \endcom
  1382. %%% ========== APPEND
  1383. \begincom{append}\ftype{Function}
  1384. \label Syntax::
  1385. \DefunWithValues append {{\rest} lists} {result}
  1386. \label Arguments and Values::
  1387. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1388. \param{list}---each must be a \term{proper list} except the last,
  1389. which may be any \term{object}.
  1390. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1391. \param{result}---an \term{object}. This will be a \term{list}
  1392. unless the last \param{list} was not a \term{list}
  1393. %Sandra noted a but in the preceding.
  1394. and all preceding \param{lists} were \term{null}.
  1395. \label Description::
  1396. %% Issue APPEND-DOTTED had an effect here, but was later rescinded.
  1397. %% 15.2.0 20
  1398. \funref{append} returns a new \param{list} that is the concatenation of
  1399. the copies. \param{lists} are left unchanged; the \term{list structure}
  1400. of each of \param{lists} except the last is copied.
  1401. %% 15.2.0 21
  1402. The last argument is not copied; it becomes the \term{cdr} of the
  1403. final \term{dotted pair} of the concatenation of the preceding \param{lists},
  1404. or is returned directly if there are no preceding
  1405. % "non-empty" added with encouragement of Sandra and KAB. -kmp 28-Jan-92
  1406. \term{non-empty}
  1407. \param{lists}.
  1408. \label Examples::
  1409. \code
  1410. (append '(a b c) '(d e f) '() '(g)) \EV (A B C D E F G)
  1411. (append '(a b c) 'd) \EV (A B C . D)
  1412. (setq lst '(a b c)) \EV (A B C)
  1413. (append lst '(d)) \EV (A B C D)
  1414. lst \EV (A B C)
  1415. (append) \EV NIL
  1416. (append 'a) \EV A
  1417. \endcode
  1418. \label Affected By:\None.
  1419. \label Exceptional Situations:\None.
  1420. \label See Also::
  1421. \funref{nconc}, \funref{concatenate}
  1422. \label Notes:\None.
  1423. \endcom
  1424. %% Entries for REVAPPEND and NCONC consolidated. -kmp 29-Aug-93
  1425. %%% ========== REVAPPEND
  1426. %%% ========== NRECONC
  1427. \begincom{revappend, nreconc}\ftype{Function}
  1428. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1429. \label Syntax::
  1430. \DefunWithValues revappend {list tail} {result-list}
  1431. \DefunWithValues nreconc {list tail} {result-list}
  1432. \label Arguments and Values::
  1433. \param{list}---a \term{proper list}.
  1434. \param{tail}---an \term{object}.
  1435. \param{result-list}---an \term{object}.
  1436. \label Description::
  1437. \funref{revappend} constructs a \term{copy}\meaning{2} of \param{list},
  1438. but with the \term{elements} in reverse order. It then appends (as if
  1439. by \funref{nconc}) the \param{tail} to that reversed list and returns the result.
  1440. \funref{nreconc} reverses the order of \term{elements} in \param{list}
  1441. (as if by \funref{nreverse}). It then appends (as if by \funref{nconc})
  1442. the \param{tail} to that reversed list and returns the result.
  1443. The resulting \term{list} shares \term{list structure} with \param{tail}.
  1444. \label Examples::
  1445. \code
  1446. (let ((list-1 (list 1 2 3))
  1447. (list-2 (list 'a 'b 'c)))
  1448. (print (revappend list-1 list-2))
  1449. (print (equal list-1 '(1 2 3)))
  1450. (print (equal list-2 '(a b c))))
  1451. \OUT (3 2 1 A B C)
  1452. \OUT T
  1453. \OUT T
  1454. \EV T
  1455. (revappend '(1 2 3) '()) \EV (3 2 1)
  1456. (revappend '(1 2 3) '(a . b)) \EV (3 2 1 A . B)
  1457. (revappend '() '(a b c)) \EV (A B C)
  1458. (revappend '(1 2 3) 'a) \EV (3 2 1 . A)
  1459. (revappend '() 'a) \EV A ;degenerate case
  1460. (let ((list-1 '(1 2 3))
  1461. (list-2 '(a b c)))
  1462. (print (nreconc list-1 list-2))
  1463. (print (equal list-1 '(1 2 3)))
  1464. (print (equal list-2 '(a b c))))
  1465. \OUT (3 2 1 A B C)
  1466. \OUT NIL
  1467. \OUT T
  1468. \EV T
  1469. \endcode
  1470. \label Side Effects::
  1471. \funref{revappend} does not modify either of its \term{arguments}.
  1472. \funref{nreconc} is permitted to modify \param{list} but not \param{tail}.
  1473. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1474. Although it might be implemented differently,
  1475. \funref{nreconc} is constrained to have side-effect behavior equivalent to:
  1476. \code
  1477. (nconc (nreverse \param{list}) \param{tail})
  1478. \endcode
  1479. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1480. \label Affected By:\None.
  1481. \label Exceptional Situations:\None.
  1482. \label See Also::
  1483. \funref{reverse},
  1484. \funref{nreverse},
  1485. \funref{nconc}
  1486. \label Notes::
  1487. %% 15.2.0 27
  1488. %% 15.2.0 30
  1489. The following functional equivalences are true,
  1490. although good \term{implementations} will typically use a faster algorithm for
  1491. achieving the same effect:
  1492. \code
  1493. (revappend \param{list} \param{tail}) \EQ (nconc (reverse \param{list}) \param{tail})
  1494. (nreconc \param{list} \param{tail}) \EQ (nconc (nreverse \param{list}) \param{tail})
  1495. \endcode
  1496. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1497. \endcom
  1498. %% Entries for REVAPPEND and NCONC consolidated. -kmp 29-Aug-93
  1499. % %%% ========== NRECONC
  1500. % \begincom{nreconc}\ftype{Function}
  1501. %
  1502. % \label Syntax::
  1503. %
  1504. % \DefunWithValues nreconc {list-1 list-2} {result-list}
  1505. %
  1506. % \label Arguments and Values::
  1507. %
  1508. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1509. %
  1510. % \param{list-1}---a \term{proper list}.
  1511. %
  1512. % \param{list-2}---an \term{object}.
  1513. %
  1514. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1515. %
  1516. % \param{result-list}---an \term{object}.
  1517. %
  1518. % \label Description::
  1519. %
  1520. % \funref{nreconc} reverses the order of the elements in
  1521. % \param{list-1} and appends \param{list-2} to \param{list-1}
  1522. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1523. % (as if by \funref{nconc}).
  1524. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1525. % The new \param{list-1} is returned.
  1526. %
  1527. % \label Examples::
  1528. %
  1529. % \code
  1530. % (defparameter *list-1* (list 1 2 3))
  1531. % (defparameter *list-2* (list 'a 'b 'c))
  1532. % (nreconc *list-1* *list-2*) \EV (3 2 1 A B C)
  1533. % *list-1* \EV \term{implementation-dependent}
  1534. % *list-2* \EV (A B C)
  1535. %
  1536. % (nreconc (list) 'a) \EV A ;degenerate situation
  1537. % \endcode
  1538. %
  1539. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1540. % % \code
  1541. % % (nreconc (cons 1 2) nil) \EV (1)
  1542. % % \endcode
  1543. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1544. %
  1545. % \label Side Effects::
  1546. %
  1547. % \param{list-1} is modified.
  1548. %
  1549. % \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1550. % \funref{nreconc} is constrained to have side-effect behavior equivalent to:
  1551. %
  1552. % \f{(nconc (nreverse \param{list-1}) \param{list-2})}.
  1553. % \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  1554. %
  1555. % \label Affected By:\None.
  1556. %
  1557. % \label Exceptional Situations:\None?
  1558. %
  1559. % \label See Also::
  1560. %
  1561. % \funref{revappend}
  1562. %
  1563. % \label Notes::
  1564. % %% 15.2.0 30
  1565. % \f{(nreconc x y)} is exactly the same as
  1566. % \f{(nconc (nreverse x) y)} except that it is potentially more efficient.
  1567. %
  1568. % \endcom
  1569. %% Entries for REVAPPEND and NCONC consolidated. -kmp 29-Aug-93
  1570. % %%% ========== REVAPPEND
  1571. % \begincom{revappend}\ftype{Function}
  1572. %
  1573. % \label Syntax::
  1574. %
  1575. % \DefunWithValues revappend {list-1 list-2} {result-list}
  1576. %
  1577. % \label Arguments and Values::
  1578. %
  1579. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1580. % \param{list-1}---a \term{proper list}.
  1581. %
  1582. % \param{list-2}---an \term{object}.
  1583. %
  1584. % \param{result-list}---an \term{object}.
  1585. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1586. %
  1587. % \label Description::
  1588. %
  1589. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1590. % Constructs a \term{fresh} \term{list} that is a \term{copy} of \param{list-1}
  1591. % but with the \term{elements} in reverse order,
  1592. % and then appends \param{list-2} to that \term{list}
  1593. % (as if by \funref{nconc}).
  1594. % %(as if by \funref{append}).
  1595. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1596. %
  1597. % The resulting \term{list} shares \term{list structure} with \param{list-2}.
  1598. %
  1599. % \label Examples::
  1600. %
  1601. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1602. % \code
  1603. % (setq lst1 '(1 2 3)
  1604. % lst2 '(a b c)) \EV (A B C)
  1605. % (revappend lst1 lst2) \EV (3 2 1 A B C)
  1606. % lst1 \EV (1 2 3)
  1607. % lst2 \EV (A B C)
  1608. % (revappend '(1 2 3) '(a . b)) \EV (3 2 1 A . B)
  1609. % (revappend nil '(a b c)) \EV (A B C)
  1610. % (revappend '() 'a) \EV A ;degenerate case
  1611. % \endcode
  1612. %
  1613. % % \code
  1614. % % (revappend '(1 . 2) '(a b c)) \EV (1 A B C)
  1615. % % \endcode
  1616. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1617. %
  1618. % \label Side Effects:\None.
  1619. %
  1620. % \label Affected By:\None.
  1621. %
  1622. % \label Exceptional Situations:\None.
  1623. %
  1624. % \label See Also::
  1625. %
  1626. % \funref{nreconc}
  1627. %
  1628. % \label Notes::
  1629. % %% 15.2.0 27
  1630. %
  1631. % %"reverse" => "nconc" per Barrett
  1632. % \code
  1633. % (revappend x y) \EQ (nconc (reverse x) y)
  1634. % \endcode
  1635. %
  1636. % \endcom
  1637. %%% ========== NBUTLAST
  1638. %%% ========== BUTLAST
  1639. \begincom{butlast, nbutlast}\ftype{Function}
  1640. \label Syntax::
  1641. \DefunWithValues butlast {list {\opt} n} {result-list}
  1642. \DefunWithValues nbutlast {list {\opt} n} {result-list}
  1643. \label Arguments and Values::
  1644. \param{list}---a \term{list},
  1645. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1646. which might be a \term{dotted list} but must not be a \term{circular list}.
  1647. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1648. \issue{BUTLAST-NEGATIVE:SHOULD-SIGNAL}
  1649. \param{n}---a non-negative \term{integer}.
  1650. \endissue{BUTLAST-NEGATIVE:SHOULD-SIGNAL}
  1651. \param{result-list}---a \term{list}.
  1652. \label Description::
  1653. %% 15.2.0 36
  1654. \funref{butlast} returns a copy of \param{list} from which the last
  1655. \param{n}
  1656. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1657. %elements
  1658. conses
  1659. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1660. have been omitted.
  1661. If \param{n} is not supplied, its value is 1.
  1662. If there are fewer than \param{n}
  1663. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1664. %elements
  1665. conses
  1666. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1667. in \param{list},
  1668. \nil\ is returned and, in the case of \funref{nbutlast},
  1669. \param{list} is not modified.
  1670. %Barmar notes that if there are n elements, NIL is returned, too.
  1671. %He suggests says "fewer than n+1".
  1672. %But KMP thinks the definition already covers that, and the reason for the
  1673. %exception about NIL is to clarify the behavior in the cases not covered.
  1674. %% 15.2.0 37
  1675. \funref{nbutlast} is like \funref{butlast}, but \funref{nbutlast}
  1676. may modify \param{list}.
  1677. It changes the \term{cdr} of
  1678. the \term{cons} \param{n}+1 from the end of the \param{list} to \nil.
  1679. \label Examples::
  1680. \code
  1681. (setq lst '(1 2 3 4 5 6 7 8 9)) \EV (1 2 3 4 5 6 7 8 9)
  1682. (butlast lst) \EV (1 2 3 4 5 6 7 8)
  1683. (butlast lst 5) \EV (1 2 3 4)
  1684. (butlast lst (+ 5 5)) \EV NIL
  1685. lst \EV (1 2 3 4 5 6 7 8 9)
  1686. (nbutlast lst 3) \EV (1 2 3 4 5 6)
  1687. lst \EV (1 2 3 4 5 6)
  1688. (nbutlast lst 99) \EV NIL
  1689. lst \EV (1 2 3 4 5 6)
  1690. (butlast '(a b c d)) \EV (A B C)
  1691. (butlast '((a b) (c d))) \EV ((A B))
  1692. (butlast '(a)) \EV NIL
  1693. (butlast nil) \EV NIL
  1694. (setq foo (list 'a 'b 'c 'd)) \EV (A B C D)
  1695. (nbutlast foo) \EV (A B C)
  1696. foo \EV (A B C)
  1697. (nbutlast (list 'a)) \EV NIL
  1698. (nbutlast '()) \EV NIL
  1699. \endcode
  1700. % The following example was present but no one could figure out what
  1701. % made anyone think this would reliably work, so I removed it. -kmp 14-Feb-92
  1702. %
  1703. % (butlast '(1 2 . 3)) \EV (1)
  1704. \label Affected By:\None.
  1705. \label Exceptional Situations::
  1706. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1707. \Shouldchecktype{list}{a \term{proper list} or a \term{dotted list}}
  1708. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1709. \issue{BUTLAST-NEGATIVE:SHOULD-SIGNAL}
  1710. \Shouldchecktype{n}{a non-negative \term{integer}}
  1711. \endissue{BUTLAST-NEGATIVE:SHOULD-SIGNAL}
  1712. \label See Also:\None.
  1713. \label Notes::
  1714. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1715. \code
  1716. (butlast \param{list} \param{n}) \EQ (ldiff \param{list} (last \param{list} \param{n}))
  1717. \endcode
  1718. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1719. \endcom
  1720. %%% ========== LAST
  1721. \begincom{last}\ftype{Function}
  1722. \label Syntax::
  1723. \DefunWithValues last {list {\opt} n} {tail}
  1724. \label Arguments and Values::
  1725. \param{list}---a \term{list},
  1726. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1727. which might be a \term{dotted list} but must not be a \term{circular list}.
  1728. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1729. \issue{LAST-N}
  1730. \param{n}---a non-negative \term{integer}.
  1731. \Default{\f{1}}
  1732. \endissue{LAST-N}
  1733. \param{tail}---an \term{object}.
  1734. \label Description::
  1735. \issue{LAST-N}
  1736. %% 15.2.0 16
  1737. \funref{last} returns the last \param{n} \term{conses}
  1738. (not the last \param{n} elements) of \param{list}).
  1739. If \param{list} is \empty, \funref{last} returns \empty.
  1740. If \param{n} is zero,
  1741. the atom that terminates \param{list} is returned.
  1742. If \param{n} is greater than or equal to the number of \term{cons} cells in \param{list},
  1743. the result is \param{list}.
  1744. \endissue{LAST-N}
  1745. \label Examples::
  1746. \issue{LAST-N}
  1747. \code
  1748. (last nil) \EV NIL
  1749. (last '(1 2 3)) \EV (3)
  1750. (last '(1 2 . 3)) \EV (2 . 3)
  1751. (setq x (list 'a 'b 'c 'd)) \EV (A B C D)
  1752. (last x) \EV (D)
  1753. (rplacd (last x) (list 'e 'f)) x \EV (A B C D E F)
  1754. (last x) \EV (F)
  1755. (last '(a b c)) \EV (C)
  1756. (last '(a b c) 0) \EV ()
  1757. (last '(a b c) 1) \EV (C)
  1758. (last '(a b c) 2) \EV (B C)
  1759. (last '(a b c) 3) \EV (A B C)
  1760. (last '(a b c) 4) \EV (A B C)
  1761. (last '(a . b) 0) \EV B
  1762. (last '(a . b) 1) \EV (A . B)
  1763. (last '(a . b) 2) \EV (A . B)
  1764. \endcode
  1765. \endissue{LAST-N}
  1766. \label Side Effects:\None.
  1767. \label Affected By:\None.
  1768. \label Exceptional Situations::
  1769. \issue{LAST-N}
  1770. The consequences are undefined if \param{list} is a \term{circular list}.
  1771. \endissue{LAST-N}
  1772. \Shouldchecktype{n}{a non-negative \term{integer}}
  1773. \label See Also::
  1774. \funref{butlast},
  1775. \funref{nth}
  1776. \label Notes::
  1777. \issue{LAST-N}
  1778. The following code could be used to define \funref{last}.
  1779. \code
  1780. (defun last (list &optional (n 1))
  1781. (check-type n (integer 0))
  1782. (do ((l list (cdr l))
  1783. (r list)
  1784. (i 0 (+ i 1)))
  1785. ((atom l) r)
  1786. (if (>= i n) (pop r))))
  1787. \endcode
  1788. \endissue{LAST-N}
  1789. \endcom
  1790. %% Tentatively merged entries for LDIFF and TAILP. -kmp 29-Aug-93
  1791. %%% ========== LDIFF
  1792. %%% ========== TAILP
  1793. \begincom{ldiff, tailp}\ftype{Function}
  1794. \label Syntax::
  1795. \DefunWithValues ldiff {list object} {result-list}
  1796. \DefunWithValues tailp {object list} {generalized-boolean}
  1797. \label Arguments and Values::
  1798. \param{list}---a \term{list},
  1799. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1800. which might be a \term{dotted list}.
  1801. \param{object}---an \term{object}.
  1802. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1803. \param{result-list}---a \term{list}.
  1804. %% Per X3J13. -kmp 05-Oct-93
  1805. \param{generalized-boolean}---a \term{generalized boolean}.
  1806. \label Description::
  1807. \issue{TAILP-NIL:T}
  1808. %% 15.5.0 7
  1809. %% (CLtL definition superseded by later cleanup issue clarifying behavior.)
  1810. If \param{object} is the \term{same} as some \term{tail} of \param{list},
  1811. \funref{tailp} returns \term{true};
  1812. otherwise, it returns \term{false}.
  1813. \endissue{TAILP-NIL:T}
  1814. %% 15.2.0 38
  1815. If \param{object} is the \term{same} as some \term{tail} of \param{list},
  1816. \funref{ldiff} returns a \term{fresh} \term{list}
  1817. of the \term{elements} of \term{list}
  1818. that precede \funref{object} in the \term{list structure} of \param{list};
  1819. otherwise, it returns a \term{copy}\meaning{2} of \param{list}.
  1820. \label Examples::
  1821. \issue{TAILP-NIL:T}
  1822. \code
  1823. (let ((lists '#((a b c) (a b c . d))))
  1824. (dotimes (i (length lists)) ()
  1825. (let ((list (aref lists i)))
  1826. (format t "~2&list=~S ~21T(tailp object list)~
  1827. ~44T(ldiff list object)~%" list)
  1828. (let ((objects (vector list (cddr list) (copy-list (cddr list))
  1829. '(f g h) '() 'd 'x)))
  1830. (dotimes (j (length objects)) ()
  1831. (let ((object (aref objects j)))
  1832. (format t "~& object=~S ~21T~S ~44T~S"
  1833. object (tailp object list) (ldiff list object))))))))
  1834. \OUT
  1835. \OUT list=(A B C) (tailp object list) (ldiff list object)
  1836. \OUT object=(A B C) T NIL
  1837. \OUT object=(C) T (A B)
  1838. \OUT object=(C) NIL (A B C)
  1839. \OUT object=(F G H) NIL (A B C)
  1840. \OUT object=NIL T (A B C)
  1841. \OUT object=D NIL (A B C)
  1842. \OUT object=X NIL (A B C)
  1843. \OUT
  1844. \OUT list=(A B C . D) (tailp object list) (ldiff list object)
  1845. \OUT object=(A B C . D) T NIL
  1846. \OUT object=(C . D) T (A B)
  1847. \OUT object=(C . D) NIL (A B C . D)
  1848. \OUT object=(F G H) NIL (A B C . D)
  1849. \OUT object=NIL NIL (A B C . D)
  1850. \OUT object=D T (A B C)
  1851. \OUT object=X NIL (A B C . D)
  1852. \EV NIL
  1853. \endcode
  1854. \endissue{TAILP-NIL:T}
  1855. \label Side Effects::
  1856. Neither \funref{ldiff} nor \funref{tailp} modifies either of its \term{arguments}.
  1857. \label Affected By:\None.
  1858. \label Exceptional Situations::
  1859. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1860. \Lazychecktype{list}{a \term{proper list} or a \term{dotted list}}
  1861. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1862. \label See Also::
  1863. \funref{set-difference}
  1864. \label Notes::
  1865. If the \param{list} is a \term{circular list},
  1866. \funref{tailp} will reliably \term{yield} a \term{value}
  1867. only if the given \param{object} is in fact a \term{tail} of \param{list}.
  1868. Otherwise, the consequences are unspecified:
  1869. a given \term{implementation} which detects the circularity must return \term{false},
  1870. but since an \term{implementation} is not obliged to detect such a \term{situation},
  1871. \funref{tailp} might just loop indefinitely without returning in that case.
  1872. \issue{TAILP-NIL:T}
  1873. \funref{tailp} could be defined as follows:
  1874. \code
  1875. (defun tailp (object list)
  1876. (do ((list list (cdr list)))
  1877. ((atom list) (eql list object))
  1878. (if (eql object list)
  1879. (return t))))
  1880. \endcode
  1881. and \funref{ldiff} could be defined by:
  1882. %% !!! I just up the following based on the Description.
  1883. %% Does everyone agree it's right? -kmp 29-Aug-93
  1884. \code
  1885. (defun ldiff (list object)
  1886. (do ((list list (cdr list))
  1887. (r '() (cons (car list) r)))
  1888. ((atom list)
  1889. (if (eql list object) (nreverse r) (nreconc r list)))
  1890. (when (eql object list)
  1891. (return (nreverse r)))))
  1892. \endcode
  1893. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1894. % This stuff probably isn't needed. -kmp 7-Jan-91
  1895. %
  1896. % Since the \param{list} can be a \term{dotted list},
  1897. % the end test must be \funref{atom}, not \funref{endp}.
  1898. % For example, if \f{(tailp \i{x} l)} returns \term{true},
  1899. % it means that there is an \i{n} such that \f{(nthcdr \i{n} \param{list})} returns \i{x}.
  1900. %
  1901. % Note that it doesn't follow that if \term{tailp} returns \nil,
  1902. % it is safe to go \funref{nthcdr}'s into the \param{list} looking
  1903. % for \i{x}, since the \param{list} might be a \term{dotted list}
  1904. % and \funref{nthcdr} might hit bad data.
  1905. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1906. \endissue{TAILP-NIL:T}
  1907. \endcom
  1908. % %%% ========== LDIFF
  1909. % \begincom{ldiff}\ftype{Function}
  1910. %
  1911. % \label Syntax::
  1912. %
  1913. % \DefunWithValues ldiff {list object} {result-list}
  1914. %
  1915. % \label Arguments and Values::
  1916. %
  1917. % \param{list}---a \term{list},
  1918. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1919. % which might be a \term{dotted list}.
  1920. %
  1921. % \param{object}---an \term{object}.
  1922. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1923. %
  1924. % \param{result-list}---a \term{list}.
  1925. %
  1926. % \label Description::
  1927. %
  1928. % %!!! Rewrite in terms of glossary term "sublist" if we can get the issue
  1929. % % of dottedness resolved. -kmp 27-May-91
  1930. %
  1931. % %% 15.2.0 38
  1932. % Returns a \term{fresh} \term{list} whose \term{elements} are
  1933. % those \term{elements} of \param{list} that appear before \param{object}.
  1934. % If \param{object} is not a tail of \param{list} or
  1935. % if \param{object} is \nil,
  1936. % then a copy of the entire \param{list} is returned.
  1937. % \param{list} is not destroyed.
  1938. %
  1939. % % KMP: Can the list be dotted?
  1940. % % What is the status of (LDIFF '(A B C . 3) 3)?
  1941. % % Barrett: The description seems to imply that it cannot be dotted.
  1942. %
  1943. % \label Examples::
  1944. %
  1945. % \code
  1946. % (setq x '(a b c d e)) \EV (A B C D E)
  1947. % (setq y (cdddr x)) \EV (D E)
  1948. % (ldiff x y) \EV (A B C)
  1949. % (ldiff x (copy-list y)) \EV (A B C D E)
  1950. % \endcode
  1951. %
  1952. % \label Side Effects:\None.
  1953. %
  1954. % \label Affected By:\None.
  1955. %
  1956. % \label Exceptional Situations::
  1957. %
  1958. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1959. % \Lazychecktype{list}{a \term{proper list} or a \term{dotted list}}
  1960. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1961. %
  1962. % \label See Also::
  1963. %
  1964. % \funref{tailp},
  1965. % \funref{set-difference}
  1966. %
  1967. % \label Notes:\None.
  1968. %
  1969. % \endcom
  1970. %
  1971. % %%% ========== TAILP
  1972. % \begincom{tailp}\ftype{Function}
  1973. %
  1974. % \label Syntax::
  1975. %
  1976. % \DefunWithValues tailp {object list} {generalized-boolean}
  1977. %
  1978. % \label Arguments and Values::
  1979. %
  1980. % \param{object}---an \term{object}.
  1981. %
  1982. % \param{list}---a \term{list},
  1983. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1984. % which might be a \term{dotted list}.
  1985. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  1986. %
  1987. % \param{generalized-boolean}---a \term{generalized boolean}.
  1988. %
  1989. % \label Description::
  1990. %
  1991. % \issue{TAILP-NIL:T}
  1992. % %% 15.5.0 7
  1993. % %% (CLtL definition superseded by later cleanup issue clarifying behavior.)
  1994. %
  1995. % Returns \term{true} if and only if \param{object} is a \term{tail} of \param{list};
  1996. % otherwise returns \term{false}. The predicate used for comparison is \funref{eql}.
  1997. %
  1998. % Since the \param{list} can be a \term{dotted list},
  1999. % the end test used by \funref{tailp} must be \funref{atom}, not \funref{endp}.
  2000. % That is, if \f{(tailp \i{x} l)} returns \term{true},
  2001. % it means that there is an \i{n} such that \f{(nthcdr \i{n} \param{list})} returns \i{x}.
  2002. %
  2003. % \label Examples::
  2004. %
  2005. % \code
  2006. % (let ((x '(b c))) (tailp x (cons 'a x))) \EV \term{true}
  2007. % (tailp '(x y) '(a b c)) \EV \term{false}
  2008. % (tailp '() '(a b c)) \EV \term{true}
  2009. % (tailp 3 '(a b c)) \EV \term{false}
  2010. % (tailp 3 '(a b c . 3)) \EV \term{true}
  2011. % (tailp '(x y) '(a b c . 3)) \EV \term{false}
  2012. % \endcode
  2013. %
  2014. % \endissue{TAILP-NIL:T}
  2015. %
  2016. % \label Side Effects:\None.
  2017. %
  2018. % \label Affected By:\None.
  2019. %
  2020. % \label Exceptional Situations::
  2021. %
  2022. % \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2023. % \Lazychecktype{list}{a \term{proper list} or a \term{dotted list}}
  2024. % \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2025. %
  2026. % \label See Also::
  2027. %
  2028. % \funref{ldiff}
  2029. %
  2030. % \label Notes::
  2031. %
  2032. % If the \param{list} is a \term{circular list},
  2033. % \funref{tailp} will reliably \term{yield} a \term{value}
  2034. % only if the given \param{object} is in fact a \term{subtail}.
  2035. % Otherwise, the consequences are unspecified:
  2036. % a given \term{implementation} which detects the circularity must return \term{false},
  2037. % but since an \term{implementation} is not obliged to detect such a \term{situation},
  2038. % \funref{tailp} might just loop indefinitely without returning in that case.
  2039. %
  2040. % \issue{TAILP-NIL:T}
  2041. %
  2042. % \funref{tailp} could be defined as follows:
  2043. %
  2044. % \code
  2045. % (defun tailp (sublist list)
  2046. % (do ((list list (cdr list)))
  2047. % ((atom list) (eql list sublist))
  2048. % (if (eql sublist list)
  2049. % (return t))))
  2050. % \endcode
  2051. %
  2052. % % This probably isn't needed. -kmp 7-Jan-91
  2053. % %
  2054. % % Note that it doesn't follow that if \term{tailp} returns \nil,
  2055. % % it is safe to go \funref{nthcdr}'s into the \param{list} looking
  2056. % % for \i{x}, since the \param{list} might be a \term{dotted list}
  2057. % % and \funref{nthcdr} might hit bad data.
  2058. %
  2059. % \endissue{TAILP-NIL:T}
  2060. %
  2061. % \endcom
  2062. %%% ========== NTHCDR
  2063. \begincom{nthcdr}\ftype{Function}
  2064. \label Syntax::
  2065. \DefunWithValues nthcdr {n list} {tail}
  2066. \label Arguments and Values::
  2067. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  2068. \param{n}---a non-negative \term{integer}.
  2069. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  2070. \param{list}---a \term{list},
  2071. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2072. which might be a \term{dotted list} or a \term{circular list}.
  2073. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2074. \param{tail}---an \term{object}.
  2075. %\term{tail} of the \param{list}.
  2076. \label Description::
  2077. %% 15.2.0 14
  2078. %% Described using more descriptive terminology,
  2079. %% in a way that doesn't get confused about whether n is 0-based or 1-based. -kmp 29-Aug-93
  2080. %Returns the \param{n}th successive \term{cdr} of \param{list}.
  2081. Returns the \term{tail} of \param{list} that would be obtained by calling \funref{cdr}
  2082. \param{n} times in succession.
  2083. \label Examples::
  2084. % I added an example of high-safety error, to demonstrate relation of NTHCDR and CDR.
  2085. % -kmp 26-Aug-93
  2086. \code
  2087. (nthcdr 0 '()) \EV NIL
  2088. (nthcdr 3 '()) \EV NIL
  2089. (nthcdr 0 '(a b c)) \EV (A B C)
  2090. (nthcdr 2 '(a b c)) \EV (C)
  2091. (nthcdr 4 '(a b c)) \EV ()
  2092. (nthcdr 1 '(0 . 1)) \EV 1
  2093. (locally (declare (optimize (safety 3)))
  2094. (nthcdr 3 '(0 . 1)))
  2095. Error: Attempted to take CDR of 1.
  2096. \endcode
  2097. \label Side Effects:\None.
  2098. \label Affected By:\None.
  2099. \label Exceptional Situations::
  2100. %% I added this stuff because it seemed consistent with the other entries. -kmp 26-Aug-93
  2101. \Shouldchecktype{n}{a non-negative \term{integer}}
  2102. For \param{n} being an integer greater than \f{1},
  2103. the error checking done by \f{(nthcdr \param{n} \param{list})}
  2104. is the same as for \f{(nthcdr (- \param{n} 1) (cdr \param{list}))};
  2105. \seefun{cdr}.
  2106. \label See Also::
  2107. \funref{cdr},
  2108. \funref{nth},
  2109. \funref{rest}
  2110. \label Notes:\None.
  2111. \endcom
  2112. %%% ========== REST
  2113. \begincom{rest}\ftype{Accessor}
  2114. \label Syntax::
  2115. \DefunWithValues rest {list} {tail}
  2116. \Defsetf rest {list} {new-tail}
  2117. \label Arguments and Values::
  2118. \param{list}---a \term{list},
  2119. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2120. which might be a \term{dotted list} or a \term{circular list}.
  2121. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2122. \param{tail}---an \term{object}.
  2123. \label Description::
  2124. %% 15.2.0 13
  2125. \funref{rest} performs the same operation as \funref{cdr},
  2126. but mnemonically complements \funref{first}.
  2127. Specifically,
  2128. \code
  2129. (rest \param{list}) \EQ (cdr \param{list})
  2130. (setf (rest \param{list}) \param{new-tail}) \EQ (setf (cdr \param{list}) \param{new-tail})
  2131. \endcode
  2132. % If \param{list} is a \term{cons},
  2133. % \funref{rest} returns the portion that follows the first \term{element}.
  2134. % If \param{list} is the \term{empty list},
  2135. % \funref{rest} returns the \term{empty list}.
  2136. %
  2137. % \macref{setf} may be used with \funref{rest} to change
  2138. % the \term{cdr} of a \term{non-empty} \term{list} (\ie a \term{cons}).
  2139. \label Examples::
  2140. \code
  2141. (rest '(1 2)) \EV (2)
  2142. (rest '(1 . 2)) \EV 2
  2143. (rest '(1)) \EV NIL
  2144. (setq *cons* '(1 . 2)) \EV (1 . 2)
  2145. (setf (rest *cons*) "two") \EV "two"
  2146. *cons* \EV (1 . "two")
  2147. \endcode
  2148. \label Side Effects:\None.
  2149. \label Affected By:\None.
  2150. \label Exceptional Situations:\None.
  2151. \label See Also::
  2152. \funref{cdr},
  2153. \funref{nthcdr}
  2154. \label Notes::
  2155. \funref{rest} is often preferred stylistically over \funref{cdr}
  2156. when the argument is to being subjectively viewed as a \term{list}
  2157. rather than as a \term{cons}.
  2158. \endcom
  2159. %%% ========== MEMBER
  2160. %%% ========== MEMBER-IF
  2161. %%% ========== MEMBER-IF-NOT
  2162. \begincom{member, member-if, member-if-not}\ftype{Function}
  2163. \label Syntax::
  2164. \DefunWithValues member {item list {\key} key test test-not} {tail}
  2165. \DefunWithValues member-if {predicate list {\key} key} {tail}
  2166. \DefunWithValues member-if-not {predicate list {\key} key} {tail}
  2167. \label Arguments and Values::
  2168. \param{item}---an \term{object}.
  2169. \param{list}---a \term{proper list}.
  2170. \param{predicate}---a \term{designator} for
  2171. a \term{function} of one \term{argument}
  2172. that returns a \term{generalized boolean}.
  2173. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  2174. that returns a \term{generalized boolean}.
  2175. \param{test-not}---a \term{designator} for
  2176. a \term{function} of two \term{arguments}
  2177. that returns a \term{generalized boolean}.
  2178. \param{key}---a \term{designator} for a \term{function} of one argument,
  2179. or \nil.
  2180. \param{tail}---a \term{list}.
  2181. \label Description::
  2182. %% 15.5.0 4
  2183. \funref{member}, \funref{member-if}, and \funref{member-if-not} each
  2184. search \param{list} for \param{item} or for a top-level element that
  2185. \term{satisfies the test}. The argument to the \param{predicate} function
  2186. is an element of \param{list}.
  2187. %% Implied by "satifies the test". -kmp 15-Feb-92
  2188. % If \kwd{test} or \kwd{test-not} is not supplied,
  2189. % \funref{eql} is used.
  2190. % The first argument to the \kwd{test}
  2191. % or \kwd{test-not} function is \param{item}, and the second argument
  2192. % is an element of \param{list} as returned by the \kwd{key} function.
  2193. % It is an error to supply both \kwd{test} and
  2194. % \kwd{test-not}
  2195. % in the same function call.
  2196. %
  2197. % If \kwd{key} is supplied, it is used to
  2198. % extract the part to be tested from the \param{list} element.
  2199. % The argument to the \kwd{key} function
  2200. % is an element of \param{list}; typically, the \kwd{key} function
  2201. % returns part of the element of
  2202. % \param{list} it was given.
  2203. % If \kwd{key} is not supplied or \nil, the \param{list}
  2204. % element is used.
  2205. If some element \term{satisfies the test},
  2206. the tail of \param{list} beginning
  2207. with this element is returned; otherwise \nil\ is returned.
  2208. \param{list} is searched on the top level only.
  2209. \label Examples::
  2210. \code
  2211. (member 2 '(1 2 3)) \EV (2 3)
  2212. (member 2 '((1 . 2) (3 . 4)) :test-not #'= :key #'cdr) \EV ((3 . 4))
  2213. (member 'e '(a b c d)) \EV NIL
  2214. \endcode
  2215. %!!! I'm suspicious of this dotted list.
  2216. \code
  2217. (member-if #'listp '(a b nil c d)) \EV (NIL C D)
  2218. (member-if #'numberp '(a #\\Space 5/3 foo)) \EV (5/3 FOO)
  2219. (member-if-not #'zerop
  2220. '(3 6 9 11 . 12)
  2221. :key #'(lambda (x) (mod x 3))) \EV (11 . 12)
  2222. \endcode
  2223. \label Side Effects:\None.
  2224. \label Affected By:\None.
  2225. \label Exceptional Situations::
  2226. \Lazychecktype{list}{a \term{proper list}}
  2227. \label See Also::
  2228. \funref{find},
  2229. \funref{position},
  2230. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2231. {\secref\TraversalRules}
  2232. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2233. \label Notes::
  2234. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2235. The \kwd{test-not} parameter is deprecated.
  2236. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2237. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2238. \Thefunction{member-if-not} is deprecated.
  2239. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2240. In the following
  2241. \code
  2242. (member 'a '(g (a y) c a d e a f)) \EV (A D E A F)
  2243. \endcode
  2244. the value returned by \funref{member} is \term{identical} to the portion
  2245. of the \term{list} beginning with \f{a}. Thus \funref{rplaca} on the
  2246. result of \funref{member} can be used to alter the part of the \term{list}
  2247. where \f{a} was found (assuming a check has been made that \funref{member}
  2248. did not return \nil).
  2249. \endcom
  2250. %-------------------- List Mapping --------------------
  2251. %%% ========== MAPCAR
  2252. %%% ========== MAPLIST
  2253. %%% ========== MAPC
  2254. %%% ========== MAPL
  2255. %%% ========== MAPCAN
  2256. %%% ========== MAPCON
  2257. \begincom{mapc, mapcar, mapcan, mapl, maplist, mapcon}\ftype{Function}
  2258. \label Syntax::
  2259. \DefunWithValues mapc {function {\rest} \plus{lists}} {list-1}
  2260. \DefunWithValues mapcar {function {\rest} \plus{lists}} {result-list}
  2261. \DefunWithValues mapcan {function {\rest} \plus{lists}} {concatenated-results}
  2262. \DefunWithValues mapl {function {\rest} \plus{lists}} {list-1}
  2263. \DefunWithValues maplist {function {\rest} \plus{lists}} {result-list}
  2264. \DefunWithValues mapcon {function {\rest} \plus{lists}} {concatenated-results}
  2265. \label Arguments and Values::
  2266. \param{function}---a \term{designator} for a \term{function}
  2267. that must take as many \term{arguments} as there are \param{lists}.
  2268. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2269. \param{list}---a \term{proper list}.
  2270. \param{list-1}---the first \param{list} (which must be a \term{proper list}).
  2271. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  2272. \param{result-list}---a \term{list}.
  2273. \param{concatenated-results}---a \term{list}.
  2274. \label Description::
  2275. The mapping operation involves applying \param{function} to
  2276. successive sets of arguments in which
  2277. one argument is obtained from each \term{sequence}.
  2278. Except for \funref{mapc} and \funref{mapl},
  2279. the result contains the results returned by \param{function}.
  2280. In the cases of \funref{mapc} and \funref{mapl},
  2281. the resulting \term{sequence} is \param{list}.
  2282. %% 14.2.0 6
  2283. \param{function} is called
  2284. first on all the elements with index \f{0}, then on all those
  2285. with index \f{1}, and so on.
  2286. \param{result-type} specifies the \term{type} of
  2287. the
  2288. resulting \term{sequence}.
  2289. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  2290. If \param{function} is a \term{symbol}, it is \funref{coerce}d
  2291. to a \term{function} as if by \funref{symbol-function}.
  2292. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  2293. %% 7.8.4 4
  2294. \funref{mapcar} operates on successive \term{elements} of the \param{lists}.
  2295. \param{function} is applied to the first \term{element} of each \param{list},
  2296. then to the second \term{element} of each \param{list}, and so on.
  2297. The iteration terminates when the shortest \param{list} runs out,
  2298. and excess elements in other lists are ignored.
  2299. The value returned by \funref{mapcar} is a \term{list}
  2300. of the results of successive calls to \param{function}.
  2301. %% 7.8.4 6
  2302. \funref{mapc} is like \funref{mapcar} except that the results of
  2303. applying \param{function} are not accumulated.
  2304. The \param{list} argument is returned.
  2305. %% 7.8.4 5
  2306. \funref{maplist} is like \funref{mapcar} except that
  2307. \param{function} is applied to successive sublists of the \param{lists}.
  2308. \param{function}
  2309. is first applied to the \param{lists} themselves,
  2310. and then to the \term{cdr} of each
  2311. \param{list}, and then to the \term{cdr} of the \term{cdr}
  2312. of each \param{list}, and so on.
  2313. \funref{mapl} is like \funref{maplist} except that the results of
  2314. applying \param{function} are not accumulated;
  2315. \param{list-1} is returned.
  2316. %% 7.8.4 8
  2317. \funref{mapcan} and \funref{mapcon} are like \funref{mapcar} and
  2318. \funref{maplist} respectively, except that the results of
  2319. applying \param{function} are combined
  2320. into a \term{list} by the use of \funref{nconc}
  2321. rather than \funref{list}.
  2322. That is,
  2323. \code
  2324. (mapcon f x1 ... xn)
  2325. \EQ (apply #'nconc (maplist f x1 ... xn))
  2326. \endcode
  2327. and similarly for the relationship between \funref{mapcan}
  2328. and \funref{mapcar}.
  2329. \label Examples::
  2330. \code
  2331. (mapcar #'car '((1 a) (2 b) (3 c))) \EV (1 2 3)
  2332. (mapcar #'abs '(3 -4 2 -5 -6)) \EV (3 4 2 5 6)
  2333. (mapcar #'cons '(a b c) '(1 2 3)) \EV ((A . 1) (B . 2) (C . 3))
  2334. (maplist #'append '(1 2 3 4) '(1 2) '(1 2 3))
  2335. \EV ((1 2 3 4 1 2 1 2 3) (2 3 4 2 2 3))
  2336. (maplist #'(lambda (x) (cons 'foo x)) '(a b c d))
  2337. \EV ((FOO A B C D) (FOO B C D) (FOO C D) (FOO D))
  2338. (maplist #'(lambda (x) (if (member (car x) (cdr x)) 0 1)) '(a b a c d b c))
  2339. \EV (0 0 1 0 1 1 1)
  2340. ;An entry is 1 if the corresponding element of the input
  2341. ; list was the last instance of that element in the input list.
  2342. (setq dummy nil) \EV NIL
  2343. (mapc #'(lambda (&rest x) (setq dummy (append dummy x)))
  2344. '(1 2 3 4)
  2345. '(a b c d e)
  2346. '(x y z)) \EV (1 2 3 4)
  2347. dummy \EV (1 A X 2 B Y 3 C Z)
  2348. (setq dummy nil) \EV NIL
  2349. (mapl #'(lambda (x) (push x dummy)) '(1 2 3 4)) \EV (1 2 3 4)
  2350. dummy \EV ((4) (3 4) (2 3 4) (1 2 3 4))
  2351. (mapcan #'(lambda (x y) (if (null x) nil (list x y)))
  2352. '(nil nil nil d e)
  2353. '(1 2 3 4 5 6)) \EV (D 4 E 5)
  2354. (mapcan #'(lambda (x) (and (numberp x) (list x)))
  2355. '(a 1 b c 3 4 d 5))
  2356. \EV (1 3 4 5)
  2357. \endcode
  2358. In this case the function serves as a filter;
  2359. this is a standard \Lisp\ idiom using \funref{mapcan}.
  2360. \code
  2361. (mapcon #'list '(1 2 3 4)) \EV ((1 2 3 4) (2 3 4) (3 4) (4))
  2362. \endcode
  2363. \label Affected By:\None.
  2364. \label Exceptional Situations::
  2365. \Lazycheckanytype{list}{a \term{proper list}}
  2366. \label See Also::
  2367. \macref{dolist},
  2368. \funref{map},
  2369. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2370. {\secref\TraversalRules}
  2371. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2372. \label Notes:\None.
  2373. \endcom
  2374. %-------------------- Alists --------------------
  2375. %%% ========== ACONS
  2376. \begincom{acons}\ftype{Function}
  2377. \label Syntax::
  2378. \DefunWithValues acons {key datum alist} {new-alist}
  2379. \label Arguments and Values::
  2380. \param{key}---an \term{object}.
  2381. \param{datum}---an \term{object}.
  2382. \param{alist}---an \term{association list}.
  2383. \param{new-alist}---an \term{association list}.
  2384. \label Description::
  2385. %% 15.6.0 5
  2386. Creates a \term{fresh} \term{cons},
  2387. the \term{cdr} of which is \param{alist} and
  2388. the \term{car} of which is another \term{fresh} \term{cons},
  2389. the \term{car} of which is \param{key} and
  2390. the \term{cdr} of which is \param{datum}.
  2391. \label Examples::
  2392. \code
  2393. (setq alist '()) \EV NIL
  2394. (acons 1 "one" alist) \EV ((1 . "one"))
  2395. alist \EV NIL
  2396. (setq alist (acons 1 "one" (acons 2 "two" alist))) \EV ((1 . "one") (2 . "two"))
  2397. (assoc 1 alist) \EV (1 . "one")
  2398. (setq alist (acons 1 "uno" alist)) \EV ((1 . "uno") (1 . "one") (2 . "two"))
  2399. (assoc 1 alist) \EV (1 . "uno")
  2400. \endcode
  2401. \label Side Effects:\None.
  2402. \label Affected By:\None.
  2403. \label Exceptional Situations:\None.
  2404. \label See Also::
  2405. \funref{assoc}, \funref{pairlis}
  2406. \label Notes::
  2407. \code
  2408. (acons \param{key} \param{datum} \param{alist}) \EQ (cons (cons \param{key} \param{datum}) \param{alist})
  2409. \endcode
  2410. \endcom
  2411. %%% ========== ASSOC
  2412. %%% ========== ASSOC-IF
  2413. %%% ========== ASSOC-IF-NOT
  2414. \begincom{assoc, assoc-if, assoc-if-not}\ftype{Function}
  2415. \label Syntax::
  2416. \DefunWithValues assoc {item alist {\key} key test test-not} {entry}
  2417. \issue{ASSOC-RASSOC-IF-KEY:YES}
  2418. \DefunWithValues assoc-if {predicate alist {\key} key} {entry}
  2419. \DefunWithValues assoc-if-not {predicate alist {\key} key} {entry}
  2420. \endissue{ASSOC-RASSOC-IF-KEY:YES}
  2421. \label Arguments and Values::
  2422. \param{item}---an \term{object}.
  2423. \param{alist}---an \term{association list}.
  2424. \param{predicate}---a \term{designator} for
  2425. a \term{function} of one \term{argument}
  2426. that returns a \term{generalized boolean}.
  2427. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  2428. that returns a \term{generalized boolean}.
  2429. \param{test-not}---a \term{designator} for
  2430. a \term{function} of two \term{arguments}
  2431. that returns a \term{generalized boolean}.
  2432. \param{key}---a \term{designator} for a \term{function} of one argument,
  2433. or \nil.
  2434. \param{entry}---a \term{cons} that is an \term{element} of \param{alist},
  2435. or \nil.
  2436. \label Description::
  2437. \issue{ASSOC-RASSOC-IF-KEY}
  2438. %% Replaced per X3J13. -kmp 05-Oct-93
  2439. % %% 15.6.0 8
  2440. % \funref{assoc} returns the first \term{cons} in \param{alist} whose
  2441. % \term{car} \term{satisfies the test}, or \nil\ if no such \term{cons} is found.
  2442. %
  2443. % The arguments to \param{test} and \param{test-not} and are the key of the
  2444. % \param{item} and the key of the \term{car} of an element of \param{alist},
  2445. % in that order.
  2446. %
  2447. % \funref{assoc-if} and \funref{assoc-if-not} return the first \term{cons}
  2448. % in \param{alist} whose \term{car} \term{satisfies the predicate}, or \nil\ if
  2449. % no such \term{cons} is found.
  2450. %
  2451. % The argument to \param{predicate} is the key of an element of \param{alist}.
  2452. \funref{assoc}, \funref{assoc-if}, and \funref{assoc-if-not}
  2453. return the first \term{cons} in \param{alist} whose \term{car} \term{satisfies the test},
  2454. or \nil\ if no such \term{cons} is found.
  2455. \endissue{ASSOC-RASSOC-IF-KEY}
  2456. For \funref{assoc}, \funref{assoc-if}, and \funref{assoc-if-not}, if \nil\ appears
  2457. in \param{alist} in place of a pair, it is ignored.
  2458. \label Examples::
  2459. %% 15.6.0 9
  2460. \issue{ASSOC-RASSOC-IF-KEY}
  2461. \code
  2462. (setq values '((x . 100) (y . 200) (z . 50))) \EV ((X . 100) (Y . 200) (Z . 50))
  2463. (assoc 'y values) \EV (Y . 200)
  2464. (rplacd (assoc 'y values) 201) \EV (Y . 201)
  2465. (assoc 'y values) \EV (Y . 201)
  2466. (setq alist '((1 . "one")(2 . "two")(3 . "three")))
  2467. \EV ((1 . "one") (2 . "two") (3 . "three"))
  2468. (assoc 2 alist) \EV (2 . "two")
  2469. (assoc-if #'evenp alist) \EV (2 . "two")
  2470. (assoc-if-not #'(lambda(x) (< x 3)) alist) \EV (3 . "three")
  2471. (setq alist '(("one" . 1)("two" . 2))) \EV (("one" . 1) ("two" . 2))
  2472. (assoc "one" alist) \EV NIL
  2473. (assoc "one" alist :test #'equalp) \EV ("one" . 1)
  2474. (assoc "two" alist :key #'(lambda(x) (char x 2))) \EV NIL
  2475. (assoc #\\o alist :key #'(lambda(x) (char x 2))) \EV ("two" . 2)
  2476. (assoc 'r '((a . b) (c . d) (r . x) (s . y) (r . z))) \EV (R . X)
  2477. (assoc 'goo '((foo . bar) (zoo . goo))) \EV NIL
  2478. (assoc '2 '((1 a b c) (2 b c d) (-7 x y z))) \EV (2 B C D)
  2479. (setq alist '(("one" . 1) ("2" . 2) ("three" . 3)))
  2480. \EV (("one" . 1) ("2" . 2) ("three" . 3))
  2481. (assoc-if-not #'alpha-char-p alist
  2482. :key #'(lambda (x) (char x 0))) \EV ("2" . 2)
  2483. \endcode
  2484. \endissue{ASSOC-RASSOC-IF-KEY}
  2485. \label Affected By:\None.
  2486. \label Exceptional Situations::
  2487. \Lazychecktype{alist}{an \term{association list}}
  2488. \label See Also::
  2489. \funref{rassoc},
  2490. \funref{find},
  2491. \funref{member},
  2492. \funref{position},
  2493. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2494. {\secref\TraversalRules}
  2495. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2496. \label Notes::
  2497. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2498. The \kwd{test-not} parameter is deprecated.
  2499. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2500. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2501. \Thefunction{assoc-if-not} is deprecated.
  2502. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2503. It is possible to \funref{rplacd} the result of \funref{assoc}, provided
  2504. that it is not \nil,
  2505. in order to ``update'' \param{alist}.
  2506. %% 15.6.0 10
  2507. The two expressions
  2508. \code
  2509. (assoc item list :test fn)
  2510. \endcode
  2511. and
  2512. \code
  2513. (find item list :test fn :key #'car)
  2514. \endcode
  2515. are equivalent in meaning with one exception:
  2516. if \nil\ appears in \param{alist} in place of a pair,
  2517. and \param{item} is \nil,
  2518. \funref{find} will compute the \term{car} of the \nil\ in \param{alist},
  2519. find that it is equal to \param{item}, and return \nil,
  2520. whereas \funref{assoc} will ignore the \nil\ in \param{alist} and continue
  2521. to search for an actual \term{cons} whose \term{car} is \nil.
  2522. \endcom
  2523. %%% ========== COPY-ALIST
  2524. \begincom{copy-alist}\ftype{Function}
  2525. \label Syntax::
  2526. \DefunWithValues copy-alist {alist} {new-alist}
  2527. \label Arguments and Values::
  2528. \param{alist}---an \term{association list}.
  2529. \param{new-alist}---an \term{association list}.
  2530. \label Description::
  2531. %% 15.2.0 24
  2532. \funref{copy-alist} returns a \term{copy} of \param{alist}.
  2533. The \term{list structure} of \param{alist} is copied,
  2534. and the \term{elements} of \param{alist} which are \term{conses} are
  2535. also copied (as \term{conses} only).
  2536. Any other \term{objects} which are referred to,
  2537. whether directly or indirectly,
  2538. by the \param{alist} continue to be shared.
  2539. \label Examples::
  2540. \code
  2541. (defparameter *alist* (acons 1 "one" (acons 2 "two" '())))
  2542. *alist* \EV ((1 . "one") (2 . "two"))
  2543. (defparameter *list-copy* (copy-list *alist*))
  2544. *list-copy* \EV ((1 . "one") (2 . "two"))
  2545. (defparameter *alist-copy* (copy-alist *alist*))
  2546. *alist-copy* \EV ((1 . "one") (2 . "two"))
  2547. (setf (cdr (assoc 2 *alist-copy*)) "deux") \EV "deux"
  2548. *alist-copy* \EV ((1 . "one") (2 . "deux"))
  2549. *alist* \EV ((1 . "one") (2 . "two"))
  2550. (setf (cdr (assoc 1 *list-copy*)) "uno") \EV "uno"
  2551. *list-copy* \EV ((1 . "uno") (2 . "two"))
  2552. *alist* \EV ((1 . "uno") (2 . "two"))
  2553. \endcode
  2554. \label Side Effects:\None.
  2555. \label Affected By:\None.
  2556. \label Exceptional Situations:\None.
  2557. \label See Also::
  2558. \funref{copy-list}
  2559. \label Notes:\None.
  2560. \endcom
  2561. %%% ========== PAIRLIS
  2562. \begincom{pairlis}\ftype{Function}
  2563. \label Syntax::
  2564. \DefunWithValues pairlis {keys data {\opt} alist} {new-alist}
  2565. \label Arguments and Values::
  2566. \param{keys}---a \term{proper list}.
  2567. \param{data}---a \term{proper list}.
  2568. \param{alist}---an \term{association list}.
  2569. \Default{the \term{empty list}}
  2570. \param{new-alist}---an \term{association list}.
  2571. \label Description::
  2572. %% 15.6.0 6
  2573. Returns an \term{association list} that associates
  2574. elements of \param{keys} to corresponding elements of \param{data}.
  2575. The consequences are undefined if \param{keys} and \param{data} are
  2576. not of the same \term{length}.
  2577. If \param{alist} is supplied, \funref{pairlis} returns
  2578. a modified \param{alist} with the
  2579. new pairs prepended to it.
  2580. %% 15.6.0 7
  2581. The new pairs may appear in the resulting \term{association list} in
  2582. either forward or backward order.
  2583. The result of
  2584. \code
  2585. (pairlis '(one two) '(1 2) '((three . 3) (four . 19)))
  2586. \endcode
  2587. might be
  2588. \code
  2589. ((one . 1) (two . 2) (three . 3) (four . 19))
  2590. \endcode
  2591. or
  2592. \code
  2593. ((two . 2) (one . 1) (three . 3) (four . 19))
  2594. \endcode
  2595. \label Examples::
  2596. \code
  2597. (setq keys '(1 2 3)
  2598. data '("one" "two" "three")
  2599. alist '((4 . "four"))) \EV ((4 . "four"))
  2600. (pairlis keys data) \EV ((3 . "three") (2 . "two") (1 . "one"))
  2601. (pairlis keys data alist)
  2602. \EV ((3 . "three") (2 . "two") (1 . "one") (4 . "four"))
  2603. alist \EV ((4 . "four"))
  2604. \endcode
  2605. \label Side Effects:\None.
  2606. \label Affected By:\None.
  2607. \label Exceptional Situations::
  2608. \Lazychecktypes{\param{keys} and \param{data}}{\term{proper lists}}
  2609. \label See Also::
  2610. \funref{acons}
  2611. \label Notes:\None.
  2612. \endcom
  2613. %%% ========== RASSOC
  2614. %%% ========== RASSOC-IF
  2615. %%% ========== RASSOC-IF-NOT
  2616. \begincom{rassoc, rassoc-if, rassoc-if-not}\ftype{Function}
  2617. \label Syntax::
  2618. \DefunWithValues rassoc {item alist {\key} key test test-not} {entry}
  2619. \issue{ASSOC-RASSOC-IF-KEY:YES}
  2620. \DefunWithValues rassoc-if {predicate alist {\key} key} {entry}
  2621. \DefunWithValues rassoc-if-not {predicate alist {\key} key} {entry}
  2622. \endissue{ASSOC-RASSOC-IF-KEY:YES}
  2623. \label Arguments and Values::
  2624. \param{item}---an \term{object}.
  2625. \param{alist}---an \term{association list}.
  2626. \param{predicate}---a \term{designator} for
  2627. a \term{function} of one \term{argument}
  2628. that returns a \term{generalized boolean}.
  2629. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  2630. that returns a \term{generalized boolean}.
  2631. \param{test-not}---a \term{designator} for
  2632. a \term{function} of two \term{arguments}
  2633. that returns a \term{generalized boolean}.
  2634. \param{key}---a \term{designator} for a \term{function} of one argument,
  2635. or \nil.
  2636. \param{entry}---a \term{cons} that is an \term{element} of the \param{alist},
  2637. or \nil.
  2638. \label Description::
  2639. %% 15.6.0 13
  2640. \funref{rassoc}, \funref{rassoc-if}, and \funref{rassoc-if-not}
  2641. return the first \term{cons} whose \term{cdr}
  2642. \term{satisfies the test}.
  2643. If no such \term{cons} is found, \nil\
  2644. is returned.
  2645. \issue{ASSOC-RASSOC-IF-KEY}
  2646. %% Removed per X3J13. -kmp 05-Oct-93
  2647. % The argument to \param{predicate} is an element of \param{alist}
  2648. % as returned by the \kwd{key} function (if supplied).
  2649. % The arguments to \kwd{test} and \kwd{test-not}
  2650. % are \param{item} and an element of \param{alist}
  2651. % as returned by the \kwd{key} function (if supplied), in that
  2652. % order.
  2653. %
  2654. % If \kwd{key} is supplied, it is applied to the \term{cdr}
  2655. % of the \param{alist} entries and the result is passed to the
  2656. % \param{predicate}, \kwd{test}, or \kwd{test-not} function.
  2657. % The \term{cdr} of the \param{alist} entry contains the
  2658. % key of the association, and if \kwd{key} is
  2659. % not supplied or \nil, the \term{cdr} is the key of the association.
  2660. \endissue{ASSOC-RASSOC-IF-KEY}
  2661. If \nil\ appears in \param{alist} in place of a pair, it is ignored.
  2662. \label Examples::
  2663. \code
  2664. (setq alist '((1 . "one") (2 . "two") (3 . 3)))
  2665. \EV ((1 . "one") (2 . "two") (3 . 3))
  2666. (rassoc 3 alist) \EV (3 . 3)
  2667. (rassoc "two" alist) \EV NIL
  2668. (rassoc "two" alist :test 'equal) \EV (2 . "two")
  2669. (rassoc 1 alist :key #'(lambda (x) (if (numberp x) (/ x 3)))) \EV (3 . 3)
  2670. (rassoc 'a '((a . b) (b . c) (c . a) (z . a))) \EV (C . A)
  2671. (rassoc-if #'stringp alist) \EV (1 . "one")
  2672. (rassoc-if-not #'vectorp alist) \EV (3 . 3)
  2673. \endcode
  2674. \label Side Effects:\None.
  2675. \label Affected By:\None.
  2676. \label Exceptional Situations:\None.
  2677. \label See Also::
  2678. \funref{assoc},
  2679. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2680. {\secref\TraversalRules}
  2681. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  2682. \label Notes::
  2683. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2684. The \kwd{test-not} parameter is deprecated.
  2685. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2686. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2687. \Thefunction{rassoc-if-not} is deprecated.
  2688. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  2689. It is possible to \funref{rplaca} the result of \funref{rassoc},
  2690. provided that it is not \nil, in order to ``update'' \param{alist}.
  2691. %% 15.6.0 13
  2692. The expressions
  2693. \code
  2694. (rassoc item list :test fn)
  2695. \endcode
  2696. and
  2697. \code
  2698. (find item list :test fn :key #'cdr)
  2699. \endcode
  2700. are equivalent in meaning, except when the \f{item} is \nil\
  2701. and \nil\ appears in place of a pair in the \param{alist}.
  2702. \Seefun{assoc}.
  2703. \endcom
  2704. %-------------------- Plists --------------------
  2705. %%% ========== GET-PROPERTIES
  2706. \begincom{get-properties}\ftype{Function}
  2707. \label Syntax::
  2708. \DefunWithValues get-properties {plist indicator-list} {indicator, value, tail}
  2709. \label Arguments and Values::
  2710. \issue{PLIST-DUPLICATES:ALLOW}
  2711. \param{plist}---a \term{property list}.
  2712. \endissue{PLIST-DUPLICATES:ALLOW}
  2713. \param{indicator-list}---a \term{proper list} (of \term{indicators}).
  2714. \param{indicator}---an \term{object} that is an \term{element} of \param{indicator-list}.
  2715. \param{value}---an \term{object}.
  2716. \param{tail}---a \term{list}.
  2717. \label Description::
  2718. %% 10.1.0 19
  2719. \funref{get-properties} is used to look up any of several
  2720. \term{property list} entries all at once.
  2721. %% 10.1.0 23
  2722. It searches the \param{plist} for the first entry whose \term{indicator}
  2723. is \term{identical} to one of the \term{objects} in \param{indicator-list}.
  2724. If such an entry is found, the \param{indicator} and \param{value} returned
  2725. are the \term{property indicator} and its associated \term{property value},
  2726. and the \param{tail} returned is the \term{tail} of the \param{plist}
  2727. that begins with the found entry (\ie whose \term{car} is the \param{indicator}).
  2728. If no such entry is found, the \param{indicator}, \param{value}, and \param{tail}
  2729. are all \nil.
  2730. \label Examples::
  2731. \code
  2732. (setq x '()) \EV NIL
  2733. (setq *indicator-list* '(prop1 prop2)) \EV (PROP1 PROP2)
  2734. (getf x 'prop1) \EV NIL
  2735. (setf (getf x 'prop1) 'val1) \EV VAL1
  2736. (eq (getf x 'prop1) 'val1) \EV \term{true}
  2737. (get-properties x *indicator-list*) \EV PROP1, VAL1, (PROP1 VAL1)
  2738. x \EV (PROP1 VAL1)
  2739. \endcode
  2740. \label Side Effects:\None.
  2741. \label Affected By:\None.
  2742. \label Exceptional Situations:\None.
  2743. \label See Also::
  2744. \funref{get}, \funref{getf}
  2745. \label Notes:\None.
  2746. \endcom
  2747. %%% ========== GETF
  2748. \begincom{getf}\ftype{Accessor}
  2749. \label Syntax::
  2750. \DefunWithValues getf {plist indicator {\opt} default} {value}
  2751. \Defsetf getf {place indicator {\opt} default} {new-value}
  2752. \label Arguments and Values::
  2753. \param{plist}---a \term{property list}.
  2754. \param{place}---a \term{place}, the \term{value} of which is a \term{property list}.
  2755. \param{indicator}---an \term{object}.
  2756. \param{default}---an \term{object}.
  2757. \Default{\nil}
  2758. %% 10.1.0 24
  2759. \param{value}---an \term{object}.
  2760. \param{new-value}---an \term{object}.
  2761. \label Description::
  2762. %% 10.1.0 19
  2763. % \funref{getf} is used to \term{access} entries in a \term{property list}.
  2764. % \funref{getf} searches \param{plist} for an indicator
  2765. % \term{identical} to \param{indicator} and returns the associated value.
  2766. \funref{getf} finds a \term{property} on the \param{plist}
  2767. whose \term{property indicator} is \term{identical} to \param{indicator},
  2768. and returns its corresponding \term{property value}.
  2769. \issue{PLIST-DUPLICATES:ALLOW}
  2770. If there are multiple \term{properties}\meaning{1} with that \term{property indicator},
  2771. \funref{getf} uses the first such \term{property}.
  2772. \endissue{PLIST-DUPLICATES:ALLOW}
  2773. % If \param{indicator} is not found, then \param{default} is returned.
  2774. If there is no \term{property} with that \term{property indicator},
  2775. \param{default} is returned.
  2776. % %% 10.1.0 20
  2777. % For \macref{setf} of \funref{getf}, the effect is
  2778. % to add a new property-value pair,
  2779. % or to update an existing pair,
  2780. % in the \term{property list} that is the \term{value} of \param{place}.
  2781. \macref{setf} of \funref{getf} may be used to associate a new \term{object}
  2782. with an existing indicator in the \term{property list} held by \param{place},
  2783. or to create a new assocation if none exists.
  2784. \issue{PLIST-DUPLICATES:ALLOW}
  2785. If there are multiple \term{properties}\meaning{1} with that \term{property indicator},
  2786. \macref{setf} of \funref{getf} associates the \param{new-value}
  2787. with the first such \term{property}.
  2788. \endissue{PLIST-DUPLICATES:ALLOW}
  2789. \issue{SETF-GET-DEFAULT:EVALUATED-BUT-IGNORED}
  2790. When a \funref{getf} \term{form} is used as a \macref{setf} \param{place},
  2791. any \param{default} which is supplied is evaluated according to normal
  2792. left-to-right evaluation rules, but its \term{value} is ignored.
  2793. \endissue{SETF-GET-DEFAULT:EVALUATED-BUT-IGNORED}
  2794. %% 10.1.0 20
  2795. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2796. \macref{setf} of \funref{getf} is permitted to either
  2797. \term{write} the \term{value} of \param{place} itself,
  2798. or modify of any part, \term{car} or \term{cdr},
  2799. of the \term{list structure} held by \param{place}.
  2800. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}%
  2801. \label Examples::
  2802. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2803. \code
  2804. (setq x '()) \EV NIL
  2805. (getf x 'prop1) \EV NIL
  2806. (getf x 'prop1 7) \EV 7
  2807. (getf x 'prop1) \EV NIL
  2808. (setf (getf x 'prop1) 'val1) \EV VAL1
  2809. (eq (getf x 'prop1) 'val1) \EV \term{true}
  2810. (getf x 'prop1) \EV VAL1
  2811. (getf x 'prop1 7) \EV VAL1
  2812. x \EV (PROP1 VAL1)
  2813. ;; Examples of implementation variation permitted.
  2814. (setq foo (list 'a 'b 'c 'd 'e 'f)) \EV (A B C D E F)
  2815. (setq bar (cddr foo)) \EV (C D E F)
  2816. (remf foo 'c) \EV \term{true}
  2817. foo \EV (A B E F)
  2818. bar
  2819. \EV (C D E F)
  2820. \OV (C)
  2821. \OV (NIL)
  2822. \OV (C NIL)
  2823. \OV (C D)
  2824. \endcode
  2825. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2826. \label Side Effects:\None.
  2827. \label Affected By:\None.
  2828. \label Exceptional Situations:\None.
  2829. \label See Also::
  2830. \funref{get},
  2831. \funref{get-properties},
  2832. \macref{setf},
  2833. {\secref\FnFormsAsGenRefs}
  2834. \label Notes::
  2835. There is no way (using \funref{getf}) to distinguish an absent property
  2836. from one whose value is \param{default}; but see \funref{get-properties}.
  2837. Note that while supplying a \term{default} argument to \macref{getf}
  2838. in a \macref{setf} situation is sometimes not very interesting,
  2839. it is still important because some macros, such as \macref{push} and
  2840. \macref{incf}, require a \param{place} argument which data is both \term{read}
  2841. from and \term{written} to. In such a context, if a \term{default}
  2842. argument is to be supplied for the \term{read} situation, it must be
  2843. syntactically valid for the \term{write} situation as well. For example,
  2844. \code
  2845. (let ((plist '()))
  2846. (incf (getf plist 'count 0))
  2847. plist) \EV (COUNT 1)
  2848. \endcode
  2849. \endcom
  2850. %%% ========== REMF
  2851. \begincom{remf}\ftype{Macro}
  2852. \label Syntax::
  2853. \DefmacWithValues remf {place indicator} {generalized-boolean}
  2854. \label Arguments and Values::
  2855. \param{place}---a \term{place}.
  2856. \param{indicator}---an \term{object}.
  2857. \param{generalized-boolean}---a \term{generalized boolean}.
  2858. \label Description::
  2859. %% 10.1.0 22
  2860. \macref{remf} removes from the \term{property list} stored in \param{place}
  2861. a \term{property}\meaning{1} with a \term{property indicator}
  2862. % EQ => identical -kmp 14-Jul-93
  2863. \term{identical} to \param{indicator}.
  2864. \issue{PLIST-DUPLICATES:ALLOW}
  2865. If there are multiple \term{properties}\meaning{1} with the \term{identical} key,
  2866. \macref{remf} only removes the first such \term{property}.
  2867. \endissue{PLIST-DUPLICATES:ALLOW}
  2868. \macref{remf} returns \term{false} if no such \term{property} was found,
  2869. or \term{true} if a property was found.
  2870. The \term{property indicator}
  2871. and the corresponding \term{property value}
  2872. are removed in an undefined order
  2873. by destructively splicing the property list.
  2874. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2875. \macref{remf} is permitted to either \macref{setf} \param{place} or to
  2876. \macref{setf} any part, \funref{car} or \funref{cdr},
  2877. of the \term{list structure} held by that \param{place}.
  2878. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2879. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  2880. For information about the \term{evaluation} of \term{subforms} of \param{place},
  2881. \seesection\GenRefSubFormEval.
  2882. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  2883. \label Examples::
  2884. \code
  2885. (setq x (cons () ())) \EV (NIL)
  2886. (setf (getf (car x) 'prop1) 'val1) \EV VAL1
  2887. (remf (car x) 'prop1) \EV \term{true}
  2888. (remf (car x) 'prop1) \EV \term{false}
  2889. \endcode
  2890. \label Side Effects::
  2891. The property list stored in \param{place} is modified.
  2892. \label Affected By:\None.
  2893. \label Exceptional Situations:\None.
  2894. \label See Also::
  2895. \funref{remprop}, \funref{getf}
  2896. \label Notes:\None.
  2897. \endcom
  2898. %-------------------- Sets --------------------
  2899. %%% ========== INTERSECTION
  2900. %%% ========== NINTERSECTION
  2901. \begincom{intersection, nintersection}\ftype{Function}
  2902. \label Syntax::
  2903. \DefunWithValues intersection {list-1 list-2 {\key} key test test-not} {result-list}
  2904. \DefunWithValues nintersection {list-1 list-2 {\key} key test test-not} {result-list}
  2905. \label Arguments and Values::
  2906. \param{list-1}---a \term{proper list}.
  2907. \param{list-2}---a \term{proper list}.
  2908. %% 15.5.0 15
  2909. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  2910. that returns a \term{generalized boolean}.
  2911. \param{test-not}---a \term{designator} for
  2912. a \term{function} of two \term{arguments}
  2913. that returns a \term{generalized boolean}.
  2914. \param{key}---a \term{designator} for a \term{function} of one argument,
  2915. or \nil.
  2916. \param{result-list}---a \term{list}.
  2917. \label Description::
  2918. %% 15.5.0 14
  2919. \funref{intersection} and \funref{nintersection} return a \term{list}
  2920. that contains every element that occurs in both \param{list-1} and \param{list-2}.
  2921. %% 15.5.0 16
  2922. \funref{nintersection} is the destructive version of \funref{intersection}.
  2923. It performs the same operation,
  2924. but may destroy \param{list-1} using its cells to construct the result.
  2925. \issue{NINTERSECTION-DESTRUCTION:REVERT}
  2926. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2927. %% This has gone back and forth, but my opinion is that the current state of this
  2928. %% is that the second arg is again protected. -kmp 7-Feb-92
  2929. %%
  2930. %% This opinion finally validated by clarifying vote in letter ballot (X3J13/93-302).
  2931. %% Option REVERT affirms the status quo from both CLtL1 and draft 12.24,
  2932. %% overriding the possible effect of REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89.
  2933. %
  2934. % %%Barmar noted that this next sentence was in conflict with the changes
  2935. % %%made by REMF-DESTRUCTION-UNSPECIFIED, so I've removed it for now. Mail sent
  2936. % %%to find out if X3J13 really intended for NINTERSECTION's contract to be changed,
  2937. % %%or if making this untrue this was a `typo':
  2938. % %\param{list-2} is not destroyed.
  2939. %
  2940. % \funref{nintersection} is permitted to modify any part of the \term{list structure}
  2941. % of \param{list-1} or \param{list-2}.
  2942. %
  2943. \param{list-2} is not destroyed.
  2944. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2945. \endissue{NINTERSECTION-DESTRUCTION:REVERT}
  2946. The intersection operation is described as follows.
  2947. For all possible ordered pairs consisting of
  2948. one \term{element} from \param{list-1}
  2949. and one \term{element} from \param{list-2},
  2950. \kwd{test} or \kwd{test-not} are used
  2951. to determine whether they \term{satisfy the test}.
  2952. The first argument to the \kwd{test} or \kwd{test-not}
  2953. function is an element of \param{list-1}; the second argument is an
  2954. element of \param{list-2}.
  2955. If \kwd{test} or \kwd{test-not} is not supplied, \funref{eql}
  2956. is used.
  2957. It is an error if \kwd{test} and \kwd{test-not} are supplied in
  2958. the same function call.
  2959. If \kwd{key} is supplied (and not \nil), it is used to
  2960. extract the part to be tested from the \param{list} element.
  2961. The argument to the \kwd{key} function
  2962. is an element of either \param{list-1} or \param{list-2};
  2963. the \kwd{key} function typically returns part of the supplied element.
  2964. If \kwd{key} is not supplied or \nil, the \param{list-1} and
  2965. \param{list-2} elements are used.
  2966. For every pair that \term{satifies the test},
  2967. exactly one of the two elements of the pair will be put in the result.
  2968. No element from either \term{list} appears in the result that does not
  2969. \term{satisfy the test} for
  2970. an element from the other \term{list}.
  2971. If one of the \term{lists} contains duplicate
  2972. elements, there may be duplication in the result.
  2973. There is no guarantee that the order of elements in the result will
  2974. reflect the ordering of the arguments in any particular way.
  2975. The result \term{list} may share cells with,
  2976. or be \funref{eq} to, either \param{list-1} or \param{list-2}
  2977. if appropriate.
  2978. \label Examples::
  2979. \code
  2980. (setq list1 (list 1 1 2 3 4 a b c "A" "B" "C" "d")
  2981. list2 (list 1 4 5 b c d "a" "B" "c" "D"))
  2982. \EV (1 4 5 B C D "a" "B" "c" "D")
  2983. (intersection list1 list2) \EV (C B 4 1 1)
  2984. (intersection list1 list2 :test 'equal) \EV ("B" C B 4 1 1)
  2985. (intersection list1 list2 :test #'equalp) \EV ("d" "C" "B" "A" C B 4 1 1)
  2986. (nintersection list1 list2) \EV (1 1 4 B C)
  2987. list1 \EV \term{implementation-dependent} ;\eg (1 1 4 B C)
  2988. list2 \EV \term{implementation-dependent} ;\eg (1 4 5 B C D "a" "B" "c" "D")
  2989. (setq list1 (copy-list '((1 . 2) (2 . 3) (3 . 4) (4 . 5))))
  2990. \EV ((1 . 2) (2 . 3) (3 . 4) (4 . 5))
  2991. (setq list2 (copy-list '((1 . 3) (2 . 4) (3 . 6) (4 . 8))))
  2992. \EV ((1 . 3) (2 . 4) (3 . 6) (4 . 8))
  2993. (nintersection list1 list2 :key #'cdr) \EV ((2 . 3) (3 . 4))
  2994. list1 \EV \term{implementation-dependent} ;\eg ((1 . 2) (2 . 3) (3 . 4))
  2995. list2 \EV \term{implementation-dependent} ;\eg ((1 . 3) (2 . 4) (3 . 6) (4 . 8))
  2996. \endcode
  2997. \label Side Effects::
  2998. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  2999. \funref{nintersection} can modify \param{list-1},
  3000. \issue{NINTERSECTION-DESTRUCTION}
  3001. %or \param{list-2}.
  3002. but not \param{list-2}.
  3003. \endissue{NINTERSECTION-DESTRUCTION}
  3004. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3005. \label Affected By:\None.
  3006. \label Exceptional Situations::
  3007. \Lazychecktypes{\param{list-1} and \param{list-2}}{\term{proper lists}}
  3008. \label See Also::
  3009. \funref{union},
  3010. \issue{CONSTANT-MODIFICATION:DISALLOW}
  3011. {\secref\ConstantModification},
  3012. \endissue{CONSTANT-MODIFICATION:DISALLOW}
  3013. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3014. {\secref\TraversalRules}
  3015. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3016. \label Notes::
  3017. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3018. The \kwd{test-not} parameter is deprecated.
  3019. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3020. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3021. Since the \funref{nintersection} side effect is not required,
  3022. it should not be used in for-effect-only
  3023. positions in portable code.
  3024. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3025. \endcom
  3026. %%% ========== ADJOIN
  3027. \begincom{adjoin}\ftype{Function}
  3028. \label Syntax::
  3029. \DefunWithValues adjoin {item list {\key} key test test-not} {new-list}
  3030. \label Arguments and Values::
  3031. \param{item}---an \term{object}.
  3032. \param{list}---a \term{proper list}.
  3033. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  3034. that returns a \term{generalized boolean}.
  3035. \param{test-not}---a \term{designator} for
  3036. a \term{function} of two \term{arguments}
  3037. that returns a \term{generalized boolean}.
  3038. \param{key}---a \term{designator} for a \term{function} of one argument,
  3039. or \nil.
  3040. %% 15.5.0 8
  3041. \param{new-list}---a \term{list}.
  3042. \label Description::
  3043. Tests whether \param{item} is the same as an existing element of \param{list}.
  3044. If the \param{item} is not an existing element,
  3045. \funref{adjoin} adds it to \param{list} (as if by \funref{cons})
  3046. and returns the resulting \term{list};
  3047. otherwise, nothing is added and the original \param{list} is returned.
  3048. \SatisfyTest{item}{an \term{element} of \param{list}}
  3049. \label Examples::
  3050. \code
  3051. (setq slist '()) \EV NIL
  3052. (adjoin 'a slist) \EV (A)
  3053. slist \EV NIL
  3054. (setq slist (adjoin '(test-item 1) slist)) \EV ((TEST-ITEM 1))
  3055. (adjoin '(test-item 1) slist) \EV ((TEST-ITEM 1) (TEST-ITEM 1))
  3056. (adjoin '(test-item 1) slist :test 'equal) \EV ((TEST-ITEM 1))
  3057. (adjoin '(new-test-item 1) slist :key #'cadr) \EV ((TEST-ITEM 1))
  3058. (adjoin '(new-test-item 1) slist) \EV ((NEW-TEST-ITEM 1) (TEST-ITEM 1))
  3059. \endcode
  3060. \label Affected By:\None.
  3061. \label Exceptional Situations::
  3062. \Lazychecktype{list}{a \term{proper list}}
  3063. \label See Also::
  3064. \macref{pushnew},
  3065. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3066. {\secref\TraversalRules}
  3067. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3068. \label Notes::
  3069. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3070. The \kwd{test-not} parameter is deprecated.
  3071. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3072. \code
  3073. (adjoin item list :key fn)
  3074. \EQ (if (member (fn item) list :key fn) list (cons item list))
  3075. \endcode
  3076. \endcom
  3077. %%% ========== PUSHNEW
  3078. \begincom{pushnew}\ftype{Macro}
  3079. \label Syntax::
  3080. \DefmacWithValuesNewline pushnew {item place {\key} key test test-not} {new-place-value}
  3081. \label Arguments and Values::
  3082. \param{item}---an \term{object}.
  3083. %!!! Need to separate discussion of place from its value. -kmp 1-Sep-91
  3084. \param{place}---a \term{place}, the \term{value} of which is a \term{proper list}.
  3085. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  3086. that returns a \term{generalized boolean}.
  3087. \param{test-not}---a \term{designator} for
  3088. a \term{function} of two \term{arguments}
  3089. that returns a \term{generalized boolean}.
  3090. \param{key}---a \term{designator} for a \term{function} of one argument,
  3091. or \nil.
  3092. \param{new-place-value}---a \term{list} (the new \term{value} of \param{place}).
  3093. \label Description::
  3094. \macref{pushnew} tests whether \param{item} is the same as any existing
  3095. element of the \term{list} stored in \param{place}. If \param{item} is not,
  3096. it is prepended to the \term{list}, and the new \term{list} is stored in
  3097. \param{place}.
  3098. %% 15.2.0 34
  3099. \macref{pushnew} returns the new \term{list} that is stored in \param{place}.
  3100. %% 15.2.0 32
  3101. Whether or not \param{item} is already a member of the \term{list} that is
  3102. in \param{place} is determined by comparisons using \kwd{test} or \kwd{test-not}.
  3103. The first argument to the \kwd{test} or \kwd{test-not}
  3104. function is \param{item}; the second argument is
  3105. an element of the \term{list} in \param{place} as returned by
  3106. the \kwd{key} function (if supplied).
  3107. If \kwd{key} is supplied, it is used to extract the part to be tested from
  3108. both \param{item} and the \term{list} element,
  3109. as for \funref{adjoin}.
  3110. The argument to the \kwd{key} function
  3111. is an element of the \term{list} stored in
  3112. \param{place}. The \kwd{key} function typically returns part
  3113. part of the element of the \term{list}.
  3114. If \kwd{key} is not supplied or \nil, the \term{list}
  3115. element is used.
  3116. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  3117. For information about the \term{evaluation} of \term{subforms} of \param{place},
  3118. \seesection\GenRefSubFormEval.
  3119. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  3120. \issue{PUSHNEW-STORE-REQUIRED:UNSPECIFIED}
  3121. It is \term{implementation-dependent} whether or not \macref{pushnew}
  3122. actually executes the storing form for its \param{place} in the
  3123. situation where the \param{item} is already a member of the \term{list}
  3124. held by \param{place}.
  3125. \endissue{PUSHNEW-STORE-REQUIRED:UNSPECIFIED}
  3126. \label Examples::
  3127. \code
  3128. (setq x '(a (b c) d)) \EV (A (B C) D)
  3129. (pushnew 5 (cadr x)) \EV (5 B C)
  3130. x \EV (A (5 B C) D)
  3131. (pushnew 'b (cadr x)) \EV (5 B C)
  3132. x \EV (A (5 B C) D)
  3133. (setq lst '((1) (1 2) (1 2 3))) \EV ((1) (1 2) (1 2 3))
  3134. (pushnew '(2) lst) \EV ((2) (1) (1 2) (1 2 3))
  3135. (pushnew '(1) lst) \EV ((1) (2) (1) (1 2) (1 2 3))
  3136. (pushnew '(1) lst :test 'equal) \EV ((1) (2) (1) (1 2) (1 2 3))
  3137. (pushnew '(1) lst :key #'car) \EV ((1) (2) (1) (1 2) (1 2 3))
  3138. \endcode
  3139. \label Side Effects::
  3140. The contents of \param{place} may be modified.
  3141. \label Affected By:\None.
  3142. \label Exceptional Situations:\None.
  3143. \label See Also::
  3144. \macref{push},
  3145. \funref{adjoin},
  3146. {\secref\GeneralizedReference}
  3147. \label Notes::
  3148. The effect of
  3149. \code
  3150. (pushnew item place :test p)
  3151. \endcode
  3152. is roughly equivalent to
  3153. \code
  3154. (setf place (adjoin item place :test p))
  3155. \endcode
  3156. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  3157. except that the \term{subforms} of \f{place} are evaluated only once,
  3158. and \f{item} is evaluated before \f{place}.
  3159. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  3160. \endcom
  3161. %%% ========== NSET-DIFFERENCE
  3162. %%% ========== SET-DIFFERENCE
  3163. \begincom{set-difference, nset-difference}\ftype{Function}
  3164. \label Syntax::
  3165. \DefunWithValues set-difference {list-1 list-2 {\key} key test test-not} {result-list}
  3166. \DefunWithValues nset-difference {list-1 list-2 {\key} key test test-not} {result-list}
  3167. \label Arguments and Values::
  3168. \param{list-1}---a \term{proper list}.
  3169. \param{list-2}---a \term{proper list}.
  3170. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  3171. that returns a \term{generalized boolean}.
  3172. \param{test-not}---a \term{designator} for
  3173. a \term{function} of two \term{arguments}
  3174. that returns a \term{generalized boolean}.
  3175. \param{key}---a \term{designator} for a \term{function} of one argument,
  3176. or \nil.
  3177. \param{result-list}---a \term{list}.
  3178. \label Description::
  3179. %% 15.5.0 17
  3180. \funref{set-difference} returns a \term{list}
  3181. of elements of \param{list-1}
  3182. that do not appear in \param{list-2}.
  3183. %% 15.5.0 20
  3184. \funref{nset-difference} is the destructive
  3185. version of \funref{set-difference}.
  3186. It may destroy \param{list-1}.
  3187. %% 15.5.0 19
  3188. For all possible ordered pairs consisting of
  3189. one element from \param{list-1} and one element from \param{list-2}, the
  3190. \kwd{test} or \kwd{test-not} function is
  3191. used to determine whether they \term{satisfy the test}.
  3192. The first argument to the \kwd{test} or \kwd{test-not} function
  3193. is the part of an element of \param{list-1} that is returned by
  3194. the \kwd{key} function (if supplied); the second argument is the part of
  3195. an element of \param{list-2} that is
  3196. returned by the \kwd{key} function (if supplied).
  3197. If \kwd{key} is supplied, its argument is a \param{list-1} or
  3198. \param{list-2} element. The \kwd{key} function
  3199. typically returns part of
  3200. the supplied element.
  3201. If \kwd{key} is not supplied, the \param{list-1} or \param{list-2}
  3202. element is used.
  3203. An element of \param{list-1}
  3204. appears in the result if and only if it does not match any element
  3205. of \param{list-2}.
  3206. %% 15.5.0 18
  3207. There is no guarantee that the order of elements in the result will
  3208. reflect the ordering of the arguments in any particular way.
  3209. The result \term{list}
  3210. may share cells with, or be \funref{eq} to, either of \param{list-1}
  3211. or \param{list-2},
  3212. if appropriate.
  3213. \label Examples::
  3214. \code
  3215. (setq lst1 (list "A" "b" "C" "d")
  3216. lst2 (list "a" "B" "C" "d")) \EV ("a" "B" "C" "d")
  3217. (set-difference lst1 lst2) \EV ("d" "C" "b" "A")
  3218. (set-difference lst1 lst2 :test 'equal) \EV ("b" "A")
  3219. (set-difference lst1 lst2 :test #'equalp) \EV NIL
  3220. (nset-difference lst1 lst2 :test #'string=) \EV ("A" "b")
  3221. (setq lst1 '(("a" . "b") ("c" . "d") ("e" . "f")))
  3222. \EV (("a" . "b") ("c" . "d") ("e" . "f"))
  3223. (setq lst2 '(("c" . "a") ("e" . "b") ("d" . "a")))
  3224. \EV (("c" . "a") ("e" . "b") ("d" . "a"))
  3225. (nset-difference lst1 lst2 :test #'string= :key #'cdr)
  3226. \EV (("c" . "d") ("e" . "f"))
  3227. lst1 \EV (("a" . "b") ("c" . "d") ("e" . "f"))
  3228. lst2 \EV (("c" . "a") ("e" . "b") ("d" . "a"))
  3229. \endcode
  3230. \code
  3231. ;; Remove all flavor names that contain "c" or "w".
  3232. (set-difference '("strawberry" "chocolate" "banana"
  3233. "lemon" "pistachio" "rhubarb")
  3234. '(#\\c #\\w)
  3235. :test #'(lambda (s c) (find c s)))
  3236. \EV ("banana" "rhubarb" "lemon") ;One possible ordering.
  3237. \endcode
  3238. \label Side Effects::
  3239. \funref{nset-difference} may destroy \param{list-1}.
  3240. \label Affected By:\None.
  3241. \label Exceptional Situations::
  3242. \Lazychecktypes{\param{list-1} and \param{list-2}}{\term{proper lists}}
  3243. \label See Also::
  3244. \issue{CONSTANT-MODIFICATION:DISALLOW}
  3245. {\secref\ConstantModification},
  3246. \endissue{CONSTANT-MODIFICATION:DISALLOW}
  3247. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3248. {\secref\TraversalRules}
  3249. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3250. \label Notes::
  3251. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3252. The \kwd{test-not} parameter is deprecated.
  3253. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3254. \endcom
  3255. %%% ========== NSET-EXCLUSIVE-OR
  3256. %%% ========== SET-EXCLUSIVE-OR
  3257. \begincom{set-exclusive-or, nset-exclusive-or}\ftype{Function}
  3258. \label Syntax::
  3259. \DefunWithValues set-exclusive-or {list-1 list-2 {\key} key test test-not} {result-list}
  3260. \DefunWithValues nset-exclusive-or {list-1 list-2 {\key} key test test-not} {result-list}
  3261. \label Arguments and Values::
  3262. \param{list-1}---a \term{proper list}.
  3263. \param{list-2}---a \term{proper list}.
  3264. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  3265. that returns a \term{generalized boolean}.
  3266. \param{test-not}---a \term{designator} for
  3267. a \term{function} of two \term{arguments}
  3268. that returns a \term{generalized boolean}.
  3269. \param{key}---a \term{designator} for a \term{function} of one argument,
  3270. or \nil.
  3271. \param{result-list}---a \term{list}.
  3272. \label Description::
  3273. %% 15.5.0 22
  3274. \funref{set-exclusive-or} returns a \term{list} of elements that appear
  3275. in exactly one of \param{list-1} and \param{list-2}.
  3276. %% 15.5.0 25
  3277. \funref{nset-exclusive-or}
  3278. is the \term{destructive} version of \funref{set-exclusive-or}.
  3279. %% 15.5.0 24
  3280. For all possible ordered pairs consisting of
  3281. one element from \param{list-1} and one element from \param{list-2}, the
  3282. \kwd{test} or \kwd{test-not} function is
  3283. used to determine whether they \term{satisfy the test}.
  3284. If \kwd{key} is supplied, it is used to
  3285. extract the part to be tested from the \param{list-1} or \param{list-2} element.
  3286. The first argument to the \kwd{test} or \kwd{test-not} function
  3287. is the part of an element of \param{list-1} extracted by the \kwd{key}
  3288. function (if supplied); the second argument is the part of an
  3289. element of \param{list-2} extracted by the \kwd{key} function (if supplied).
  3290. If \kwd{key} is not supplied or \nil, the \param{list-1} or
  3291. \param{list-2} element is used.
  3292. The result contains precisely
  3293. those elements of \param{list-1} and \param{list-2}
  3294. that appear in no matching pair.
  3295. The result \term{list} of \funref{set-exclusive-or}
  3296. might share storage with one of \param{list-1} or \param{list-2}.
  3297. \label Examples::
  3298. \code
  3299. (setq lst1 (list 1 "a" "b")
  3300. lst2 (list 1 "A" "b")) \EV (1 "A" "b")
  3301. (set-exclusive-or lst1 lst2) \EV ("b" "A" "b" "a")
  3302. (set-exclusive-or lst1 lst2 :test #'equal) \EV ("A" "a")
  3303. (set-exclusive-or lst1 lst2 :test 'equalp) \EV NIL
  3304. (nset-exclusive-or lst1 lst2) \EV ("a" "b" "A" "b")
  3305. (setq lst1 (list (("a" . "b") ("c" . "d") ("e" . "f"))))
  3306. \EV (("a" . "b") ("c" . "d") ("e" . "f"))
  3307. (setq lst2 (list (("c" . "a") ("e" . "b") ("d" . "a"))))
  3308. \EV (("c" . "a") ("e" . "b") ("d" . "a"))
  3309. (nset-exclusive-or lst1 lst2 :test #'string= :key #'cdr)
  3310. \EV (("c" . "d") ("e" . "f") ("c" . "a") ("d" . "a"))
  3311. lst1 \EV (("a" . "b") ("c" . "d") ("e" . "f"))
  3312. lst2 \EV (("c" . "a") ("d" . "a"))
  3313. \endcode
  3314. \label Side Effects::
  3315. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3316. \funref{nset-exclusive-or} is permitted to modify any part,
  3317. \term{car} or \term{cdr}, of the \term{list structure} of \param{list-1} or \param{list-2}.
  3318. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3319. \label Affected By:\None.
  3320. \label Exceptional Situations::
  3321. \Lazychecktypes{\param{list-1} and \param{list-2}}{\term{proper lists}}
  3322. \label See Also::
  3323. \issue{CONSTANT-MODIFICATION:DISALLOW}
  3324. {\secref\ConstantModification},
  3325. \endissue{CONSTANT-MODIFICATION:DISALLOW}
  3326. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3327. {\secref\TraversalRules}
  3328. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3329. \label Notes::
  3330. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3331. The \kwd{test-not} parameter is deprecated.
  3332. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3333. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3334. Since the \funref{nset-exclusive-or} side effect is not required,
  3335. it should not be used in for-effect-only
  3336. positions in portable code.
  3337. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3338. \endcom
  3339. %%% ========== SUBSETP
  3340. \begincom{subsetp}\ftype{Function}
  3341. \label Syntax::
  3342. \DefunWithValues subsetp {list-1 list-2 {\key} key test test-not} {generalized-boolean}
  3343. \label Arguments and Values::
  3344. \param{list-1}---a \term{proper list}.
  3345. \param{list-2}---a \term{proper list}.
  3346. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  3347. that returns a \term{generalized boolean}.
  3348. \param{test-not}---a \term{designator} for
  3349. a \term{function} of two \term{arguments}
  3350. that returns a \term{generalized boolean}.
  3351. \param{key}---a \term{designator} for a \term{function} of one argument,
  3352. or \nil.
  3353. \param{generalized-boolean}---a \term{generalized boolean}.
  3354. \label Description::
  3355. %% 15.5.0 26
  3356. \funref{subsetp} returns \term{true} if every element of \param{list-1}
  3357. \bogusterm{matches} some element of \param{list-2},
  3358. and \term{false} otherwise.
  3359. Whether a list element is the same as another list element is
  3360. determined by the functions specified by the keyword arguments.
  3361. The first argument to the \kwd{test} or \kwd{test-not}
  3362. function is
  3363. %!!! Sandra: typically?
  3364. typically
  3365. part of an element of \param{list-1} extracted by
  3366. the \kwd{key} function; the second argument is typically part of
  3367. an element of \param{list-2} extracted by
  3368. the \kwd{key} function.
  3369. The argument to the \kwd{key} function is an element of either
  3370. \param{list-1} or \param{list-2}; the return value is part of the element
  3371. of the supplied list element.
  3372. If \kwd{key} is not supplied or \nil,
  3373. the \param{list-1} or \param{list-2}
  3374. element itself is supplied to the \kwd{test} or \kwd{test-not}
  3375. function.
  3376. \label Examples::
  3377. \code
  3378. (setq cosmos '(1 "a" (1 2))) \EV (1 "a" (1 2))
  3379. (subsetp '(1) cosmos) \EV \term{true}
  3380. (subsetp '((1 2)) cosmos) \EV \term{false}
  3381. (subsetp '((1 2)) cosmos :test 'equal) \EV \term{true}
  3382. (subsetp '(1 "A") cosmos :test #'equalp) \EV \term{true}
  3383. (subsetp '((1) (2)) '((1) (2))) \EV \term{false}
  3384. (subsetp '((1) (2)) '((1) (2)) :key #'car) \EV \term{true}
  3385. \endcode
  3386. \label Side Effects:\None.
  3387. \label Affected By:\None.
  3388. \label Exceptional Situations::
  3389. \Lazychecktypes{\param{list-1} and \param{list-2}}{\term{proper lists}}
  3390. \label See Also::
  3391. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3392. {\secref\TraversalRules}
  3393. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3394. \label Notes::
  3395. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3396. The \kwd{test-not} parameter is deprecated.
  3397. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3398. \endcom
  3399. %%% ========== NUNION
  3400. %%% ========== UNION
  3401. \begincom{union, nunion}\ftype{Function}
  3402. \label Syntax::
  3403. \DefunWithValues union {list-1 list-2 {\key} key test test-not} {result-list}
  3404. \DefunWithValues nunion {list-1 list-2 {\key} key test test-not} {result-list}
  3405. \label Arguments and Values::
  3406. \param{list-1}---a \term{proper list}.
  3407. \param{list-2}---a \term{proper list}.
  3408. \param{test}---a \term{designator} for a \term{function} of two \term{arguments}
  3409. that returns a \term{generalized boolean}.
  3410. \param{test-not}---a \term{designator} for
  3411. a \term{function} of two \term{arguments}
  3412. that returns a \term{generalized boolean}.
  3413. \param{key}---a \term{designator} for a \term{function} of one argument,
  3414. or \nil.
  3415. \param{result-list}---a \term{list}.
  3416. \label Description::
  3417. \funref{union} and \funref{nunion} return a \term{list}
  3418. that contains every element that occurs in either \param{list-1}
  3419. or \param{list-2}.
  3420. %% 15.5.0 11
  3421. For all possible ordered pairs consisting of one
  3422. element from \param{list-1}
  3423. and one element from \param{list-2}, \kwd{test} or \kwd{test-not} is used
  3424. to determine whether they \term{satisfy the test}.
  3425. The first argument to the \kwd{test} or \kwd{test-not}
  3426. function is the part of the element of \param{list-1} extracted by the
  3427. \kwd{key} function (if supplied); the second argument
  3428. is the part of the element of \param{list-2} extracted by the
  3429. \kwd{key} function (if supplied).
  3430. The argument to the \kwd{key} function is an element of
  3431. \param{list-1} or \param{list-2}; the return value is part of the supplied
  3432. element.
  3433. If \kwd{key} is not supplied or \nil,
  3434. the element of \param{list-1} or \param{list-2}
  3435. itself is supplied to the \kwd{test} or \kwd{test-not} function.
  3436. For every matching pair,
  3437. %Removed per barmar -kmp 29-Jul-91
  3438. %at least
  3439. one of the two elements of the pair will be in the result. Any
  3440. element from either \param{list-1} or \param{list-2}
  3441. that matches no element of the other will appear
  3442. in the result.
  3443. %% 15.5.0 9
  3444. If there is a duplication between \param{list-1}
  3445. and \param{list-2},
  3446. only one of the duplicate instances will be in the result.
  3447. If either \param{list-1}
  3448. or \param{list-2} has duplicate entries within it,
  3449. the redundant entries
  3450. might or might not appear in the result.
  3451. %% 15.5.0 10
  3452. The order of elements in the result do not have to
  3453. reflect the ordering of \param{list-1} or \param{list-2} in any way.
  3454. The result \term{list} may be \funref{eq} to either
  3455. \param{list-1} or \param{list-2} if appropriate.
  3456. \label Examples::
  3457. \code
  3458. (union '(a b c) '(f a d))
  3459. \EV (A B C F D)
  3460. \OV (B C F A D)
  3461. \OV (D F A B C)
  3462. (union '((x 5) (y 6)) '((z 2) (x 4)) :key #'car)
  3463. \EV ((X 5) (Y 6) (Z 2))
  3464. \OV ((X 4) (Y 6) (Z 2))
  3465. (setq lst1 (list 1 2 '(1 2) "a" "b")
  3466. lst2 (list 2 3 '(2 3) "B" "C"))
  3467. \EV (2 3 (2 3) "B" "C")
  3468. (nunion lst1 lst2)
  3469. \EV (1 (1 2) "a" "b" 2 3 (2 3) "B" "C")
  3470. \OV (1 2 (1 2) "a" "b" "C" "B" (2 3) 3)
  3471. \endcode
  3472. \label Side Effects::
  3473. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3474. \funref{nunion} is permitted to modify any part, \term{car} or \term{cdr},
  3475. of the \term{list structure} of \param{list-1} or \param{list-2}.
  3476. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  3477. \label Affected By:\None.
  3478. \label Exceptional Situations::
  3479. \Lazychecktypes{\param{list-1} and \param{list-2}}{\term{proper lists}}
  3480. \label See Also::
  3481. \funref{intersection},
  3482. \issue{CONSTANT-MODIFICATION:DISALLOW}
  3483. {\secref\ConstantModification},
  3484. \endissue{CONSTANT-MODIFICATION:DISALLOW}
  3485. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3486. {\secref\TraversalRules}
  3487. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3488. \label Notes::
  3489. \issue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3490. The \kwd{test-not} parameter is deprecated.
  3491. \endissue{TEST-NOT-IF-NOT:FLUSH-ALL}
  3492. Since the \funref{nunion} side effect is not required,
  3493. it should not be used in for-effect-only positions in portable code.
  3494. \endcom