dict-flow.tex 215 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278
  1. % -*- Mode: TeX -*-
  2. % Control and Data flow
  3. % Functions
  4. % Variables
  5. % Control Transfer
  6. % Predicates and Truth Values
  7. % Truth Values
  8. % Identity/Equality
  9. % Functional Composition
  10. % Boolean Composition
  11. % Conditionals
  12. % Dispatch
  13. % Multiple Values
  14. % Data and Control
  15. % Setf
  16. %-------------------- Functions --------------------
  17. %%% ========== APPLY
  18. % should this be an accessor rather than a function? --sjl 5 mar 92
  19. \begincom{apply}\ftype{Function}
  20. %!!! This needs some careful review. -kmp 1-Sep-91
  21. \label Syntax::
  22. \DefunWithValues apply {function {\rest} \plus{args}} {\starparam{result}}
  23. \label Arguments and Values::
  24. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  25. \param{function}---a \term{function designator}.
  26. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  27. \param{args}---a \term{spreadable argument list designator}.
  28. %% 7.9.2 5
  29. \param{results}---the \term{values} returned by \param{function}.
  30. \label Description::
  31. %% 7.3.0 2
  32. \term{Applies} the \param{function} to the \param{args}.
  33. %%This is implied by the use of "spreadable argument list designator" above. -kmp 15-Aug-91
  34. % All but the last \param{arg} must be the
  35. % arguments taken by \param{function}.
  36. % The last \param{arg} supplied must be a \term{list} of such arguments.
  37. %
  38. % The argument list for \param{function} consists of the last \param{arg} supplied
  39. % appended to the end of a \term{list} of all the other \param{args}.
  40. \issue{REST-LIST-ALLOCATION:MAY-SHARE}
  41. When the \param{function} receives its arguments via \keyref{rest}, it is
  42. permissible (but not required) for the \term{implementation} to \term{bind}
  43. the \term{rest parameter}
  44. to an \term{object} that shares structure with the last argument to \funref{apply}.
  45. Because a \term{function} can neither detect whether it was called via \funref{apply}
  46. nor whether (if so) the last argument to \funref{apply} was a \term{constant},
  47. \term{conforming programs} must neither rely on the \term{list} structure
  48. of a \term{rest list} to be freshly consed, nor modify that \term{list} structure.
  49. \endissue{REST-LIST-ALLOCATION:MAY-SHARE}
  50. \macref{setf} can be used with \funref{apply} in certain circumstances;
  51. \seesection\SETFofAPPLY.
  52. \label Examples::
  53. \issue{REST-LIST-ALLOCATION:MAY-SHARE}
  54. \code
  55. (setq f '+) \EV +
  56. (apply f '(1 2)) \EV 3
  57. (setq f #'-) \EV #<FUNCTION ->
  58. (apply f '(1 2)) \EV -1
  59. (apply #'max 3 5 '(2 7 3)) \EV 7
  60. (apply 'cons '((+ 2 3) 4)) \EV ((+ 2 3) . 4)
  61. (apply #'+ '()) \EV 0
  62. (defparameter *some-list* '(a b c))
  63. (defun strange-test (&rest x) (eq x *some-list*))
  64. (apply #'strange-test *some-list*) \EV \term{implementation-dependent}
  65. (defun bad-boy (&rest x) (rplacd x 'y))
  66. (bad-boy 'a 'b 'c) has undefined consequences.
  67. (apply #'bad-boy *some-list*) has undefined consequences.
  68. \endcode
  69. \endissue{REST-LIST-ALLOCATION:MAY-SHARE}
  70. \code
  71. (defun foo (size &rest keys &key double &allow-other-keys)
  72. (let ((v (apply #'make-array size :allow-other-keys t keys)))
  73. (if double (concatenate (type-of v) v v) v)))
  74. (foo 4 :initial-contents '(a b c d) :double t)
  75. \EV #(A B C D A B C D)
  76. \endcode
  77. \label Affected By:\None.
  78. \label Exceptional Situations:\None.
  79. %!!! Barmar: "Last argument must be a list."
  80. \label See Also::
  81. \funref{funcall},
  82. \funref{fdefinition},
  83. \specref{function},
  84. {\secref\Evaluation},
  85. {\secref\SETFofAPPLY}
  86. \label Notes:\None.
  87. \endcom
  88. %%% ========== DEFUN
  89. \begincom{defun}\ftype{Macro}
  90. \issue{DECLS-AND-DOC}
  91. \issue{FUNCTION-NAME:LARGE}
  92. \label Syntax::
  93. \DefmacWithValuesNewline defun
  94. {function-name lambda-list {\DeclsAndDoc} \starparam{form}}
  95. {function-name}
  96. \label Arguments and Values::
  97. \param{function-name}---a \term{function name}.
  98. % tweaked --sjl 5 Mar 92
  99. %\param{lambda-list}---a \term{lambda list}.
  100. \param{lambda-list}---an \term{ordinary lambda list}.
  101. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  102. %% 5.3.1 3
  103. \param{documentation}---a \term{string}; \noeval.
  104. %% 5.3.1 4
  105. \param{forms}---an \term{implicit progn}.
  106. \param{block-name}---the \term{function block name} of the \param{function-name}.
  107. \label Description::
  108. Defines a new \term{function} named \param{function-name} in the \term{global environment}.
  109. The body of the \term{function} defined by \macref{defun} consists
  110. of \param{forms}; they are executed as an \term{implicit progn}
  111. when the \term{function} is called.
  112. %% 5.3.1 6
  113. \macref{defun} can be used
  114. to define a new \term{function},
  115. to install a corrected version of an incorrect definition,
  116. to redefine an already-defined \term{function},
  117. or to redefine a \term{macro} as a \term{function}.
  118. %% 5.3.1 5
  119. %% 7.7.0 4
  120. \macref{defun} implicitly puts a \specref{block} named \param{block-name}
  121. around the body \param{forms}
  122. \issue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  123. (but not the \term{forms} in the \param{lambda-list})
  124. \endissue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  125. of the \term{function} defined.
  126. %% 5.3.1 3
  127. \issue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  128. \param{Documentation} is attached as a \term{documentation string}
  129. to \param{name} (as kind \specref{function})
  130. and to the \term{function} \term{object}.
  131. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  132. %% 5.3.1 2
  133. Evaluating \macref{defun} causes \param{function-name} to be a global name
  134. for the \term{function} specified by the \term{lambda expression}
  135. \code
  136. (lambda \param{lambda-list}
  137. {\DeclsAndDoc}
  138. (block \param{block-name} \starparam{form}))
  139. \endcode
  140. processed in the \term{lexical environment} in which \macref{defun} was executed.
  141. (None of the arguments are evaluated at macro expansion time.)
  142. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  143. \macref{defun} is not required to perform any compile-time side effects.
  144. In particular, \macref{defun} does not make the \term{function} definition available
  145. at compile time. An \term{implementation} may choose to store information
  146. about the \term{function} for the purposes of compile-time error-checking
  147. (such as checking the number of arguments on calls),
  148. or to enable the \term{function} to be expanded inline.
  149. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  150. \label Examples::
  151. \code
  152. (defun recur (x)
  153. (when (> x 0)
  154. (recur (1- x)))) \EV RECUR
  155. (defun ex (a b &optional c (d 66) &rest keys &key test (start 0))
  156. (list a b c d keys test start)) \EV EX
  157. (ex 1 2) \EV (1 2 NIL 66 NIL NIL 0)
  158. (ex 1 2 3 4 :test 'equal :start 50)
  159. \EV (1 2 3 4 (:TEST EQUAL :START 50) EQUAL 50)
  160. (ex :test 1 :start 2) \EV (:TEST 1 :START 2 NIL NIL 0)
  161. ;; This function assumes its callers have checked the types of the
  162. ;; arguments, and authorizes the compiler to build in that assumption.
  163. (defun discriminant (a b c)
  164. (declare (number a b c))
  165. "Compute the discriminant for a quadratic equation."
  166. (- (* b b) (* 4 a c))) \EV DISCRIMINANT
  167. (discriminant 1 2/3 -2) \EV 76/9
  168. ;; This function assumes its callers have not checked the types of the
  169. ;; arguments, and performs explicit type checks before making any assumptions.
  170. (defun careful-discriminant (a b c)
  171. "Compute the discriminant for a quadratic equation."
  172. (check-type a number)
  173. (check-type b number)
  174. (check-type c number)
  175. (locally (declare (number a b c))
  176. (- (* b b) (* 4 a c)))) \EV CAREFUL-DISCRIMINANT
  177. (careful-discriminant 1 2/3 -2) \EV 76/9
  178. \endcode
  179. \label Affected By:\None.
  180. \label Exceptional Situations:\None.
  181. % adequately addressed in the packages chapter. --sjl 5 mar 92
  182. % \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  183. % For each \i{S} that is a \term{symbol} in \thepackage{common-lisp},
  184. % the consequences are undefined if either \i{S} or \f{(setf \i{S})}
  185. % is used as the \param{function-name}.
  186. % \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  187. \label See Also::
  188. \specref{flet},
  189. \specref{labels},
  190. \specref{block},
  191. \specref{return-from},
  192. \misc{declare},
  193. \funref{documentation},
  194. {\secref\Evaluation},
  195. {\secref\OrdinaryLambdaLists},
  196. {\secref\DocVsDecls}
  197. \label Notes::
  198. %% 5.3.1 5
  199. \specref{return-from} can be used to return
  200. prematurely from a \term{function} defined by \macref{defun}.
  201. Additional side effects might take place when additional information
  202. (typically debugging information)
  203. about the function definition is recorded.
  204. \endissue{FUNCTION-NAME:LARGE}
  205. \endissue{DECLS-AND-DOC}
  206. \endcom
  207. %%% ========== FDEFINITION
  208. \begincom{fdefinition}\ftype{Accessor}
  209. \issue{FUNCTION-NAME:LARGE}
  210. \label Syntax::
  211. \DefunWithValues fdefinition {function-name} {definition}
  212. \Defsetf fdefinition {function-name} {new-definition}
  213. \label Arguments and Values::
  214. \param{function-name}---a \term{function name}.
  215. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  216. In the non-\macref{setf} case,
  217. the \term{name} must be \term{fbound} in the \term{global environment}.
  218. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  219. \param{definition}---Current global function definition named by \param{function-name}.
  220. \param{new-definition}---a \term{function}.
  221. \label Description::
  222. \funref{fdefinition} \term{accesses} the current global function definition
  223. named by \param{function-name}. The definition may be a
  224. \term{function} or may be an \term{object} representing a
  225. \term{special form} or \term{macro}.
  226. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  227. The value returned by \funref{fdefinition} when \funref{fboundp} returns true
  228. but the \param{function-name} denotes a \term{macro} or
  229. \term{special form} is not well-defined, but \funref{fdefinition} does not signal an error.
  230. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  231. \label Examples:\None.
  232. \label Side Effects:\None.
  233. \label Affected By:\None.
  234. \label Exceptional Situations::
  235. \Shouldchecktype{function-name}{a \term{function name}}
  236. An error \oftype{undefined-function} is signaled
  237. in the non-\macref{setf} case if \param{function-name} is not \term{fbound}.
  238. \label See Also::
  239. \funref{fboundp},
  240. \funref{fmakunbound},
  241. \funref{macro-function},
  242. \issue{SPECIAL-FORM-P-MISNOMER:RENAME}
  243. \funref{special-operator-p},
  244. \endissue{SPECIAL-FORM-P-MISNOMER:RENAME}
  245. \funref{symbol-function}
  246. \label Notes::
  247. \funref{fdefinition} cannot \term{access} the value of a lexical function name
  248. produced by \specref{flet} or \specref{labels}; it can \term{access} only
  249. the global function value.
  250. \macref{setf} can be used with
  251. \funref{fdefinition} to replace a global function
  252. definition when the \param{function-name}'s function definition
  253. does not represent a \term{special form}.
  254. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  255. \macref{setf} of \funref{fdefinition}
  256. requires a \term{function} as the new value.
  257. It is an error to set the \funref{fdefinition} of a \param{function-name}
  258. to a \term{symbol}, a \term{list}, or the value returned
  259. by \funref{fdefinition} on the name of a \term{macro}
  260. or \term{special form}.
  261. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  262. \endissue{FUNCTION-NAME:LARGE}
  263. \endcom
  264. %%% ========== FBOUNDP
  265. \begincom{fboundp}\ftype{Function}
  266. \label Syntax::
  267. \DefunWithValues fboundp {name} {generalized-boolean}
  268. \label Pronunciation::
  269. \pronounced{\stress{ef}\Stress{ba\.und}p\harde}
  270. \label Arguments and Values::
  271. \issue{FUNCTION-NAME:LARGE}
  272. \param{name}---a \term{function name}.
  273. \endissue{FUNCTION-NAME:LARGE}
  274. \param{generalized-boolean}---a \term{generalized boolean}.
  275. \label Description::
  276. %% 7.1.1 20
  277. \Predicate{name}{\term{fbound}}
  278. \label Examples::
  279. %Some "implementation dependent" => "true" per Moore #2 (first public review). -kmp 12-May-93
  280. \code
  281. (fboundp 'car) \EV \term{true}
  282. (fboundp 'nth-value) \EV \term{false}
  283. (fboundp 'with-open-file) \EV \term{true}
  284. (fboundp 'unwind-protect) \EV \term{true}
  285. (defun my-function (x) x) \EV MY-FUNCTION
  286. (fboundp 'my-function) \EV \term{true}
  287. (let ((saved-definition (symbol-function 'my-function)))
  288. (unwind-protect (progn (fmakunbound 'my-function)
  289. (fboundp 'my-function))
  290. (setf (symbol-function 'my-function) saved-definition)))
  291. \EV \term{false}
  292. (fboundp 'my-function) \EV \term{true}
  293. (defmacro my-macro (x) `',x) \EV MY-MACRO
  294. (fboundp 'my-macro) \EV \term{true}
  295. (fmakunbound 'my-function) \EV MY-FUNCTION
  296. (fboundp 'my-function) \EV \term{false}
  297. (flet ((my-function (x) x))
  298. (fboundp 'my-function)) \EV \term{false}
  299. \endcode
  300. \label Side Effects:\None.
  301. \label Affected By:\None.
  302. \label Exceptional Situations::
  303. \Shouldchecktype{name}{a \term{function name}}
  304. \label See Also::
  305. \funref{symbol-function}, \funref{fmakunbound}, \funref{fdefinition}
  306. \label Notes::
  307. It is permissible to call \funref{symbol-function} on any \term{symbol}
  308. that is \term{fbound}.
  309. \funref{fboundp} is sometimes used to ``guard''
  310. an access to the \term{function cell}, as in:
  311. \code
  312. (if (fboundp x) (symbol-function x))
  313. \endcode
  314. \issue{SETF-FUNCTIONS-AGAIN:MINIMAL-CHANGES}
  315. Defining a \term{setf expander} \param{F} does not cause the \term{setf function}
  316. \f{(setf \param{F})} to become defined.
  317. %% Moon wanted this removed because he thinks it is "redundant and pompous". -kmp 4-Dec-91
  318. % as such, if there is such a definition
  319. % of a \term{setf expander} \param{F}, the \term{function} \f{(setf \param{F})}
  320. % can be \term{fbound} if and only if, by design or coincidence, a
  321. % function binding for \f{(setf \param{F})} has been independently established.
  322. \endissue{SETF-FUNCTIONS-AGAIN:MINIMAL-CHANGES}
  323. \endcom
  324. %%% ========== FMAKUNBOUND
  325. \begincom{fmakunbound}\ftype{Function}
  326. \label Syntax::
  327. \DefunWithValues fmakunbound {name} {name}
  328. \label Pronunciation::
  329. \pronounced{\stress{ef}\Stress{mak}\schwa n\stress{ba\.und}}
  330. or \pronounced{\stress{ef}\Stress{m\harda k}\schwa n\stress{ba\.und}}
  331. \label Arguments and Values::
  332. \issue{FUNCTION-NAME:LARGE}
  333. \param{name}---a \term{function name}.
  334. \endissue{FUNCTION-NAME:LARGE}
  335. \label Description::
  336. Removes the \term{function} or \term{macro} definition, if any, of \param{name}
  337. in the \term{global environment}.
  338. \label Examples::
  339. \code
  340. (defun add-some (x) (+ x 19)) \EV ADD-SOME
  341. (fboundp 'add-some) \EV \term{true}
  342. (flet ((add-some (x) (+ x 37)))
  343. (fmakunbound 'add-some)
  344. (add-some 1)) \EV 38
  345. (fboundp 'add-some) \EV \term{false}
  346. \endcode
  347. \label Side Effects:\None.
  348. % I see no symbol here. --sjl 5 Mar 92
  349. %The \term{function cell} of \param{symbol} is modified.
  350. \label Affected By:\None.
  351. \label Exceptional Situations::
  352. \Shouldchecktype{name}{a \term{function name}}
  353. The consequences are undefined if \param{name} is a \term{special operator}.
  354. \label See Also::
  355. \funref{fboundp}, \funref{makunbound}
  356. \label Notes:\None.
  357. \endcom
  358. %%% ========== FLET
  359. %%% ========== LABELS
  360. %%% ========== MACROLET
  361. \begincom{flet, labels, macrolet}\ftype{Special Operator}
  362. \issue{DECLS-AND-DOC}
  363. \label Syntax::
  364. \issue{FLET-DECLARATIONS:ALLOW}
  365. \DefspecWithValuesNewline flet
  366. {\vtop{\hbox{\paren{\starparen{\param{function-name}
  367. \param{lambda-list}
  368. {\LocalDeclsAndDoc}
  369. \starparam{local-form}}}}
  370. \hbox{\starparam{declaration} \starparam{form}}}}
  371. {\starparam{result}}
  372. \DefspecWithValuesNewline labels
  373. {\vtop{\hbox{\paren{\starparen{\param{function-name}
  374. \param{lambda-list}
  375. {\LocalDeclsAndDoc}
  376. \starparam{local-form}}}}
  377. \hbox{\starparam{declaration} \starparam{form}}}}
  378. {\starparam{result}}
  379. \DefspecWithValuesNewline macrolet
  380. {\vtop{\hbox{\paren{\starparen{\param{name}
  381. \param{lambda-list}
  382. {\LocalDeclsAndDoc}
  383. \starparam{local-form}}}}
  384. \hbox{\starparam{declaration} \starparam{form}}}}
  385. {\starparam{result}}
  386. \endissue{FLET-DECLARATIONS:ALLOW}
  387. \label Arguments and Values::
  388. \issue{FUNCTION-NAME:LARGE}
  389. \param{function-name}---a \term{function name}.
  390. \endissue{FUNCTION-NAME:LARGE}
  391. \param{name}---a \term{symbol}.
  392. %name of the \term{macro} being defined.
  393. \param{lambda-list}---a \term{lambda list};
  394. for \specref{flet} and \specref{labels},
  395. it is an \term{ordinary lambda list};
  396. for \specref{macrolet},
  397. it is a \term{macro lambda list}.
  398. \param{local-declaration}---a \misc{declare} \term{expression}; \noeval.
  399. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  400. \param{local-documentation}---a \term{string}; \noeval.
  401. \param{local-forms}, \param{forms}---an \term{implicit progn}.
  402. \param{results}---the \term{values} of the \param{forms}.
  403. \label Description::
  404. \specref{flet}, \specref{labels}, and \specref{macrolet}
  405. define local \term{functions} and \term{macros}, and execute
  406. \param{forms} using the local definitions.
  407. \param{Forms} are executed in order of occurrence.
  408. \issue{FLET-IMPLICIT-BLOCK:YES}
  409. \issue{FUNCTION-NAME:LARGE}
  410. \issue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  411. The body forms (but not the \term{lambda list})
  412. \endissue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  413. of each \term{function} created by \specref{flet} and \specref{labels}
  414. and each \term{macro} created by \specref{macrolet}
  415. are enclosed in an \term{implicit block} whose name
  416. is the \term{function block name} of the \param{function-name} or \param{name},
  417. as appropriate.
  418. \endissue{FUNCTION-NAME:LARGE}
  419. \endissue{FLET-IMPLICIT-BLOCK:YES}
  420. \issue{FLET-DECLARATIONS}
  421. The scope of the \param{declarations}
  422. between
  423. the list of local function/macro definitions and the body \param{forms}
  424. in \specref{flet} and \specref{labels}
  425. does not include the bodies of the
  426. locally defined \term{functions}, except that for \specref{labels},
  427. any \declref{inline}, \declref{notinline}, or \declref{ftype} declarations
  428. that refer to the locally defined functions do apply to the local function
  429. bodies. That is, their \term{scope}
  430. is the same as the function name that they
  431. affect.
  432. \issue{DECLARATION-SCOPE:NO-HOISTING}
  433. %The following will be deleted from the standard:
  434. %
  435. %when the \param{declarations}
  436. %are \term{pervasive}. Non-\term{pervasive}
  437. %\param{declarations} have no effect on those bodies, except when
  438. %\specref{labels} includes the
  439. %body in the \term{scope} of a function non-\term{pervasively} declared.
  440. %
  441. %End of deletion.
  442. \endissue{DECLARATION-SCOPE:NO-HOISTING}
  443. The scope of these \param{declarations}
  444. does not include the bodies of the macro expander
  445. functions defined by \specref{macrolet}.
  446. \endissue{FLET-DECLARATIONS}
  447. % This is adequately covered in the packages chapter. --sjl 5 mar 92
  448. %\issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  449. %The consequences are undefined if a \term{symbol} in \thepackage{common-lisp}
  450. %that is defined as a \term{function}, \term{macro}, or \term{special form}
  451. %is used as the function-name or name argument.
  452. %If such a \term{symbol} is not defined as a \term{function}, \term{macro}, or
  453. %\term{special form}, it is allowed to (lexically) bind it as a \term{function}
  454. %or \term{macro}.
  455. %\endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  456. \beginlist
  457. \itemitem{\bf flet}
  458. %% 7.5.0 17
  459. \specref{flet} defines locally named \term{functions} and executes a series of
  460. \param{forms} with these definition \term{bindings}. Any number of
  461. such local \term{functions} can be defined.
  462. The \term{scope} of the name \term{binding} encompasses only the body.
  463. Within the
  464. body of \specref{flet},
  465. \param{function-names} matching those defined
  466. by \specref{flet}
  467. refer to the locally defined \term{functions}
  468. rather than to
  469. the global function definitions of the same name.
  470. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  471. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  472. Also, within the scope of \specref{flet},
  473. global \term{setf expander} definitions of the \param{function-name}
  474. defined by \specref{flet} do not apply.
  475. %% This shouldn't be needed any more under SETF-METHOD-VS-SETF-METHOD.
  476. %!!! Issue: (defun (setf x) ...) vs (defmethod (setf x) ...) is really the issue, isn't it?
  477. Note that this applies to
  478. {\tt (defsetf \i{f} ...)}, not
  479. {\tt (defmethod (setf \i{f}) ...)}.
  480. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  481. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  482. The names of \term{functions} defined by \specref{flet}
  483. are in the \term{lexical environment}; they retain
  484. their local definitions only within the body of \specref{flet}.
  485. The function definition bindings are visible only in
  486. the body of \specref{flet}, not the definitions themselves. Within the
  487. function definitions, local function names
  488. that match those being
  489. defined refer to \term{functions} or
  490. \term{macros} defined outside the \specref{flet}.
  491. \specref{flet} can locally \term{shadow} a global function name,
  492. and the new definition can refer to the global definition.
  493. Any \param{local-documentation} is attached to the corresponding local \param{function}
  494. (if one is actually created) as a \term{documentation string}.
  495. \itemitem{\bf labels}
  496. %% 7.5.0 18
  497. \specref{labels} is equivalent to \specref{flet} except that
  498. the scope of the defined function names for \specref{labels}
  499. encompasses the function definitions themselves as well as the body.
  500. % That is, within the body of \specref{labels},
  501. % \param{function-names} matching those defined by \specref{labels}
  502. % refer to the locally defined \term{functions}
  503. % rather than to
  504. % the global function definitions of the same name.
  505. %!!! FLET duplicates this same text. Is there a way to centralize it?
  506. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  507. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  508. %% Moon says this is "redundant and confusing"--presumably because it's
  509. %% already said under FLET, which LABELS purports to be equivalent to. -kmp 4-Dec-91
  510. % Within the scope of \specref{labels},
  511. % any global \term{setf expander} definitions whose names are among the \param{function-names}
  512. % are lexically disabled.
  513. %% This shouldn't be needed under SETF-METHOD-VS-SETF-METHOD
  514. % Note that this applies to {\tt (defsetf \i{f} ...)}, not
  515. % {\tt (defmethod (setf \i{f}) ...)}.
  516. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  517. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  518. \itemitem{\bf macrolet}
  519. %% 7.5.0 19
  520. \specref{macrolet} %is different from \specref{flet} in that it
  521. establishes local \term{macro} definitions,
  522. using the same format used by \macref{defmacro}.
  523. %!!! Duplicated in FLET and LABELS. Centralize? -kmp 8-May-91
  524. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  525. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  526. % We haven't defined what the scope is yet. --sjl 5 mar 92
  527. %Within the scope of \specref{macrolet},
  528. Within the body of \specref{macrolet},
  529. global \term{setf expander} definitions of the \param{names} defined by the
  530. \specref{macrolet} do not apply; rather, \macref{setf} expands the
  531. \term{macro form} and recursively process the resulting \term{form}.
  532. %!!! See note above about (defun (setf x) ...) ...
  533. % Note that this applies to {\tt (defsetf \i{f} ...)}, not
  534. % {\tt (defmethod (setf \i{f}) ...)}.
  535. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  536. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  537. %!!! Barmar: Mention that macros are expadned at semantic analysis time
  538. % so even global varaible references must be to variables gieven values at compile time.
  539. %% 7.5.0 20
  540. The macro-expansion functions defined by \specref{macrolet}
  541. are defined in the
  542. \issue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  543. \term{lexical environment} in which the \specref{macrolet} form appears.
  544. %global environment.
  545. Declarations and \specref{macrolet} and
  546. \specref{symbol-macrolet} definitions
  547. affect the local macro definitions in a \specref{macrolet}, but the
  548. consequences are undefined if the local macro definitions reference
  549. any local \term{variable} or \term{function} \term{bindings} that are visible in that
  550. \term{lexical environment}.
  551. %Lexical entities that would ordinarily be lexically apparent
  552. %are not visible within the expansion functions. However,
  553. %lexical entities are visible
  554. %within the body of the \specref{macrolet} form and are visible
  555. %to the code that is the expansion of a macro call.
  556. \endissue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  557. Any \param{local-documentation} is attached to the corresponding local \param{macro function}
  558. as a \term{documentation string}.
  559. \endlist
  560. \label Examples::
  561. \code
  562. (defun foo (x flag)
  563. (macrolet ((fudge (z)
  564. ;The parameters x and flag are not accessible
  565. ; at this point; a reference to flag would be to
  566. ; the global variable of that name.
  567. \bq\ (if flag (* ,z ,z) ,z)))
  568. ;The parameters x and flag are accessible here.
  569. (+ x
  570. (fudge x)
  571. (fudge (+ x 1)))))
  572. \EQ
  573. (defun foo (x flag)
  574. (+ x
  575. (if flag (* x x) x)
  576. (if flag (* (+ x 1) (+ x 1)) (+ x 1))))
  577. \endcode
  578. after macro expansion. The occurrences of \f{x} and \f{flag} legitimately
  579. refer to the parameters of the function \f{foo} because those parameters are
  580. visible at the site of the macro call which produced the expansion.
  581. \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  582. %Barmar points out that this example violated LISP-SYMBOL-REDEFINITION:
  583. % \code
  584. % (flet ((+ (&rest args) 'crossed-out)) (+ 1 2 3)) \EV CROSSED-OUT
  585. % \endcode
  586. \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  587. \code
  588. (flet ((flet1 (n) (+ n n)))
  589. (flet ((flet1 (n) (+ 2 (flet1 n))))
  590. (flet1 2))) \EV 6
  591. (defun dummy-function () 'top-level) \EV DUMMY-FUNCTION
  592. (funcall #'dummy-function) \EV TOP-LEVEL
  593. (flet ((dummy-function () 'shadow))
  594. (funcall #'dummy-function)) \EV SHADOW
  595. (eq (funcall #'dummy-function) (funcall 'dummy-function))
  596. \EV \term{true}
  597. (flet ((dummy-function () 'shadow))
  598. (eq (funcall #'dummy-function)
  599. (funcall 'dummy-function)))
  600. \EV \term{false}
  601. (defun recursive-times (k n)
  602. (labels ((temp (n)
  603. (if (zerop n) 0 (+ k (temp (1- n))))))
  604. (temp n))) \EV RECURSIVE-TIMES
  605. (recursive-times 2 3) \EV 6
  606. (defmacro mlets (x &environment env)
  607. (let ((form `(babbit ,x)))
  608. (macroexpand form env))) \EV MLETS
  609. (macrolet ((babbit (z) `(+ ,z ,z))) (mlets 5)) \EV 10
  610. \endcode
  611. \code
  612. (flet ((safesqrt (x) (sqrt (abs x))))
  613. ;; The safesqrt function is used in two places.
  614. (safesqrt (apply #'+ (map 'list #'safesqrt '(1 2 3 4 5 6)))))
  615. \EV 3.291173
  616. \endcode
  617. \code
  618. (defun integer-power (n k)
  619. (declare (integer n))
  620. (declare (type (integer 0 *) k))
  621. (labels ((expt0 (x k a)
  622. (declare (integer x a) (type (integer 0 *) k))
  623. (cond ((zerop k) a)
  624. ((evenp k) (expt1 (* x x) (floor k 2) a))
  625. (t (expt0 (* x x) (floor k 2) (* x a)))))
  626. (expt1 (x k a)
  627. (declare (integer x a) (type (integer 0 *) k))
  628. (cond ((evenp k) (expt1 (* x x) (floor k 2) a))
  629. (t (expt0 (* x x) (floor k 2) (* x a))))))
  630. (expt0 n k 1))) \EV INTEGER-POWER
  631. \endcode
  632. \issue{FLET-DECLARATIONS}
  633. \code
  634. (defun example (y l)
  635. (flet ((attach (x)
  636. (setq l (append l (list x)))))
  637. (declare (inline attach))
  638. (dolist (x y)
  639. (unless (null (cdr x))
  640. (attach x)))
  641. l))
  642. (example '((a apple apricot) (b banana) (c cherry) (d) (e))
  643. '((1) (2) (3) (4 2) (5) (6 3 2)))
  644. \EV ((1) (2) (3) (4 2) (5) (6 3 2) (A APPLE APRICOT) (B BANANA) (C CHERRY))
  645. \endcode
  646. \endissue{FLET-DECLARATIONS}
  647. \label Affected By:\None.
  648. \label Exceptional Situations:\None.
  649. \label See Also::
  650. \misc{declare},
  651. \macref{defmacro},
  652. \macref{defun},
  653. \funref{documentation},
  654. \macref{let},
  655. {\secref\Evaluation},
  656. {\secref\DocVsDecls}
  657. \label Notes::
  658. It is not possible to define recursive \term{functions} with \specref{flet}.
  659. \specref{labels} can be used to define mutually recursive \term{functions}.
  660. If a \specref{macrolet} \term{form} is a \term{top level form},
  661. the body \param{forms} are also processed as \term{top level forms}.
  662. \Seesection\FileCompilation.
  663. \endissue{DECLS-AND-DOC}
  664. \endcom
  665. %%% ========== FUNCALL
  666. \begincom{funcall}\ftype{Function}
  667. \label Syntax::
  668. \DefunWithValues funcall {function {\rest} args} {\starparam{result}}
  669. \label Arguments and Values::
  670. \param{function}---a \term{function designator}.
  671. \param{args}---\term{arguments} to the \param{function}.
  672. %% 7.9.2 5
  673. \param{results}---the \term{values} returned by the \param{function}.
  674. \label Description::
  675. %% 7.3.0 3
  676. \funref{funcall} applies \param{function} to \param{args}.
  677. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  678. %!!! Barmar: "a symbol" => "a function name"
  679. If \param{function} is a \term{symbol},
  680. it is coerced to a \term{function} as if by
  681. %!!! Barmar: => "... as if fdefinition."
  682. finding its \term{functional value} in the \term{global environment}.
  683. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  684. \label Examples::
  685. \code
  686. (funcall #'+ 1 2 3) \EV 6
  687. (funcall 'car '(1 2 3)) \EV 1
  688. (funcall 'position 1 '(1 2 3 2 1) :start 1) \EV 4
  689. (cons 1 2) \EV (1 . 2)
  690. (flet ((cons (x y) `(kons ,x ,y)))
  691. (let ((cons (symbol-function '+)))
  692. (funcall #'cons
  693. (funcall 'cons 1 2)
  694. (funcall cons 1 2))))
  695. \EV (KONS (1 . 2) 3)
  696. \endcode
  697. \label Affected By:\None.
  698. \label Exceptional Situations::
  699. An error \oftype{undefined-function} should be signaled if \param{function}
  700. is a \term{symbol} that does not have a global definition as a \term{function}
  701. or that has a global definition as a \term{macro} or a \term{special operator}.
  702. \label See Also::
  703. \funref{apply}, \specref{function}, {\secref\Evaluation}
  704. \label Notes::
  705. \code
  706. (funcall \param{function} \param{arg1} \param{arg2} ...)
  707. \EQ (apply \param{function} \param{arg1} \param{arg2} ... nil)
  708. \EQ (apply \param{function} (list \param{arg1} \param{arg2} ...))
  709. \endcode
  710. The difference between \funref{funcall} and an ordinary function call is that
  711. in the former case the \param{function} is obtained by ordinary \term{evaluation}
  712. of a \term{form}, and in the latter case it is obtained by the special
  713. interpretation of the function position that normally occurs.
  714. \endcom
  715. %%% ========== FUNCTION
  716. \begincom{function}\ftype{Special Operator}
  717. % What about these?
  718. % #'#.#'car
  719. % (#.#'car '(x))
  720. % -kmp 24-Apr-91
  721. \issue{FUNCTION-NAME:LARGE}
  722. \label Syntax::
  723. \DefspecWithValues function {name} {function}
  724. \label Arguments and Values::
  725. \param{name}---a \term{function name} or \term{lambda expression}.
  726. %% 2.13.0 5
  727. \param{function}---a \term{function} \term{object}.
  728. \label Description::
  729. %% 7.1.1 4
  730. The \term{value} of \specref{function} is the \term{functional value} of \param{name}
  731. in the current \term{lexical environment}.
  732. If \param{name} is a \term{function name}, the functional definition of that name
  733. %which is that
  734. is that
  735. %!!! Must be a better way to say this! -kmp
  736. % Yup. -- sjl 5 Mar 92
  737. established by the innermost lexically enclosing
  738. \specref{flet}, \specref{labels}, or \specref{macrolet} \term{form},
  739. %if there is one, or else the global functional definition of the \term{symbol}
  740. if there is one. Otherwise the global functional definition of the
  741. \term{function name}
  742. is returned.
  743. If \param{name} is a \term{lambda expression}, then a \term{lexical closure}
  744. is returned. In situations where a \term{closure} over the same set of
  745. \term{bindings} might be produced more than once, the various resulting
  746. \term{closures} might or might not be \funref{eq}.
  747. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  748. It is an error to use \specref{function} on a \term{function name}
  749. that does not denote a \term{function} in the lexical environment in
  750. which the \specref{function} form appears.
  751. Specifically, it is an error to use \specref{function} on a \term{symbol}
  752. that denotes a \term{macro} or \term{special form}.
  753. An implementation may choose not to signal this error for
  754. performance reasons, but implementations are forbidden from
  755. defining the failure to signal an error as a useful behavior.
  756. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  757. \label Examples::
  758. \code
  759. (defun adder (x) (function (lambda (y) (+ x y))))
  760. \endcode
  761. The result of \f{(adder 3)} is a function that adds \f{3} to its argument:
  762. \code
  763. (setq add3 (adder 3))
  764. (funcall add3 5) \EV 8
  765. \endcode
  766. This works because \specref{function} creates a \term{closure} of
  767. the \term{lambda expression} that is able to refer to the \term{value} \f{3}
  768. of the variable \f{x} even after control has returned from the function \f{adder}.
  769. \label Side Effects:\None.
  770. \label Affected By:\None.
  771. \label Exceptional Situations:\None.
  772. %!!! Moon: Perhaps "should signal" undefined-function and/or type-error.
  773. \label See Also::
  774. \macref{defun},
  775. \funref{fdefinition},
  776. \specref{flet},
  777. \specref{labels},
  778. \funref{symbol-function},
  779. {\secref\SymbolsAsForms},
  780. {\secref\SharpsignQuote},
  781. {\secref\PrintingOtherObjects}
  782. \label Notes::
  783. The notation {\tt \#'\param{name}} may be used as an abbreviation
  784. for {\tt (function \param{name})}.
  785. \endissue{FUNCTION-NAME:LARGE}
  786. \endcom
  787. %%% ========== FUNCTION-LAMBDA-EXPRESSION
  788. \begincom{function-lambda-expression}\ftype{Function}
  789. \issue{FUNCTION-DEFINITION:JAN89-X3J13}
  790. \label Syntax::
  791. \DefunWithValuesNewline function-lambda-expression
  792. {function}
  793. {lambda-expression, closure-p, name}
  794. \label Arguments and Values::
  795. \param{function}---a \term{function}.
  796. \param{lambda-expression}---a \term{lambda expression} or \nil.
  797. \param{closure-p}---a \term{generalized boolean}.
  798. \param{name}---an \term{object}.
  799. \label Description::
  800. Returns information about \param{function} as follows:
  801. The \term{primary value}, \param{lambda-expression},
  802. is \param{function}'s defining \term{lambda expression},
  803. or \nil\ if the information is not available. The \term{lambda expression}
  804. may have been pre-processed in some ways, but it should remain a suitable
  805. argument to \funref{compile} or \specref{function}.
  806. Any \term{implementation} may legitimately return \nil\
  807. as the \param{lambda-expression} of any \param{function}.
  808. The \term{secondary value}, \param{closure-p},
  809. is \nil\ if \param{function}'s definition was enclosed
  810. in the \term{null lexical environment} or something \term{non-nil} if
  811. \param{function}'s definition might have been enclosed in some
  812. \term{non-null lexical environment}.
  813. Any \term{implementation} may legitimately return \term{true}
  814. as the \param{closure-p} of any \param{function}.
  815. The \term{tertiary value}, \param{name},
  816. is the ``name'' of \param{function}.
  817. The name is intended for debugging only and is not necessarily one that would
  818. be valid for use as a name in \macref{defun} or \specref{function}, for example.
  819. By convention, \nil\ is used to mean that \param{function} has no name.
  820. Any \term{implementation} may legitimately return \nil\
  821. as the \param{name} of any \param{function}.
  822. \label Examples::
  823. The following examples illustrate some possible return values, but
  824. are not intended to be exhaustive:
  825. \code
  826. (function-lambda-expression #'(lambda (x) x))
  827. \EV NIL, \term{false}, NIL
  828. \OV NIL, \term{true}, NIL
  829. \OV (LAMBDA (X) X), \term{true}, NIL
  830. \OV (LAMBDA (X) X), \term{false}, NIL
  831. (function-lambda-expression
  832. (funcall #'(lambda () #'(lambda (x) x))))
  833. \EV NIL, \term{false}, NIL
  834. \OV NIL, \term{true}, NIL
  835. \OV (LAMBDA (X) X), \term{true}, NIL
  836. \OV (LAMBDA (X) X), \term{false}, NIL
  837. (function-lambda-expression
  838. (funcall #'(lambda (x) #'(lambda () x)) nil))
  839. \EV NIL, \term{true}, NIL
  840. \OV (LAMBDA () X), \term{true}, NIL
  841. \NV NIL, \term{false}, NIL
  842. \NV (LAMBDA () X), \term{false}, NIL
  843. (flet ((foo (x) x))
  844. (setf (symbol-function 'bar) #'foo)
  845. (function-lambda-expression #'bar))
  846. \EV NIL, \term{false}, NIL
  847. \OV NIL, \term{true}, NIL
  848. \OV (LAMBDA (X) (BLOCK FOO X)), \term{true}, NIL
  849. \OV (LAMBDA (X) (BLOCK FOO X)), \term{false}, FOO
  850. \OV (SI::BLOCK-LAMBDA FOO (X) X), \term{false}, FOO
  851. (defun foo ()
  852. (flet ((bar (x) x))
  853. #'bar))
  854. (function-lambda-expression (foo))
  855. \EV NIL, \term{false}, NIL
  856. \OV NIL, \term{true}, NIL
  857. \OV (LAMBDA (X) (BLOCK BAR X)), \term{true}, NIL
  858. \OV (LAMBDA (X) (BLOCK BAR X)), \term{true}, (:INTERNAL FOO 0 BAR)
  859. \OV (LAMBDA (X) (BLOCK BAR X)), \term{false}, "BAR in FOO"
  860. \endcode
  861. \label Side Effects:\None.
  862. \label Affected By:\None.
  863. \label Exceptional Situations:\None.
  864. \label See Also:\None.
  865. \label Notes::
  866. Although \term{implementations} are free to return ``\nil, \term{true}, \nil'' in all cases,
  867. they are encouraged to return a \term{lambda expression} as the \term{primary value}
  868. in the case where the argument was created by a call to \funref{compile}
  869. or \funref{eval} (as opposed to being created by \term{loading} a \term{compiled file}).
  870. \endissue{FUNCTION-DEFINITION:JAN89-X3J13}
  871. \endcom
  872. %%% ========== FUNCTIONP
  873. \begincom{functionp}\ftype{Function}
  874. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  875. \label Syntax::
  876. \DefunWithValues functionp {object} {generalized-boolean}
  877. \label Arguments and Values::
  878. \param{object}---an \term{object}.
  879. \param{generalized-boolean}---a \term{generalized boolean}.
  880. \label Description::
  881. \TypePredicate{object}{function}
  882. %% 6.2.2 26
  883. %% 6.2.2 27
  884. % These are overridden by FUNCTION-TYPE:X3J13-MARCH-88.
  885. \label Examples::
  886. \code
  887. (functionp 'append) \EV \term{false}
  888. (functionp #'append) \EV \term{true}
  889. (functionp (symbol-function 'append)) \EV \term{true}
  890. (flet ((f () 1)) (functionp #'f)) \EV \term{true}
  891. (functionp (compile nil '(lambda () 259))) \EV \term{true}
  892. (functionp nil) \EV \term{false}
  893. (functionp 12) \EV \term{false}
  894. (functionp '(lambda (x) (* x x))) \EV \term{false}
  895. (functionp #'(lambda (x) (* x x))) \EV \term{true}
  896. \endcode
  897. \label Side Effects:\None.
  898. \label Affected By:\None.
  899. \label Exceptional Situations:\None!
  900. \label See Also:\None.
  901. \label Notes::
  902. \code
  903. (functionp \param{object}) \EQ (typep \param{object} 'function)
  904. \endcode
  905. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  906. \endcom
  907. %%% ========== COMPILED-FUNCTION-P
  908. \begincom{compiled-function-p}\ftype{Function}
  909. \label Syntax::
  910. \DefunWithValues compiled-function-p {object} {generalized-boolean}
  911. \label Arguments and Values::
  912. \param{object}---an \term{object}.
  913. \param{generalized-boolean}---a \term{generalized boolean}.
  914. \label Description::
  915. %% 6.2.2 28
  916. \TypePredicate{object}{compiled-function}
  917. \label Examples::
  918. \code
  919. (defun f (x) x) \EV F
  920. (compiled-function-p #'f)
  921. \EV \term{false}
  922. \OV \term{true}
  923. (compiled-function-p 'f) \EV \term{false}
  924. (compile 'f) \EV F
  925. (compiled-function-p #'f) \EV \term{true}
  926. (compiled-function-p 'f) \EV \term{false}
  927. (compiled-function-p (compile nil '(lambda (x) x)))
  928. \EV \term{true}
  929. (compiled-function-p #'(lambda (x) x))
  930. \EV \term{false}
  931. \OV \term{true}
  932. (compiled-function-p '(lambda (x) x)) \EV \term{false}
  933. \endcode
  934. \label Side Effects:\None.
  935. \label Affected By:\None.
  936. \label Exceptional Situations:\None!
  937. \label See Also::
  938. \funref{compile},
  939. \funref{compile-file},
  940. \funref{compiled-function}
  941. \label Notes::
  942. \code
  943. (compiled-function-p \param{object}) \EQ (typep \param{object} 'compiled-function)
  944. \endcode
  945. \endcom
  946. %%% ========== CALL-ARGUMENTS-LIMIT
  947. \begincom{call-arguments-limit}\ftype{Constant Variable}
  948. \label Constant Value::
  949. An integer not smaller than \f{50} and at least as great as
  950. the \term{value} of \conref{lambda-parameters-limit},
  951. the exact magnitude of which is \term{implementation-dependent}.
  952. \label Description::
  953. %% 7.3.0 7
  954. The upper exclusive bound on the number of \term{arguments} that
  955. may be passed to a \term{function}.
  956. \label Examples:\None.
  957. \label See Also::
  958. \conref{lambda-parameters-limit}, \conref{multiple-values-limit}
  959. \label Notes:\None.
  960. \endcom
  961. %%% ========== LAMBDA-LIST-KEYWORDS
  962. \begincom{lambda-list-keywords}\ftype{Constant Variable}
  963. \label Constant Value::
  964. a \term{list}, the \term{elements} of which are \term{implementation-dependent},
  965. but which must contain at least the \term{symbols}
  966. \keyref{allow-other-keys},
  967. \keyref{aux},
  968. \keyref{body},
  969. \keyref{environment},
  970. \keyref{key},
  971. \keyref{optional},
  972. \keyref{rest},
  973. and
  974. \keyref{whole}.
  975. \label Description::
  976. %% 5.2.2 27
  977. A \term{list} of all the \term{lambda list keywords} used
  978. in the \term{implementation}, including the additional ones
  979. used only by \term{macro} definition \term{forms}.
  980. \label Examples:\None.
  981. \label See Also::
  982. \macref{defun},
  983. \specref{flet},
  984. \macref{defmacro},
  985. \specref{macrolet},
  986. {\secref\EvaluationModel}
  987. \label Notes:\None.
  988. \endcom
  989. %%% ========== LAMBDA-PARAMETERS-LIMIT
  990. \begincom{lambda-parameters-limit}\ftype{Constant Variable}
  991. \label Constant Value::
  992. \term{implementation-dependent}, but not smaller than \f{50}.
  993. \label Description::
  994. %% 5.2.2 29
  995. A positive \term{integer} that is the upper exclusive bound on
  996. the number of \term{parameter} \term{names} that can appear
  997. in a single \term{lambda list}.
  998. \label Examples:\None.
  999. \label See Also::
  1000. \conref{call-arguments-limit}
  1001. \label Notes::
  1002. Implementors are encouraged to make the \term{value} of
  1003. \conref{lambda-parameters-limit} as large as possible.
  1004. \endcom
  1005. %-------------------- Variables --------------------
  1006. %%% ========== DEFCONSTANT
  1007. \begincom{defconstant}\ftype{Macro}
  1008. \label Syntax::
  1009. %% 5.3.2 14
  1010. \DefmacWithValues defconstant {name initial-value \brac{documentation}} {name}
  1011. \label Arguments and Values::
  1012. \param{name}---a \term{symbol}; \noeval.
  1013. \param{initial-value}---a \term{form}; \eval.
  1014. %% 5.3.2 10
  1015. \issue{DEFVAR-DOCUMENTATION:UNEVALUATED}
  1016. \param{documentation}---a \term{string}; \noeval.
  1017. \endissue{DEFVAR-DOCUMENTATION:UNEVALUATED}
  1018. \label Description::
  1019. %% 5.3.2 7
  1020. \macref{defconstant}
  1021. %!!! KMP: Maybe use "establishes" here somewhere?
  1022. causes the global variable named by \param{name} to be
  1023. given a value that is the result of evaluating \param{initial-value}.
  1024. %Once \param{name} has been defined using \macref{defconstant}, its value
  1025. %is constant and cannot be changed by assignment or \term{binding}.
  1026. %% 5.1.2 6
  1027. A constant defined by \macref{defconstant} can be redefined
  1028. with \macref{defconstant}.
  1029. %This sentence added per Barmar: -kmp 28-Dec-90
  1030. However, the consequences are undefined if an attempt is made to assign
  1031. a \term{value} to the \term{symbol} using another operator, or to
  1032. assign it to a \term{different}
  1033. %%I gave different a formal meaning the same as non-EQL. -kmp 1-Jan-91
  1034. % (non-\funref{eql})
  1035. \term{value} using a subsequent
  1036. \macref{defconstant}.
  1037. If \param{documentation} is supplied, it is attached to \param{name} as a
  1038. \term{documentation string} of kind \misc{variable}.
  1039. \issue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  1040. \macref{defconstant}
  1041. normally appears as a \term{top level form}, but it is meaningful
  1042. for it to appear as a \term{non-top-level form}.
  1043. However, the compile-time side
  1044. effects described below
  1045. only take place when \macref{defconstant} appears as a
  1046. \term{top level form}.
  1047. \endissue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  1048. %% 5.3.2 8
  1049. The consequences are undefined if there are any
  1050. \term{bindings}
  1051. of the variable named by \param{name} at the time \macref{defconstant}
  1052. is executed or if the value is not \funref{eql} to the value of
  1053. \param{initial-value}.
  1054. %%% 5.3.2 9
  1055. %Once \param{name} has been declared by \macref{defconstant} to be constant,
  1056. %the consequences are undefined if any further assignment to or \term{binding}
  1057. %of \param{name} is attempted.
  1058. \issue{DEFCONSTANT-SPECIAL:NO}
  1059. The consequences are undefined when constant \term{symbols} are rebound
  1060. as either lexical or dynamic variables. In other words, a reference to a
  1061. \term{symbol} declared with \macref{defconstant} always refers to its global value.
  1062. \endissue{DEFCONSTANT-SPECIAL:NO}
  1063. The side effects of the execution of \macref{defconstant} must
  1064. be equivalent to at least the side effects of the execution of the following
  1065. code:
  1066. % We explicitly addressed the question of whether DEFCONSTANT must
  1067. % proclaim the variable SPECIAL in issue DEFCONSTANT-SPECIAL; the final
  1068. % decision was that it might or might not. Including such a proclamation
  1069. % here as required behavior is incorrect. --sjl 5 Mar 92
  1070. % \code
  1071. % (declaim (special \i{name}))
  1072. % (setf (symbol-value '\i{name}) \i{initial-value})
  1073. % (setf (documentation '\i{name} 'variable) '\i{documentation})
  1074. % \endcode
  1075. \code
  1076. (setf (symbol-value '\i{name}) \i{initial-value})
  1077. (setf (documentation '\i{name} 'variable) '\i{documentation})
  1078. \endcode
  1079. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1080. % added qualification about top-level-ness --sjl 5 Mar 92
  1081. If a \macref{defconstant} \term{form} appears as a \term{top level form},
  1082. the \term{compiler} must recognize that \param{name} names
  1083. a \term{constant variable}. An implementation may choose to
  1084. evaluate the value-form at compile time, load time, or both.
  1085. Therefore, users must ensure that the \param{initial-value}
  1086. can be \term{evaluated} at compile time
  1087. (regardless of whether or not references to \param{name}
  1088. appear in the file) and that it always \term{evaluates}
  1089. to the same value.
  1090. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1091. \editornote{KMP: Does ``same value'' here mean eql or similar?}
  1092. \reviewer{Moon: Probably depends on whether load time is compared to compile time,
  1093. or two compiles.}
  1094. % Removed redundant text. --sjl 5 Mar 92
  1095. % Names of \term{constant variables} defined by \macref{defconstant}
  1096. % become reserved and may not be further assigned to or bound (although
  1097. % they may be redefined by using \macref{defconstant}).
  1098. \label Examples::
  1099. \code
  1100. (defconstant this-is-a-constant 'never-changing "for a test") \EV THIS-IS-A-CONSTANT
  1101. this-is-a-constant \EV NEVER-CHANGING
  1102. (documentation 'this-is-a-constant 'variable) \EV "for a test"
  1103. (constantp 'this-is-a-constant) \EV \term{true}
  1104. \endcode
  1105. \label Affected By:\None.
  1106. \label Exceptional Situations:\None.
  1107. \label See Also::
  1108. \funref{declaim},
  1109. \macref{defparameter},
  1110. \macref{defvar},
  1111. \funref{documentation},
  1112. \funref{proclaim},
  1113. {\secref\ConstantVars},
  1114. {\secref\Compilation}
  1115. \label Notes:\None.
  1116. \endcom
  1117. %%% ========== DEFVAR
  1118. %%% ========== DEFPARAMETER
  1119. \begincom{defparameter, defvar}\ftype{Macro}
  1120. \label Syntax::
  1121. \DefmacWithValues defparameter {name initial-value \brac{documentation} } {name}
  1122. \DefmacWithValues defvar {name \ttbrac{initial-value \brac{documentation}}} {name}
  1123. \label Arguments and Values::
  1124. \param{name}---a \term{symbol}; \noeval.
  1125. \issue{DEFVAR-INIT-TIME:NOT-DELAYED}
  1126. % I believe that the confusing wording of CLtL about evaluation has been avoided here,
  1127. % so there is no explicit wording to support the intent of this proposal.
  1128. \endissue{DEFVAR-INIT-TIME:NOT-DELAYED}
  1129. \param{initial-value}---a \term{form};
  1130. for \macref{defparameter}, it is always \term{evaluated},
  1131. but for \macref{defvar} it is \term{evaluated}
  1132. only if \param{name} is not already \term{bound}.
  1133. \issue{DEFVAR-DOCUMENTATION:UNEVALUATED}
  1134. \param{documentation}---a \param{string}; \noeval.
  1135. \endissue{DEFVAR-DOCUMENTATION:UNEVALUATED}
  1136. \label Description::
  1137. %% 5.3.2 2
  1138. %% 5.3.2 4
  1139. \macref{defparameter} and \macref{defvar} \term{establish} \param{name}
  1140. as a \term{dynamic variable}.
  1141. \macref{defparameter} unconditionally
  1142. \term{assigns} the \param{initial-value} to the \term{dynamic variable} named \param{name}.
  1143. \macref{defvar}, by contrast, \term{assigns} \param{initial-value} (if supplied)
  1144. to the \term{dynamic variable} named \param{name}
  1145. only if \param{name} is not already \term{bound}.
  1146. \issue{DEFVAR-INITIALIZATION:CONSERVATIVE}
  1147. If no \param{initial-value} is supplied,
  1148. \macref{defvar} leaves the \term{value cell} of
  1149. the \term{dynamic variable} named \param{name} undisturbed;
  1150. if \param{name} was previously \term{bound}, its old \term{value} persists,
  1151. and if it was previously \term{unbound}, it remains \term{unbound}.
  1152. \endissue{DEFVAR-INITIALIZATION:CONSERVATIVE}
  1153. If \param{documentation} is supplied, it is attached to \param{name} as a
  1154. \term{documentation string} of kind \misc{variable}.
  1155. \issue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  1156. \macref{defparameter} and \macref{defvar} normally appear as a \term{top level form},
  1157. but it is meaningful for them to appear as \term{non-top-level forms}. However,
  1158. the compile-time side effects described below only take place when
  1159. they appear as \term{top level forms}.
  1160. \endissue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  1161. \label Examples::
  1162. \code
  1163. (defparameter *p* 1) \EV *P*
  1164. *p* \EV 1
  1165. (constantp '*p*) \EV \term{false}
  1166. (setq *p* 2) \EV 2
  1167. (defparameter *p* 3) \EV *P*
  1168. *p* \EV 3
  1169. (defvar *v* 1) \EV *V*
  1170. *v* \EV 1
  1171. (constantp '*v*) \EV \term{false}
  1172. (setq *v* 2) \EV 2
  1173. (defvar *v* 3) \EV *V*
  1174. *v* \EV 2
  1175. (defun foo ()
  1176. (let ((*p* 'p) (*v* 'v))
  1177. (bar))) \EV FOO
  1178. (defun bar () (list *p* *v*)) \EV BAR
  1179. (foo) \EV (P V)
  1180. \endcode
  1181. The principal operational distinction between \macref{defparameter} and \macref{defvar}
  1182. is that \macref{defparameter} makes an unconditional assignment to \param{name},
  1183. while \macref{defvar} makes a conditional one. In practice, this means that
  1184. \macref{defparameter} is useful in situations where loading or reloading the definition
  1185. would want to pick up a new value of the variable, while \macref{defvar} is used in
  1186. situations where the old value would want to be retained if the file were loaded or reloaded.
  1187. For example, one might create a file which contained:
  1188. \code
  1189. (defvar *the-interesting-numbers* '())
  1190. (defmacro define-interesting-number (name n)
  1191. `(progn (defvar ,name ,n)
  1192. (pushnew ,name *the-interesting-numbers*)
  1193. ',name))
  1194. (define-interesting-number *my-height* 168) ;cm
  1195. (define-interesting-number *my-weight* 13) ;stones
  1196. \endcode
  1197. Here the initial value, \f{()}, for the variable \f{*the-interesting-numbers*}
  1198. is just a seed that we are never likely to want to reset to something else
  1199. once something has been grown from it. As such, we have used \macref{defvar}
  1200. to avoid having the \f{*interesting-numbers*} information reset if the file is
  1201. loaded a second time. It is true that the two calls to
  1202. \macref{define-interesting-number} here would be reprocessed, but
  1203. if there were additional calls in another file, they would not be and that
  1204. information would be lost. On the other hand, consider the following code:
  1205. \code
  1206. (defparameter *default-beep-count* 3)
  1207. (defun beep (&optional (n *default-beep-count*))
  1208. (dotimes (i n) (si:%beep 1000. 100000.) (sleep 0.1)))
  1209. \endcode
  1210. Here we could easily imagine editing the code to change the initial value of
  1211. \f{*default-beep-count*}, and then reloading the file to pick up the new value.
  1212. In order to make value updating easy, we have used \macref{defparameter}.
  1213. On the other hand, there is potential value to using \macref{defvar} in this
  1214. situation. For example, suppose that someone had predefined an alternate
  1215. value for \f{*default-beep-count*}, or had loaded the file and then manually
  1216. changed the value. In both cases, if we had used \macref{defvar} instead of
  1217. \macref{defparameter}, those user preferences would not be overridden by
  1218. (re)loading the file.
  1219. The choice of whether to use \macref{defparameter} or \macref{defvar} has
  1220. visible consequences to programs, but is nevertheless often made for subjective
  1221. reasons.
  1222. \label Side Effects::
  1223. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1224. % added qualification about top-level-ness --sjl 5 Mar 92
  1225. If a \macref{defvar} or \macref{defparameter} \term{form} appears as a \term{top level form},
  1226. the \term{compiler} must recognize that the \param{name} has been
  1227. proclaimed \declref{special}. However, it must neither \term{evaluate}
  1228. the \param{initial-value} \term{form} nor \term{assign} the
  1229. \term{dynamic variable} named \param{name} at compile time.
  1230. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1231. There may be additional (\term{implementation-defined}) compile-time or
  1232. run-time side effects, as long as such effects do not interfere with the
  1233. correct operation of \term{conforming programs}.
  1234. \label Affected By::
  1235. \macref{defvar} is affected by whether \param{name} is already \term{bound}.
  1236. \label Exceptional Situations:\None.
  1237. \label See Also::
  1238. \funref{declaim},
  1239. \macref{defconstant},
  1240. \funref{documentation},
  1241. {\secref\Compilation}
  1242. \label Notes::
  1243. It is customary to name \term{dynamic variables} with an \term{asterisk}
  1244. at the beginning and end of the name. e.g., \f{*foo*} is a good name for
  1245. a \term{dynamic variable}, but not for a \term{lexical variable};
  1246. \f{foo} is a good name for a \term{lexical variable},
  1247. but not for a \term{dynamic variable}.
  1248. This naming convention is observed for all \term{defined names} in \clisp;
  1249. however, neither \term{conforming programs} nor \term{conforming implementations}
  1250. are obliged to adhere to this convention.
  1251. The intent of the permission for additional side effects is to allow
  1252. \term{implementations} to do normal ``bookkeeping'' that accompanies
  1253. definitions. For example, the \term{macro expansion} of a \macref{defvar}
  1254. or \macref{defparameter} \term{form} might include code that arranges to
  1255. record the name of the source file in which the definition occurs.
  1256. \macref{defparameter} and \macref{defvar} might be defined as follows:
  1257. \code
  1258. (defmacro defparameter (name initial-value
  1259. &optional (documentation nil documentation-p))
  1260. `(progn (declaim (special ,name))
  1261. (setf (symbol-value ',name) ,initial-value)
  1262. ,(when documentation-p
  1263. `(setf (documentation ',name 'variable) ',documentation))
  1264. ',name))
  1265. (defmacro defvar (name &optional
  1266. (initial-value nil initial-value-p)
  1267. (documentation nil documentation-p))
  1268. `(progn (declaim (special ,name))
  1269. ,(when initial-value-p
  1270. `(unless (boundp ',name)
  1271. (setf (symbol-value ',name) ,initial-value)))
  1272. ,(when documentation-p
  1273. `(setf (documentation ',name 'variable) ',documentation))
  1274. ',name))
  1275. \endcode
  1276. \endcom
  1277. %%% ========== DESTRUCTURING-BIND
  1278. \begincom{destructuring-bind}\ftype{Macro}
  1279. \issue{DECLS-AND-DOC}
  1280. \issue{DESTRUCTURING-BIND:NEW-MACRO}
  1281. \label Syntax::
  1282. \DefmacWithValuesNewline destructuring-bind
  1283. {lambda-list expression \starparam{declaration} \starparam{form}}
  1284. {\starparam{result}}
  1285. \label Arguments and Values::
  1286. %% 8.1.0 9
  1287. %% 8.1.0 10
  1288. %% 8.1.0 11
  1289. %% 8.1.0 12
  1290. % tweaked --sjl 5 Mar 92
  1291. %\param{lambda-list}---a \term{lambda list};
  1292. % can contain the \term{lambda list keywords}
  1293. % \keyref{allow-other-keys},
  1294. % \keyref{aux},
  1295. % \keyref{body},
  1296. % \keyref{key},
  1297. % \keyref{optional},
  1298. % \keyref{rest},
  1299. % and
  1300. % \keyref{whole}.
  1301. \param{lambda-list}---a \term{destructuring lambda list}.
  1302. \param{expression}---a \term{form}.
  1303. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  1304. \param{forms}---an \term{implicit progn}.
  1305. \param{results}---the \term{values} returned by the \term{forms}.
  1306. \label Description::
  1307. \macref{destructuring-bind} binds the variables specified in \param{lambda-list}
  1308. to the corresponding values in the tree structure resulting from the evaluation
  1309. of \param{expression}; then \macref{destructuring-bind} evaluates \param{forms}.
  1310. % All of this text is redundant; a simple cross-reference will do.
  1311. % --sjl 5 Mar 92
  1312. % Anywhere in \param{lambda-list} where a parameter name can appear, and
  1313. % where ordinary \term{lambda list} syntax as described in {\secref\OrdinaryLambdaLists}
  1314. % does not otherwise allow a \term{list}, a \term{lambda list} can appear
  1315. % in place of the parameter name. When this is done, then the portion of
  1316. % the tree structure resulting from the evaluation of \param{expression}
  1317. % that would match the parameter is treated as a tree structure for satisfying
  1318. % the parameters in the embedded \term{lambda list}.
  1319. %
  1320. % If any of the \term{lambda list keywords}
  1321. % \keyref{optional}, \keyref{rest}, \keyref{key}, \keyref{allow-other-keys}
  1322. % and \keyref{aux} appears in \param{lambda-list},
  1323. % it is treated as it would be in an \term{ordinary lambda list}.
  1324. %
  1325. % If the \term{lambda list keyword} \keyref{body} appears,
  1326. % it is treated the same as if \keyref{rest} had appeared.
  1327. % (Only one of \keyref{body} or \keyref{rest} can be used at any one level.)
  1328. %
  1329. % If the \term{lambda list keyword} \keyref{whole} appears,
  1330. % it must be immediately followed by a single variable that is bound
  1331. % to the entire tree at the current level.
  1332. % \keyref{whole} and its following variable should appear first in the list,
  1333. % before any other \term{parameter} or \term{lambda list keyword}.
  1334. %
  1335. % It is also permissible for any level of \param{lambda-list} to be a
  1336. % \term{dotted list}, ending in a parameter name. This situation is
  1337. % treated exactly as if the parameter name that ends the \term{dotted list}
  1338. % had appeared preceded by \keyref{rest} in a \term{proper list}.
  1339. % For example, the notation \f{(x y . z)} is equivalent to \f{(x y \&rest z)}.
  1340. %
  1341. % For \keyref{optional} and \keyref{key} parameters, initialization forms and ``supplied-p''
  1342. % parameters can be supplied, just as for \macref{defun}.
  1343. The \param{lambda-list} supports destructuring as described in
  1344. \secref\DestructuringLambdaLists.
  1345. \label Examples::
  1346. \code
  1347. (defun iota (n) (loop for i from 1 to n collect i)) ;helper
  1348. (destructuring-bind ((a &optional (b 'bee)) one two three)
  1349. `((alpha) ,@(iota 3))
  1350. (list a b three two one)) \EV (ALPHA BEE 3 2 1)
  1351. \endcode
  1352. \label Affected By:\None.
  1353. \label Exceptional Situations::
  1354. If the result of evaluating the \param{expression} does not match the
  1355. destructuring pattern, an error \oftype{error} should be signaled.
  1356. \label See Also::
  1357. \specref{macrolet}, \macref{defmacro}
  1358. \label Notes:\None.
  1359. \endissue{DESTRUCTURING-BIND:NEW-MACRO}
  1360. \endissue{DECLS-AND-DOC}
  1361. \endcom
  1362. %%% ========== LET
  1363. %%% ========== LET*
  1364. \begincom{let, let*}\ftype{Special Operator}
  1365. \issue{DECLS-AND-DOC}
  1366. \label Syntax::
  1367. \issue{VARIABLE-LIST-ASYMMETRY:SYMMETRIZE}
  1368. \DefspecWithValues let
  1369. {\paren{\star{\VarValue}} \starparam{declaration} \starparam{form}}
  1370. {\starparam{result}}
  1371. \DefspecWithValues let*
  1372. {\paren{\star{\VarValue}} \starparam{declaration} \starparam{form}}
  1373. {\starparam{result}}
  1374. \endissue{VARIABLE-LIST-ASYMMETRY:SYMMETRIZE}
  1375. \label Arguments and Values::
  1376. %!!! Barmar thinks this should say "non-constant symbol".
  1377. \param{var}---a \term{symbol}.
  1378. % fixed some confusion about whether this is ``init-form'' or ``value''.
  1379. % --sjl 5 Mar 92
  1380. \param{init-form}---a \term{form}.
  1381. %!!! Barmar asks why "not evaluated" is only specified for this argument.
  1382. %% 7.5.0 6
  1383. %% 7.5.0 10
  1384. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  1385. \param{form}---a \term{form}.
  1386. \param{results}---the \term{values} returned by the \term{forms}.
  1387. \label Description::
  1388. %% 7.5.0 3
  1389. \specref{let} and \specref{let*}
  1390. create new variable \term{bindings} and
  1391. execute a series of \param{forms} that use these \term{bindings}.
  1392. \specref{let} performs the \term{bindings} in parallel and
  1393. \specref{let*} does them sequentially.
  1394. %% 7.5.0 4
  1395. %% 7.5.0 5
  1396. The form
  1397. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1398. \code
  1399. (let ((\param{var1} \param{init-form-1})
  1400. (\param{var2} \param{init-form-2})
  1401. ...
  1402. (\param{varm} \param{init-form-m}))
  1403. \param{declaration1}
  1404. \param{declaration2}
  1405. ...
  1406. \param{declarationp}
  1407. \param{form1}
  1408. \param{form2}
  1409. ...
  1410. \param{formn})
  1411. \endcode
  1412. first evaluates the expressions \param{init-form-1}, \param{init-form-2}, and so on,
  1413. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1414. in that order, saving the resulting values.
  1415. Then all of the variables \param{varj} are bound to the corresponding
  1416. values; each \term{binding} is lexical unless
  1417. there is a \declref{special} declaration to the contrary.
  1418. The expressions \param{formk} are then evaluated
  1419. in order; the values of all but the last are discarded
  1420. (that is, the body of a \specref{let}
  1421. is an \term{implicit progn}).
  1422. %% 7.5.0 7
  1423. %% 7.5.0 9
  1424. \specref{let*}
  1425. is similar to \specref{let}, but the \term{bindings} of variables
  1426. are performed sequentially rather than in parallel.
  1427. The expression for the \param{init-form} of a
  1428. \param{var} can refer to \param{vars}
  1429. previously bound in the \specref{let*}.
  1430. %% 7.5.0 8
  1431. The form
  1432. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1433. \code
  1434. (let* ((\param{var1} \param{init-form-1})
  1435. (\param{var2} \param{init-form-2})
  1436. ...
  1437. (\param{varm} \param{init-form-m}))
  1438. \param{declaration1}
  1439. \param{declaration2}
  1440. ...
  1441. \param{declarationp}
  1442. \param{form1}
  1443. \param{form2}
  1444. ...
  1445. \param{formn})
  1446. \endcode
  1447. first evaluates the expression \param{init-form-1}, then binds the variable
  1448. \param{var1} to that value; then it evaluates \param{init-form-2} and binds
  1449. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1450. \param{var2}, and so on.
  1451. The expressions \param{formj} are then evaluated
  1452. in order; the values of all but the last are discarded
  1453. (that is, the body of \specref{let*} is an implicit \specref{progn}).
  1454. For both \specref{let} and \specref{let*},
  1455. if there is not an \param{init-form} associated with a \param{var},
  1456. \param{var} is initialized to \nil.
  1457. % This is a property of TYPE declarations and doesn't need to
  1458. % be said again here. --sjl 5 Mar 92
  1459. % The consequences are undefined if a type \param{declaration} is supplied for a
  1460. % \param{var} and the initial \param{value} of
  1461. % that \param{var} is not consistent with the type \param{declaration}.
  1462. The special form \specref{let}
  1463. has the property that the \term{scope}
  1464. of the name binding does not include any
  1465. initial value form.
  1466. For \specref{let*}, a variable's \term{scope} also includes the
  1467. remaining initial value forms for subsequent variable bindings.
  1468. %New name bindings take precedence over any
  1469. %higher level binding or declarations. For example,
  1470. %
  1471. %\code
  1472. % (locally (declare (special x) (float y))
  1473. % (let ((x 5) (y 10))
  1474. % (print (+ x y))))
  1475. %\endcode
  1476. %
  1477. %If there are no
  1478. %proclamations are in effect,
  1479. %then {\tt x} is local (not \declref{special})
  1480. %and {\tt y} is bound with no particular
  1481. %type information because the {\tt y} being bound is a different variable
  1482. %from the {\tt y} declared {\tt float}.
  1483. %See \misc{declare}.
  1484. % This is adequately addressed in the packages chapter. --sjl 5 Mar 92
  1485. %\issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  1486. %It is permissible to use symbols in \thepackage{common-lisp} as lexical variable names,
  1487. %provided they are not globally defined as \term{variables}.
  1488. %\endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  1489. \label Examples::
  1490. \code
  1491. (setq a 'top) \EV TOP
  1492. (defun dummy-function () a) \EV DUMMY-FUNCTION
  1493. (let ((a 'inside) (b a))
  1494. (format nil "~S ~S ~S" a b (dummy-function))) \EV "INSIDE TOP TOP"
  1495. (let* ((a 'inside) (b a))
  1496. (format nil "~S ~S ~S" a b (dummy-function))) \EV "INSIDE INSIDE TOP"
  1497. (let ((a 'inside) (b a))
  1498. (declare (special a))
  1499. (format nil "~S ~S ~S" a b (dummy-function))) \EV "INSIDE TOP INSIDE"
  1500. \endcode
  1501. \medbreak
  1502. The code
  1503. \code
  1504. (let (x)
  1505. (declare (integer x))
  1506. (setq x (gcd y z))
  1507. ...)
  1508. \endcode
  1509. is incorrect; although \f{x} is indeed set before it is used,
  1510. and is set to a value of the declared type \term{integer}, nevertheless
  1511. \f{x} initially takes on the value \nil\ in violation of the type
  1512. declaration.
  1513. \label Affected By:\None.
  1514. \label Exceptional Situations:\None.
  1515. \label See Also::
  1516. \specref{progv}
  1517. \label Notes:\None.
  1518. \endissue{DECLS-AND-DOC}
  1519. \endcom
  1520. %%% ========== PROGV
  1521. \begincom{progv}\ftype{Special Operator}
  1522. \label Syntax::
  1523. \DefspecWithValues progv
  1524. {\param{symbols} \param{values} \starparam{form}}
  1525. {\starparam{result}}
  1526. \label Arguments and Values::
  1527. %!!! Barmar thinks this should say "non-constant symbols"
  1528. \param{symbols}---a \term{list} of \term{symbols}; \eval.
  1529. \param{values}---a \term{list} of \term{objects}; \eval.
  1530. \param{forms}---an \term{implicit progn}.
  1531. \param{results}---the \term{values} returned by the \term{forms}.
  1532. \label Description::
  1533. \specref{progv} creates new dynamic variable \term{bindings} and
  1534. executes each \param{form} using those \term{bindings}.
  1535. Each \param{form} is evaluated in order.
  1536. %% 7.5.0 14
  1537. \specref{progv} allows \term{binding} one or more dynamic
  1538. variables whose names may be determined at run time.
  1539. Each \param{form} is evaluated in order
  1540. with the dynamic variables whose names are in
  1541. \param{symbols} bound to corresponding \param{values}.
  1542. If too few \param{values}
  1543. are supplied, the remaining \term{symbols} are bound and then
  1544. made to have no value. If too many \param{values} are
  1545. supplied, the excess values are ignored.
  1546. The \term{bindings} of the dynamic variables are undone on
  1547. exit from \specref{progv}.
  1548. \label Examples::
  1549. \code
  1550. (setq *x* 1) \EV 1
  1551. (progv '(*x*) '(2) *x*) \EV 2
  1552. *x* \EV 1
  1553. Assuming *x* is not globally special,
  1554. (let ((*x* 3))
  1555. (progv '(*x*) '(4)
  1556. (list *x* (symbol-value '*x*)))) \EV (3 4)
  1557. \endcode
  1558. \label Affected By:\None.
  1559. \label Exceptional Situations:\None.
  1560. \label See Also::
  1561. \specref{let}, {\secref\Evaluation}
  1562. \label Notes::
  1563. %% 7.5.0 16
  1564. Among other things, \specref{progv} is useful when writing
  1565. interpreters for languages embedded in \Lisp; it provides a handle
  1566. on the mechanism for \term{binding} \term{dynamic variables}.
  1567. \endcom
  1568. %%% ========== SETQ
  1569. \begincom{setq}\ftype{Special Form}
  1570. \label Syntax::
  1571. \DefspecWithValues setq {\stardown{pair}} {result}
  1572. \auxbnf{pair}{var form}
  1573. \label Pronunciation::
  1574. \pronounced{\Stress{set}\stress{ky\"u}}
  1575. \label Arguments and Values::
  1576. %!!! Perhaps there should be a glossary term which makes this more convenient to say.
  1577. \param{var}---a \term{symbol} naming a \term{variable} other than a \term{constant variable}.
  1578. \param{form}---a \term{form}.
  1579. %% 7.1.2 4
  1580. \param{result}---the \term{primary value} of the last \param{form},
  1581. or \nil\ if no \param{pairs} were supplied.
  1582. \label Description::
  1583. Assigns values to \term{variables}.
  1584. %% 7.1.2 3
  1585. \f{(setq \i{var1} \i{form1} \i{var2} \i{form2} ...)}
  1586. is the simple variable assignment statement of \Lisp.
  1587. First \param{form1} is evaluated
  1588. and the result is stored in the variable \param{var1}, then \param{form2}
  1589. is evaluated and the result stored in \param{var2}, and so forth.
  1590. \specref{setq} may be used for assignment of both lexical
  1591. and dynamic variables.
  1592. \issue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1593. If any \param{var} refers to a \term{binding}
  1594. made by \specref{symbol-macrolet},
  1595. then that \param{var} is treated as if \macref{setf}
  1596. (not \specref{setq}) had been used.
  1597. \endissue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1598. \label Examples::
  1599. \code
  1600. ;; A simple use of SETQ to establish values for variables.
  1601. (setq a 1 b 2 c 3) \EV 3
  1602. a \EV 1
  1603. b \EV 2
  1604. c \EV 3
  1605. ;; Use of SETQ to update values by sequential assignment.
  1606. (setq a (1+ b) b (1+ a) c (+ a b)) \EV 7
  1607. a \EV 3
  1608. b \EV 4
  1609. c \EV 7
  1610. ;; This illustrates the use of SETQ on a symbol macro.
  1611. (let ((x (list 10 20 30)))
  1612. (symbol-macrolet ((y (car x)) (z (cadr x)))
  1613. (setq y (1+ z) z (1+ y))
  1614. (list x y z)))
  1615. \EV ((21 22 30) 21 22)
  1616. \endcode
  1617. \label Side Effects::
  1618. The \term{primary value} of each \param{form} is assigned to the corresponding \param{var}.
  1619. \label Affected By:\None.
  1620. \label Exceptional Situations:\None.
  1621. \label See Also::
  1622. \macref{psetq},
  1623. \funref{set},
  1624. \macref{setf}
  1625. \label Notes:\None.
  1626. \endcom
  1627. %%% ========== PSETQ
  1628. \begincom{psetq}\ftype{Macro}
  1629. \label Syntax::
  1630. \DefmacWithValues psetq {\stardown{pair}} {\nil}
  1631. \auxbnf{pair}{var form}
  1632. \label Pronunciation::
  1633. \macref{psetq}: \pronounced{\maybeStress{p\harde}\Stress{set}\stress{ky\"u}}
  1634. \label Arguments and Values::
  1635. %!!! Perhaps there should be a glossary term which makes this more convenient to say.
  1636. \param{var}---a \term{symbol} naming a \term{variable} other than a \term{constant variable}.
  1637. \param{form}---a \term{form}.
  1638. \label Description::
  1639. Assigns values to \term{variables}.
  1640. This is just like \specref{setq}, except that the assignments
  1641. happen ``in parallel.'' That is, first all of the forms are
  1642. evaluated, and only then are the variables set to the resulting values.
  1643. In this way, the assignment to one variable does not affect the value
  1644. computation of another in the way that would occur with \specref{setq}'s
  1645. sequential assignment.
  1646. \issue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1647. If any \param{var} refers to a \term{binding}
  1648. made by \specref{symbol-macrolet},
  1649. then that \param{var} is treated as if \macref{psetf} (not \macref{psetq})
  1650. had been used.
  1651. \endissue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1652. \label Examples::
  1653. \code
  1654. ;; A simple use of PSETQ to establish values for variables.
  1655. ;; As a matter of style, many programmers would prefer SETQ
  1656. ;; in a simple situation like this where parallel assignment
  1657. ;; is not needed, but the two have equivalent effect.
  1658. (psetq a 1 b 2 c 3) \EV NIL
  1659. a \EV 1
  1660. b \EV 2
  1661. c \EV 3
  1662. ;; Use of PSETQ to update values by parallel assignment.
  1663. ;; The effect here is very different than if SETQ had been used.
  1664. (psetq a (1+ b) b (1+ a) c (+ a b)) \EV NIL
  1665. a \EV 3
  1666. b \EV 2
  1667. c \EV 3
  1668. ;; Use of PSETQ on a symbol macro.
  1669. (let ((x (list 10 20 30)))
  1670. (symbol-macrolet ((y (car x)) (z (cadr x)))
  1671. (psetq y (1+ z) z (1+ y))
  1672. (list x y z)))
  1673. \EV ((21 11 30) 21 11)
  1674. ;; Use of parallel assignment to swap values of A and B.
  1675. (let ((a 1) (b 2))
  1676. (psetq a b b a)
  1677. (values a b))
  1678. \EV 2, 1
  1679. \endcode
  1680. \label Side Effects::
  1681. The values of \param{forms} are assigned to \param{vars}.
  1682. \label Affected By:\None.
  1683. \label Exceptional Situations:\None.
  1684. \label See Also::
  1685. \macref{psetf},
  1686. \specref{setq}
  1687. \label Notes:\None.
  1688. \endcom
  1689. % I moved the dictionary entry for the SPECIAL declaration to chapter 3,
  1690. % to live with all the other declaration specifiers. --sjl 5 Mar 92
  1691. %-------------------- Control Transfer --------------------
  1692. %%% ========== BLOCK
  1693. \begincom{block}\ftype{Special Operator}
  1694. \label Syntax::
  1695. \DefspecWithValues block {\param{name} \star{\param{form}}} {\starparam{result}}
  1696. \label Arguments and Values::
  1697. %% 7.7.0 3
  1698. \param{name}---a \term{symbol}.
  1699. \param{form}---a \term{form}.
  1700. %% 7.9.2 11
  1701. %% 7.9.2 12
  1702. \param{results}---the \term{values} of the \term{forms} if a \term{normal return} occurs,
  1703. or else, if an \term{explicit return} occurs, the \term{values} that were transferred.
  1704. \label Description::
  1705. %% 7.7.0 2
  1706. \specref{block} \term{establishes} a \term{block} named \param{name}
  1707. and then evaluates \param{forms} as an \term{implicit progn}.
  1708. % If a \macref{return} or \specref{return-from} that specifies
  1709. % \param{name} is executed during the execution of some \param{form}, then
  1710. % the results specified by the \macref{return} or \specref{return-from}
  1711. % are immediately returned as the value of \specref{block},
  1712. % and execution proceeds as if the \specref{block} had terminated
  1713. % normally. Only a \macref{return} or \specref{return-from}
  1714. % textually contained in some \param{form} can exit from the \specref{block}.
  1715. The \term{special operators} \specref{block} and \specref{return-from} work together to
  1716. provide a structured, lexical, non-local exit facility. At any point lexically
  1717. contained within \term{forms}, \specref{return-from} can be used with the
  1718. given \param{name} to return control and values from the \specref{block}
  1719. \term{form}, except when an intervening \term{block} with the same name
  1720. has been \term{established}, in which case the outer \term{block} is
  1721. shadowed by the inner one.
  1722. The \term{block} named \term{name} has
  1723. \term{lexical scope} and \term{dynamic extent}.
  1724. % It is only possible to exit from a given run-time incarnation of a
  1725. % \specref{block} once, either normally or by explicit return.
  1726. Once established, a \term{block} may only be exited once,
  1727. whether by \term{normal return} or \term{explicit return}.
  1728. %%Barmar didn't think the following was really essential. I agree. -kmp 21-Dec-90
  1729. %
  1730. %% 7.7.0 6
  1731. % The fact that \param{name} is lexical
  1732. % has consequences that might be surprising
  1733. % to users and implementors.
  1734. % For example:
  1735. %
  1736. % \code
  1737. % (block loser
  1738. % (catch 'stuff
  1739. % (mapcar #'(lambda (x) (if (numberp x)
  1740. % (hairyfun x)
  1741. % (return-from loser \nil)))
  1742. % items)))
  1743. % \endcode
  1744. %
  1745. % A \macref{return} can break up catchers if necessary to get
  1746. % to the block in question.
  1747. % It is possible for a \term{closure} created by \specref{function} for
  1748. % a \term{lambda expression} to refer to a \specref{block}
  1749. % name as long as the name
  1750. % is lexically apparent.
  1751. \label Examples::
  1752. \code
  1753. (block empty) \EV NIL
  1754. (block whocares (values 1 2) (values 3 4)) \EV 3, 4
  1755. (let ((x 1))
  1756. (block stop (setq x 2) (return-from stop) (setq x 3))
  1757. x) \EV 2
  1758. (block early (return-from early (values 1 2)) (values 3 4)) \EV 1, 2
  1759. (block outer (block inner (return-from outer 1)) 2) \EV 1
  1760. (block twin (block twin (return-from twin 1)) 2) \EV 2
  1761. ;; Contrast behavior of this example with corresponding example of CATCH.
  1762. (block b
  1763. (flet ((b1 () (return-from b 1)))
  1764. (block b (b1) (print 'unreachable))
  1765. 2)) \EV 1
  1766. \endcode
  1767. \label Affected By:\None.
  1768. \label Exceptional Situations:\None.
  1769. \label See Also::
  1770. \macref{return}, \specref{return-from}, {\secref\Evaluation}
  1771. \label Notes::
  1772. %%This seems random to me. -kmp
  1773. % \specref{block} differs from \specref{progn} in that \specref{progn}
  1774. % has nothing to do with \macref{return}.
  1775. \endcom
  1776. %%% ========== CATCH
  1777. \begincom{catch}\ftype{Special Operator}
  1778. \label Syntax::
  1779. \DefspecWithValues catch
  1780. {\param{tag} \starparam{form}}
  1781. {\starparam{result}}
  1782. \label Arguments and Values::
  1783. %% 7.10.0 3
  1784. \param{tag}---a \term{catch tag}; \eval.
  1785. \param{forms}---an \term{implicit progn}.
  1786. \param{results}---if the \param{forms} exit normally,
  1787. the \term{values} returned by the \param{forms};
  1788. if a throw occurs to the \param{tag},
  1789. the \term{values} that are thrown.
  1790. \label Description::
  1791. %!!!
  1792. % Barmar: Tags are compared using EQ, not EQL. Therefore, the consequences
  1793. % of using numbers and characters as tags are unspecified.
  1794. % KMP: Personally, I think we should fix that to simplify the language
  1795. % description. I don't approve of our using EQ anywhere in the spec.
  1796. %% 7.10.0 2
  1797. \specref{catch} is used as the destination of a non-local
  1798. control transfer by \specref{throw}.
  1799. \param{Tags} are used to find the \specref{catch}
  1800. to which a \specref{throw} is transferring control.
  1801. \f{(catch 'foo \i{form})} catches a
  1802. \f{(throw 'foo \i{form})} but not a
  1803. \f{(throw 'bar \i{form})}.
  1804. %% 7.10.0 4
  1805. The order of execution of \specref{catch} follows:\idxtext{order of evaluation}\idxtext{evaluation order}
  1806. \beginlist
  1807. \itemitem{1.} \param{Tag} is evaluated.
  1808. It serves as the name of the
  1809. \specref{catch}.
  1810. \itemitem{2.} \param{Forms} are then evaluated as an implicit \specref{progn},
  1811. and the results of the last \param{form} are returned unless a
  1812. \specref{throw} occurs.
  1813. \itemitem{3.} If a \specref{throw} occurs
  1814. during the execution of one of the \param{forms}, control
  1815. is transferred to the \specref{catch} \term{form} whose \param{tag}
  1816. is \funref{eq} to
  1817. the tag argument of the \specref{throw}
  1818. and which is the most recently established \specref{catch} with that
  1819. \param{tag}.
  1820. %The evaluation of \param{forms} is aborted.
  1821. No further evaluation of \param{forms} occurs.
  1822. %%Barmar thinks this is not redundant. I agree. -kmp 22-Dec-90
  1823. % If several tags match the tag
  1824. % argument of a \specref{throw},
  1825. % control is transferred to the dynamically most recently established
  1826. % \specref{catch}.
  1827. \itemitem{4.} The \param{tag} \term{established}
  1828. by \specref{catch} is \term{disestablished}
  1829. just before the results are returned.
  1830. \endlist
  1831. %% 7.9.2 14
  1832. %% 7.9.2 15
  1833. %% gray's rewording
  1834. If during the execution of one of the \param{forms}, a \specref{throw}
  1835. is executed whose tag is \funref{eq} to the \specref{catch} tag,
  1836. then the values specified by the \specref{throw} are
  1837. returned as the result of the dynamically most recently established
  1838. \specref{catch} form with that tag.
  1839. % If a \specref{throw} occurs
  1840. %during the execution of one of the \param{forms},
  1841. %and there is a \specref{catch} \param{tag} that is
  1842. %\funref{eq} to the \specref{throw} tag,
  1843. %the value or values resulting from
  1844. %the \specref{throw} are returned.
  1845. The mechanism for \specref{catch} and \specref{throw} works even
  1846. if \specref{throw} is not within the lexical scope of \specref{catch}.
  1847. \specref{throw} must occur within the \term{dynamic extent}
  1848. of the \term{evaluation} of the body of a \specref{catch} with a corresponding \param{tag}.
  1849. \label Examples::
  1850. \code
  1851. (catch 'dummy-tag 1 2 (throw 'dummy-tag 3) 4) \EV 3
  1852. (catch 'dummy-tag 1 2 3 4) \EV 4
  1853. (defun throw-back (tag) (throw tag t)) \EV THROW-BACK
  1854. (catch 'dummy-tag (throw-back 'dummy-tag) 2) \EV T
  1855. ;; Contrast behavior of this example with corresponding example of BLOCK.
  1856. (catch 'c
  1857. (flet ((c1 () (throw 'c 1)))
  1858. (catch 'c (c1) (print 'unreachable))
  1859. 2)) \EV 2
  1860. \endcode
  1861. \label Affected By:\None.
  1862. \label Exceptional Situations::
  1863. An error \oftype{control-error} is signaled
  1864. if \specref{throw} is done
  1865. when there is no suitable \specref{catch} \param{tag}.
  1866. \label See Also::
  1867. \specref{throw}, {\secref\Evaluation}
  1868. \label Notes::
  1869. It is customary for \term{symbols} to be used
  1870. as \param{tags}, but any \term{object} is permitted.
  1871. However, numbers should not be
  1872. used because the comparison is done using \funref{eq}.
  1873. \specref{catch} differs from \specref{block} in that
  1874. \specref{catch}
  1875. tags have dynamic \term{scope} while
  1876. \specref{block} names have \term{lexical scope}.
  1877. \endcom
  1878. %%% ========== GO
  1879. \begincom{go}\ftype{Special Operator}
  1880. \label Syntax::
  1881. %% 7.8.5 17
  1882. \DefspecNoReturn go {tag}
  1883. \label Arguments and Values::
  1884. \param{tag}---a \term{go tag}.
  1885. % a \term{symbol} or an \term{integer}.
  1886. \label Description::
  1887. %% 7.8.5 16
  1888. \specref{go} transfers control to the point in the body
  1889. of an enclosing \specref{tagbody} form labeled by a
  1890. tag \funref{eql} to \param{tag}.
  1891. %!!! Barmar: Which TAGBODY forms was the first sentence talking about??
  1892. % GO only examines lexically containing forms.
  1893. If there is no such \param{tag} in the body, the
  1894. bodies of lexically containing \specref{tagbody} \term{forms}
  1895. (if any) are examined as well.
  1896. If several tags are \funref{eql}
  1897. to \param{tag}, control is transferred to
  1898. whichever matching \param{tag}
  1899. is contained in the innermost \specref{tagbody} form that
  1900. contains the \specref{go}.
  1901. The consequences are undefined
  1902. if there is no matching \param{tag} lexically visible
  1903. to the point of the \specref{go}.
  1904. % This is all said in a concept section now. --sjl 7 Mar 92
  1905. %\issue{EXIT-EXTENT:MINIMAL}
  1906. %When a transfer of control is initiated by \specref{go},
  1907. %the following events occur in order to accomplish the transfer of control.
  1908. %Note that for \specref{go},
  1909. %the \term{exit point} is the \term{form} within the \specref{tagbody}
  1910. %that is being executed at the time the \specref{go} is performed.
  1911. %\beginlist
  1912. %\itemitem{1.}
  1913. % Intervening \term{exit points} are ``abandoned''
  1914. % (\ie their \term{extent} ends
  1915. % and it is no longer valid to attempt to transfer control through them).
  1916. %
  1917. %\itemitem{2.}
  1918. % The cleanup clauses of any intervening \specref{unwind-protect} clauses
  1919. % are evaluated.
  1920. %
  1921. %\itemitem{3.}
  1922. % Intervening dynamic \term{bindings} of \declref{special} variables and
  1923. % \term{catch tags} are undone.
  1924. %
  1925. %\itemitem{4.}
  1926. % The \term{extent} of the \term{exit point} being invoked ends,
  1927. % and control is passed to the target.
  1928. %\endlist
  1929. %
  1930. %The extent of an exit being ``abandoned'' because it is being passed over
  1931. %ends as soon as the transfer of control is initiated. That is,
  1932. %event 1 occurs at the beginning of the initiation of the transfer of
  1933. %control.
  1934. %The consequences are undefined if an attempt is made to transfer control
  1935. %to an \term{exit point} whose \term{dynamic extent} has ended.
  1936. %
  1937. %%Moon had me add the part about "interleaved" -kmp 13-Feb-92
  1938. %Events 2 and 3 are actually performed interleaved, in the order
  1939. %corresponding to the reverse order in which they were established.
  1940. %The effect of this is that the cleanup clauses of an \specref{unwind-protect}
  1941. %sees the same dynamic \term{bindings}
  1942. %of variables and \term{catch tags} as were
  1943. %visible when the \specref{unwind-protect} was entered.
  1944. %
  1945. %Event 4 occurs at the end of the transfer of control.
  1946. %
  1947. %\endissue{EXIT-EXTENT:MINIMAL}
  1948. The transfer of control initiated by \specref{go} is performed
  1949. as described in \secref\TransferOfControl.
  1950. \label Examples::
  1951. \code
  1952. (tagbody
  1953. (setq val 2)
  1954. (go lp)
  1955. (incf val 3)
  1956. lp (incf val 4)) \EV NIL
  1957. val \EV 6
  1958. \endcode
  1959. \issue{EXIT-EXTENT:MINIMAL}
  1960. The following is in error because there is a normal exit
  1961. of the \specref{tagbody} before the
  1962. \specref{go} is executed.
  1963. \code
  1964. (let ((a nil))
  1965. (tagbody t (setq a #'(lambda () (go t))))
  1966. (funcall a))
  1967. \endcode
  1968. The following is in error because the \specref{tagbody} is passed over
  1969. before the \specref{go} \term{form} is executed.
  1970. \code
  1971. (funcall (block nil
  1972. (tagbody a (return #'(lambda () (go a))))))
  1973. \endcode
  1974. \endissue{EXIT-EXTENT:MINIMAL}
  1975. \label Affected By:\None.
  1976. \label Exceptional Situations:\None.
  1977. \label See Also::
  1978. \specref{tagbody}
  1979. \label Notes:\None.
  1980. %% Moon: Is this just here to confuse people?
  1981. % \issue{EXIT-EXTENT:MINIMAL}
  1982. %
  1983. % Implementations can support longer \term{extents} for
  1984. % \term{exit points} than is
  1985. % required here; in particular, an implementation may be extended to
  1986. % allow a larger extent as follows:
  1987. %
  1988. % Events of 1, 2, 3, and 4 are interwoven in the reverse
  1989. % order in which they were established. In particular, the \term{extent} of
  1990. % a passed-over \term{exit point} ends when control reaches a
  1991. % frame that was
  1992. % established before the \term{exit point} was established.
  1993. %
  1994. % In particular, it would be valid, during the evaluation of an
  1995. % \specref{unwind-protect}
  1996. % cleanup form executed because of a non-local transfer of control, to
  1997. % initiate a new transfer of control to an
  1998. % \term{exit point} intervening between the
  1999. % \specref{unwind-protect}
  2000. % and the original target; the original processing of
  2001. % transfer of control is abandoned.
  2002. %
  2003. % \endissue{EXIT-EXTENT:MINIMAL}
  2004. \endcom
  2005. %%% ========== RETURN-FROM
  2006. \begincom{return-from}\ftype{Special Operator}
  2007. \label Syntax::
  2008. %% 7.7.0 7
  2009. \DefspecNoReturn return-from {\param{name} \brac{\param{result}}}
  2010. \label Arguments and Values::
  2011. \param{name}---a \term{block tag}; \noeval.
  2012. \param{result}---a \term{form}; \eval.
  2013. \Default{\nil}
  2014. \label Description::
  2015. Returns control and \term{multiple values}\meaning{2} from a lexically enclosing \term{block}.
  2016. A \specref{block} \term{form} named \param{name} must lexically enclose
  2017. the occurrence of \specref{return-from}; any \term{values} \term{yielded}
  2018. by the \term{evaluation} of \param{result} are immediately returned from
  2019. the innermost such lexically enclosing \term{block}.
  2020. % This is all said in a concept section now. --sjl 7 Mar 92
  2021. %\issue{EXIT-EXTENT:MINIMAL}
  2022. %When a transfer of control is initiated by \specref{return-from},
  2023. %the following events occur before the transfer of control is complete.
  2024. %Note that for \specref{return-from}, the
  2025. %\term{exit point} is the corresponding
  2026. %\specref{block} \term{form}.
  2027. %\beginlist
  2028. %\itemitem{1.}
  2029. %Intervening \term{exit points} are ``abandoned''
  2030. %(\ie their \term{extent} ends and it is no longer valid to attempt
  2031. %to transfer control through them).
  2032. %
  2033. %\itemitem{2.}
  2034. %The cleanup clauses of any intervening \specref{unwind-protect} clauses
  2035. % are evaluated.
  2036. %
  2037. %\itemitem{3.}
  2038. %Intervening dynamic \term{bindings} of \declref{special} variables and
  2039. %\term{catch tags} are undone.
  2040. %% what about condition handlers and restarts? --sjl 5 Mar 92
  2041. %
  2042. %\itemitem{4.}
  2043. %The \term{extent} of the \term{exit point} being invoked ends,
  2044. %and control is passed to the target.
  2045. %\endlist
  2046. %
  2047. %The extent of an exit being ``abandoned'' because it is being passed over
  2048. %ends as soon as the transfer of control is initiated. That is,
  2049. %event 1 occurs at the beginning of the initiation of the transfer of
  2050. %control.
  2051. %The consequences are undefined if an attempt is made to transfer control
  2052. %to an \term{exit point} whose \term{dynamic extent} has ended.
  2053. %
  2054. %%Moon had me add the part about "interleaved" -kmp 13-Feb-92
  2055. %Events 2 and 3 are actually performed interleaved, in the order
  2056. %corresponding to the reverse order in which they were established.
  2057. %The effect of this is that the cleanup clauses of an \specref{unwind-protect}
  2058. %sees the same dynamic \term{bindings}
  2059. %of variables and \term{catch tags} as were
  2060. %visible when the \specref{unwind-protect} was entered.
  2061. %
  2062. %Event 4 occurs at the end of the transfer of control.
  2063. %
  2064. %%Dussud removed some additional detailed discussion here about longer extents,
  2065. %% how events are interwoven, etc.
  2066. %\endissue{EXIT-EXTENT:MINIMAL}
  2067. The transfer of control initiated by \specref{return-from} is performed
  2068. as described in \secref\TransferOfControl.
  2069. \label Examples::
  2070. \issue{EXIT-EXTENT:MINIMAL}
  2071. \code
  2072. (block alpha (return-from alpha) 1) \EV NIL
  2073. (block alpha (return-from alpha 1) 2) \EV 1
  2074. (block alpha (return-from alpha (values 1 2)) 3) \EV 1, 2
  2075. (let ((a 0))
  2076. (dotimes (i 10) (incf a) (when (oddp i) (return)))
  2077. a) \EV 2
  2078. (defun temp (x)
  2079. (if x (return-from temp 'dummy))
  2080. 44) \EV TEMP
  2081. (temp nil) \EV 44
  2082. (temp t) \EV DUMMY
  2083. (block out
  2084. (flet ((exit (n) (return-from out n)))
  2085. (block out (exit 1)))
  2086. 2) \EV 1
  2087. (block nil
  2088. (unwind-protect (return-from nil 1)
  2089. (return-from nil 2)))
  2090. \EV 2
  2091. (dolist (flag '(nil t))
  2092. (block nil
  2093. (let ((x 5))
  2094. (declare (special x))
  2095. (unwind-protect (return-from nil)
  2096. (print x))))
  2097. (print 'here))
  2098. \OUT 5
  2099. \OUT HERE
  2100. \OUT 5
  2101. \OUT HERE
  2102. \EV NIL
  2103. (dolist (flag '(nil t))
  2104. (block nil
  2105. (let ((x 5))
  2106. (declare (special x))
  2107. (unwind-protect
  2108. (if flag (return-from nil))
  2109. (print x))))
  2110. (print 'here))
  2111. \OUT 5
  2112. \OUT HERE
  2113. \OUT 5
  2114. \OUT HERE
  2115. \EV NIL
  2116. \endcode
  2117. The following has undefined consequences because the \specref{block} \term{form}
  2118. exits normally before the \macref{return-from} \term{form} is attempted.
  2119. \code
  2120. (funcall (block nil #'(lambda () (return-from nil)))) is an error.
  2121. \endcode
  2122. \endissue{EXIT-EXTENT:MINIMAL}
  2123. \label Affected By:\None.
  2124. \label Exceptional Situations:\None.
  2125. \label See Also::
  2126. \specref{block},
  2127. \macref{return},
  2128. {\secref\Evaluation}
  2129. \label Notes:\None.
  2130. \endcom
  2131. %%% ========== RETURN
  2132. \begincom{return}\ftype{Macro}
  2133. \label Syntax::
  2134. %% 7.7.0 7
  2135. \DefmacNoReturn return {\brac{\param{result}}}
  2136. \label Arguments and Values::
  2137. \param{result}---a \term{form}; \eval.
  2138. \Default{\nil}
  2139. \label Description::
  2140. Returns, as if by \specref{return-from}, from the \term{block} named \nil.
  2141. \label Examples::
  2142. \code
  2143. (block nil (return) 1) \EV NIL
  2144. (block nil (return 1) 2) \EV 1
  2145. (block nil (return (values 1 2)) 3) \EV 1, 2
  2146. (block nil (block alpha (return 1) 2)) \EV 1
  2147. (block alpha (block nil (return 1)) 2) \EV 2
  2148. (block nil (block nil (return 1) 2)) \EV 1
  2149. \endcode
  2150. \label Affected By:\None.
  2151. \label Conditions:\None.
  2152. \label See Also::
  2153. \specref{block},
  2154. \specref{return-from},
  2155. {\secref\Evaluation}
  2156. \label Notes::
  2157. \code
  2158. (return) \EQ (return-from nil)
  2159. (return \param{form}) \EQ (return-from nil \param{form})
  2160. \endcode
  2161. The \term{implicit blocks} \term{established} by \term{macros} such as \macref{do}
  2162. are often named \nil, so that \macref{return} can be used to exit from
  2163. such \term{forms}.
  2164. \endcom
  2165. %%% ========== TAGBODY
  2166. \begincom{tagbody}\ftype{Special Operator}
  2167. \label Syntax::
  2168. \DefspecWithValues tagbody
  2169. {\star{\curly{\param{tag} | \param{statement}}}}
  2170. {\nil}
  2171. \label Arguments and Values::
  2172. %% 7.8.5 8
  2173. \param{tag}---a \term{go tag}; \noeval.
  2174. \param{statement}---a \term{compound form}; \evalspecial.
  2175. \label Description::
  2176. Executes zero or more \term{statements} in a
  2177. %context
  2178. \term{lexical environment}
  2179. that provides for control transfers to labels indicated by the \param{tags}.
  2180. %% 7.8.5 4
  2181. %% 7.8.5 5
  2182. The \param{statements} in a \specref{tagbody} are \term{evaluated} in order
  2183. from left to right, and their \term{values} are discarded. If at any time
  2184. there are no remaining \param{statements}, \specref{tagbody} returns \nil.
  2185. %% 7.8.5 6
  2186. However, if \f{(go \param{tag})} is \term{evaluated}, control jumps to the
  2187. part of the body labeled with the \param{tag}. (Tags are compared with \funref{eql}.)
  2188. %!!! Need to introduce the word "lexical" in more places here.
  2189. A \param{tag} established by \specref{tagbody} has \term{lexical scope}
  2190. and has \term{dynamic extent}. Once \specref{tagbody} has been exited,
  2191. it is no longer valid to \specref{go} to a \param{tag} in its body.
  2192. It is permissible for \specref{go} to jump to a \specref{tagbody} that is
  2193. not the innermost \specref{tagbody} containing that \specref{go};
  2194. the \param{tags} established by a \specref{tagbody} only shadow
  2195. other \param{tags} of like name.
  2196. \issue{TAGBODY-TAG-EXPANSION:NO}
  2197. The determination of which elements of the body are \param{tags}
  2198. and which are \param{statements} is made prior to any \term{macro expansion}
  2199. of that element. If a \param{statement} is a \term{macro form} and
  2200. its \term{macro expansion} is an \term{atom}, that \term{atom} is treated
  2201. as a \param{statement}, not a \param{tag}.
  2202. \endissue{TAGBODY-TAG-EXPANSION:NO}
  2203. %!!! Barmar: Didn't we say something about duplicate tags?
  2204. %KMP: Apparently not, but maybe something should be added about `explicitly vague'.
  2205. \label Examples::
  2206. \code
  2207. (let (val)
  2208. (tagbody
  2209. (setq val 1)
  2210. (go point-a)
  2211. (incf val 16)
  2212. point-c
  2213. (incf val 04)
  2214. (go point-b)
  2215. (incf val 32)
  2216. point-a
  2217. (incf val 02)
  2218. (go point-c)
  2219. (incf val 64)
  2220. point-b
  2221. (incf val 08))
  2222. val)
  2223. \EV 15
  2224. (defun f1 (flag)
  2225. (let ((n 1))
  2226. (tagbody
  2227. (setq n (f2 flag #'(lambda () (go out))))
  2228. out
  2229. (prin1 n))))
  2230. \EV F1
  2231. (defun f2 (flag escape)
  2232. (if flag (funcall escape) 2))
  2233. \EV F2
  2234. (f1 nil)
  2235. \OUT 2
  2236. \EV NIL
  2237. (f1 t)
  2238. \OUT 1
  2239. \EV NIL
  2240. \endcode
  2241. \label Affected By:\None.
  2242. \label Exceptional Situations:\None.
  2243. \label See Also::
  2244. \specref{go}
  2245. \label Notes::
  2246. The \term{macros} in \thenextfigure\ have \term{implicit tagbodies}.
  2247. \displaythree{Macros that have implicit tagbodies.}{
  2248. do&do-external-symbols&dotimes\cr
  2249. do*&do-symbols&prog\cr
  2250. do-all-symbols&dolist&prog*\cr
  2251. }
  2252. \endcom
  2253. %%% ========== THROW
  2254. \begincom{throw}\ftype{Special Operator}
  2255. \label Syntax::
  2256. \DefspecNoReturn throw {tag result-form}
  2257. \label Arguments and Values::
  2258. \param{tag}---a \term{catch tag}; \eval.
  2259. \param{result-form}---a \term{form}; \evalspecial.
  2260. \label Description::
  2261. \specref{throw} causes a non-local control transfer
  2262. to a \specref{catch} whose tag is \funref{eq} to \param{tag}.
  2263. %% 7.10.0 11
  2264. %% This is said more precisely below. -moon & kmp 13-feb-92
  2265. % Dynamic variable \term{bindings} are undone back to the point of the \specref{catch},
  2266. % and any intervening \specref{unwind-protect} clean-up code is executed.
  2267. \param{Tag} is evaluated first to produce an \term{object}
  2268. called the throw tag; then \param{result-form} is evaluated,
  2269. and its results are saved. If the \param{result-form} produces
  2270. multiple values, then all the values are saved.
  2271. The most recent outstanding \specref{catch}
  2272. whose \param{tag} is \funref{eq} to the throw tag
  2273. is exited; the saved results are returned as the value or
  2274. values of \specref{catch}.
  2275. % This is all said in a concept section now. --sjl 7 Mar 92
  2276. %\issue{EXIT-EXTENT:MINIMAL}
  2277. %When a transfer of control is initiated by \specref{throw},
  2278. %the following events occur before the transfer of control is complete.
  2279. %Note that for \specref{throw}, the
  2280. %\term{exit point} is the corresponding
  2281. %\specref{catch} \term{form}.
  2282. %\beginlist
  2283. %\itemitem{1.}
  2284. %Intervening \term{exit points} are ``abandoned''
  2285. %(\ie their \term{extent} ends
  2286. % and it is no longer valid to attempt to transfer control through them).
  2287. %
  2288. %\itemitem{2.}
  2289. % The cleanup clauses of any intervening \specref{unwind-protect} clauses
  2290. % are evaluated.
  2291. %
  2292. %\itemitem{3.}
  2293. % Intervening dynamic \term{bindings} of \declref{special} variables
  2294. % and \term{catch tags} are undone.
  2295. %% what about condition handlers and restarts? --sjl 5 Mar 92
  2296. %
  2297. %\itemitem{4.}
  2298. % The \term{extent} of the \term{exit point} being invoked ends,
  2299. % and control is passed to the target.
  2300. %\endlist
  2301. %
  2302. %The extent of an exit being ``abandoned'' because it is being passed over
  2303. %ends as soon as the transfer of control is initiated. That is,
  2304. %event 1 occurs at the beginning of the initiation of the transfer of
  2305. %control. The consequences are undefined if an attempt is made
  2306. %to transfer control to an \term{exit point} whose \term{dynamic extent} has
  2307. %ended.
  2308. %
  2309. %%Moon had me add the part about "interleaved" -kmp 13-Feb-92
  2310. %Events 2 and 3 are actually performed interleaved, in the order
  2311. %corresponding to the reverse order
  2312. %in which they were established.
  2313. %The effect of this is that the cleanup clauses of an \specref{unwind-protect}
  2314. %sees the same dynamic \term{bindings}
  2315. %of variables and \term{catch tags} as were
  2316. %visible when the \specref{unwind-protect} was entered.
  2317. %
  2318. %Event 4 occurs at the end of the transfer of control.
  2319. %
  2320. %\endissue{EXIT-EXTENT:MINIMAL}
  2321. The transfer of control initiated by \specref{throw} is performed
  2322. as described in \secref\TransferOfControl.
  2323. \label Examples::
  2324. \code
  2325. (catch 'result
  2326. (setq i 0 j 0)
  2327. (loop (incf j 3) (incf i)
  2328. (if (= i 3) (throw 'result (values i j))))) \EV 3, 9
  2329. \endcode
  2330. \issue{EXIT-EXTENT:MINIMAL}
  2331. \code
  2332. (catch nil
  2333. (unwind-protect (throw nil 1)
  2334. (throw nil 2))) \EV 2
  2335. \endcode
  2336. The consequences of the following are undefined
  2337. because the \specref{catch} of \f{b}
  2338. is passed over by the first \specref{throw},
  2339. hence portable programs must assume that
  2340. its \term{dynamic extent} is terminated.
  2341. The \term{binding} of the \term{catch tag} is not yet \term{disestablished}
  2342. and therefore it is the target of the second \specref{throw}.
  2343. %% Moon: Belongs with redundant and confusing text now commented out in Notes.
  2344. % If the implementation is extended as outlined above,
  2345. % the following returns \f{2}.
  2346. \code
  2347. (catch 'a
  2348. (catch 'b
  2349. (unwind-protect (throw 'a 1)
  2350. (throw 'b 2))))
  2351. \endcode
  2352. The following prints ``\f{The inner catch returns :SECOND-THROW}''
  2353. and then returns \f{:outer-catch}.
  2354. \code
  2355. (catch 'foo
  2356. (format t "The inner catch returns ~s.~%"
  2357. (catch 'foo
  2358. (unwind-protect (throw 'foo :first-throw)
  2359. (throw 'foo :second-throw))))
  2360. :outer-catch)
  2361. \OUT The inner catch returns :SECOND-THROW
  2362. \EV :OUTER-CATCH
  2363. \endcode
  2364. %% Moon: This whole example is redundant.
  2365. % The consequences of the following are undefined because the \term{extent} of
  2366. % the {\tt (catch 'bar ...)} \term{exit point}
  2367. % ends when the {\tt (THROW 'FOO ...)}
  2368. % commences.
  2369. % %% Moon: Belongs with redundant and confusing text now commented out in Notes.
  2370. % % If the implementation is extended as described above,
  2371. % % the pending \term{exit point} to tag {\tt foo} is discarded by the
  2372. % % second \specref{throw} to {\tt bar} and the value 4 is transferred to
  2373. % % {\tt (catch 'bar ...)}, that returns 4. The {\tt (catch 'foo ...)}
  2374. % % then returns the 4 because its first argument has returned
  2375. % % normally. {\tt xxx} is not printed.
  2376. %
  2377. % \code
  2378. % (catch 'foo
  2379. % (catch 'bar
  2380. % (unwind-protect (throw 'foo 3)
  2381. % (throw 'bar 4)
  2382. % (print 'xxx))))
  2383. % \endcode
  2384. \endissue{EXIT-EXTENT:MINIMAL}
  2385. \label Affected By:\None.
  2386. \label Exceptional Situations::
  2387. %% 7.10.0 12
  2388. If there is no outstanding \term{catch tag} that matches the throw tag,
  2389. no unwinding of the stack is performed,
  2390. and an error \oftype{control-error} is signaled.
  2391. When the error is signaled,
  2392. % the outstanding \specref{catch tags}
  2393. % the dynamic variable \term{bindings}, ... are those
  2394. %% Replaced by more general terms.
  2395. the \term{dynamic environment} is that which was
  2396. in force at the point of the \specref{throw}.
  2397. \label See Also::
  2398. \specref{block},
  2399. \specref{catch},
  2400. \specref{return-from},
  2401. \specref{unwind-protect},
  2402. {\secref\Evaluation}
  2403. \label Notes::
  2404. %% Moon thinks this is just confusing and unnecessary.
  2405. % Implementations can support longer \term{extents} for
  2406. % \term{exit points} than is
  2407. % required here; in particular, an implementation may be extended to
  2408. % allow a larger extent as follows:
  2409. %
  2410. % Events of 1, 2, 3, and 4 are interwoven in the reverse
  2411. % order in which they were established. In particular, the \term{extent} of
  2412. % a passed-over \term{exit point} ends when control reaches a
  2413. % frame that was
  2414. % established before the \term{exit point} was established.
  2415. %
  2416. % In particular, it would be valid, during the evaluation of an
  2417. % \specref{unwind-protect}
  2418. % cleanup form executed because of a non-local transfer of control, to
  2419. % initiate a new transfer of control to an
  2420. % \term{exit point} intervening between the
  2421. % \specref{unwind-protect}
  2422. % and the original target; the original processing of
  2423. % transfer of control is abandoned.
  2424. \specref{catch} and \specref{throw} are normally used when the \term{exit point}
  2425. must have \term{dynamic scope} (\eg the \specref{throw} is not lexically enclosed
  2426. by the \specref{catch}), while \specref{block} and \specref{return} are used
  2427. when \term{lexical scope} is sufficient.
  2428. \endcom
  2429. %%% ========== UNWIND-PROTECT
  2430. \begincom{unwind-protect}\ftype{Special Operator}
  2431. \label Syntax::
  2432. \DefspecWithValues unwind-protect
  2433. {\param{protected-form} \starparam{cleanup-form}}
  2434. {\starparam{result}}
  2435. \label Arguments and Values::
  2436. \param{protected-form}---a \term{form}.
  2437. \param{cleanup-form}---a \term{form}.
  2438. %% 7.9.2 18
  2439. \param{results}---the \term{values} of the \term{protected-form}.
  2440. \label Description::
  2441. %% 7.10.0 6
  2442. %% 7.10.0 7
  2443. \specref{unwind-protect} evaluates \param{protected-form}
  2444. and guarantees that \param{cleanup-forms} are executed
  2445. before \specref{unwind-protect} exits,
  2446. whether it terminates
  2447. normally or is aborted by a control transfer of some kind.
  2448. \specref{unwind-protect} is intended to be used
  2449. to make sure that
  2450. certain side effects take place after the evaluation of
  2451. \param{protected-form}.
  2452. %% 7.10.0 9
  2453. If a \term{non-local exit} occurs during execution of \param{cleanup-forms},
  2454. no special action is taken. The \param{cleanup-forms} of
  2455. \specref{unwind-protect}
  2456. are not protected by that \specref{unwind-protect}.
  2457. %% Moon and I couldn't figure out what this was about. -kmp 13-Feb-92
  2458. % , though they might be
  2459. % protected if that \specref{unwind-protect} occurs within the protected
  2460. % form of another \specref{unwind-protect}.
  2461. %% 7.10.0 10
  2462. \specref{unwind-protect} protects against all attempts to exit
  2463. from \param{protected-form}, including
  2464. \specref{go},
  2465. \macref{handler-case},
  2466. \macref{ignore-errors},
  2467. \macref{restart-case},
  2468. \specref{return-from},
  2469. \specref{throw},
  2470. and \macref{with-simple-restart}.
  2471. %!!! Moon: And other stuff -- see previous page. Obviously need to collect all
  2472. % this stuff into a glossary entry.
  2473. \issue{EXIT-EXTENT-AND-CONDITION-SYSTEM:LIKE-DYNAMIC-BINDINGS}
  2474. Undoing of \term{handler} and \term{restart} \term{bindings} during an exit
  2475. happens in parallel with the undoing of the bindings of \term{dynamic variables}
  2476. and \specref{catch} tags, in the reverse order in which they were established.
  2477. The effect of this is that \param{cleanup-form} sees the same \term{handler}
  2478. and \term{restart} \term{bindings}, as well as \term{dynamic variable} \term{bindings}
  2479. and \specref{catch} tags, as were visible when the \specref{unwind-protect} was entered.
  2480. \endissue{EXIT-EXTENT-AND-CONDITION-SYSTEM:LIKE-DYNAMIC-BINDINGS}
  2481. \label Examples::
  2482. \code
  2483. (tagbody
  2484. (let ((x 3))
  2485. (unwind-protect
  2486. (if (numberp x) (go out))
  2487. (print x)))
  2488. out
  2489. ...)
  2490. \endcode
  2491. When \specref{go} is executed, the call to \funref{print} is executed first,
  2492. and then the transfer of control to the tag \f{out} is completed.
  2493. \code
  2494. (defun dummy-function (x)
  2495. (setq state 'running)
  2496. (unless (numberp x) (throw 'abort 'not-a-number))
  2497. (setq state (1+ x))) \EV DUMMY-FUNCTION
  2498. (catch 'abort (dummy-function 1)) \EV 2
  2499. state \EV 2
  2500. (catch 'abort (dummy-function 'trash)) \EV NOT-A-NUMBER
  2501. state \EV RUNNING
  2502. (catch 'abort (unwind-protect (dummy-function 'trash)
  2503. (setq state 'aborted))) \EV NOT-A-NUMBER
  2504. state \EV ABORTED
  2505. \endcode
  2506. %% 7.10.0 8
  2507. The following code
  2508. is not correct:
  2509. \code
  2510. (unwind-protect
  2511. (progn (incf *access-count*)
  2512. (perform-access))
  2513. (decf *access-count*))
  2514. \endcode
  2515. If an exit occurs before completion of \macref{incf},
  2516. the \macref{decf} \term{form} is executed anyway, resulting in an
  2517. incorrect value for \f{*access-count*}.
  2518. The correct way to code this is as follows:
  2519. \code
  2520. (let ((old-count *access-count*))
  2521. (unwind-protect
  2522. (progn (incf *access-count*)
  2523. (perform-access))
  2524. (setq *access-count* old-count)))
  2525. \endcode
  2526. \issue{EXIT-EXTENT:MINIMAL}
  2527. \code
  2528. ;;; The following returns 2.
  2529. (block nil
  2530. (unwind-protect (return 1)
  2531. (return 2)))
  2532. ;;; The following has undefined consequences.
  2533. (block a
  2534. (block b
  2535. (unwind-protect (return-from a 1)
  2536. (return-from b 2))))
  2537. ;;; The following returns 2.
  2538. (catch nil
  2539. (unwind-protect (throw nil 1)
  2540. (throw nil 2)))
  2541. ;;; The following has undefined consequences because the catch of B is
  2542. ;;; passed over by the first THROW, hence portable programs must assume
  2543. ;;; its dynamic extent is terminated. The binding of the catch tag is not
  2544. ;;; yet disestablished and therefore it is the target of the second throw.
  2545. (catch 'a
  2546. (catch 'b
  2547. (unwind-protect (throw 'a 1)
  2548. (throw 'b 2))))
  2549. ;;; The following prints "The inner catch returns :SECOND-THROW"
  2550. ;;; and then returns :OUTER-CATCH.
  2551. (catch 'foo
  2552. (format t "The inner catch returns ~s.~%"
  2553. (catch 'foo
  2554. (unwind-protect (throw 'foo :first-throw)
  2555. (throw 'foo :second-throw))))
  2556. :outer-catch)
  2557. ;;; The following returns 10. The inner CATCH of A is passed over, but
  2558. ;;; because that CATCH is disestablished before the THROW to A is executed,
  2559. ;;; it isn't seen.
  2560. (catch 'a
  2561. (catch 'b
  2562. (unwind-protect (1+ (catch 'a (throw 'b 1)))
  2563. (throw 'a 10))))
  2564. ;;; The following has undefined consequences because the extent of
  2565. ;;; the (CATCH 'BAR ...) exit ends when the (THROW 'FOO ...)
  2566. ;;; commences.
  2567. (catch 'foo
  2568. (catch 'bar
  2569. (unwind-protect (throw 'foo 3)
  2570. (throw 'bar 4)
  2571. (print 'xxx))))
  2572. ;;; The following returns 4; XXX is not printed.
  2573. ;;; The (THROW 'FOO ...) has no effect on the scope of the BAR
  2574. ;;; catch tag or the extent of the (CATCH 'BAR ...) exit.
  2575. (catch 'bar
  2576. (catch 'foo
  2577. (unwind-protect (throw 'foo 3)
  2578. (throw 'bar 4)
  2579. (print 'xxx))))
  2580. ;;; The following prints 5.
  2581. (block nil
  2582. (let ((x 5))
  2583. (declare (special x))
  2584. (unwind-protect (return)
  2585. (print x))))
  2586. \endcode
  2587. \endissue{EXIT-EXTENT:MINIMAL}
  2588. \label Affected By:\None.
  2589. \label Exceptional Situations:\None.
  2590. \label See Also::
  2591. \specref{catch},
  2592. \specref{go},
  2593. \macref{handler-case},
  2594. \macref{restart-case},
  2595. \macref{return},
  2596. \specref{return-from},
  2597. \specref{throw},
  2598. {\secref\Evaluation}
  2599. \label Notes:\None.
  2600. \endcom
  2601. %-------------------- Truth Values --------------------
  2602. %%% ========== NIL
  2603. \begincom{nil}\ftype{Constant Variable}
  2604. \label Constant Value::
  2605. \nil.
  2606. \label Description::
  2607. %% 6.1.0 1
  2608. %% 6.1.0 2
  2609. %\nil\ is a \term{symbol} which appears to be treated as a variable when evaluated.
  2610. %To modify the value of \nil\ is not permitted.
  2611. %The value of the object \oftype{null} is \nil.
  2612. %\nil\ represents both the
  2613. %logical false value and the \term{empty list}.
  2614. %% 14.0.0 3
  2615. %\nil\ is considered to be a \term{sequence} of length zero.
  2616. \nil\ represents both \term{boolean} (and \term{generalized boolean}) \term{false}
  2617. and the \term{empty list}.
  2618. \label Examples::
  2619. \code
  2620. nil \EV NIL
  2621. \endcode
  2622. \label See Also::
  2623. \conref{t}
  2624. \label Notes:\None.
  2625. \endcom
  2626. %%% ========== NOT
  2627. \begincom{not}\ftype{Function}
  2628. \issue{NOT-AND-NULL-RETURN-VALUE:X3J13-MAR-93}
  2629. \label Syntax::
  2630. \DefunWithValues not {x} {boolean}
  2631. \label Arguments and Values::
  2632. \param{x}---a \term{generalized boolean} (\ie any \term{object}).
  2633. \param{boolean}---a \term{boolean}.
  2634. \label Description::
  2635. %% 6.4.0 3
  2636. \StrictPredicate{x}{\term{false}}
  2637. \label Examples::
  2638. \code
  2639. (not nil) \EV T
  2640. (not '()) \EV T
  2641. (not (integerp 'sss)) \EV T
  2642. (not (integerp 1)) \EV NIL
  2643. (not 3.7) \EV NIL
  2644. (not 'apple) \EV NIL
  2645. \endcode
  2646. \endissue{NOT-AND-NULL-RETURN-VALUE:X3J13-MAR-93}
  2647. \label Side Effects:\None.
  2648. \label Affected By:\None.
  2649. \label Exceptional Situations:\None!
  2650. \label See Also::
  2651. \funref{null}
  2652. \label Notes::
  2653. % \code
  2654. % (not x) \EQ (null x)
  2655. % \endcode
  2656. %% 6.4.0 $
  2657. \funref{not} is intended to be used to invert the `truth value' of a \term{boolean}
  2658. (or \term{generalized boolean})
  2659. whereas \funref{null} is intended to be used to test for the \term{empty list}.
  2660. Operationally, \funref{not} and \funref{null} compute the same result;
  2661. which to use is a matter of style.
  2662. \endcom
  2663. %%% ========== T
  2664. \begincom{t}\ftype{Constant Variable}
  2665. \label Constant Value::
  2666. %% 6.1.0 3
  2667. \misc{t}.
  2668. \label Description::
  2669. The \term{boolean} representing true,
  2670. and the canonical \term{generalized boolean} representing true.
  2671. Although any \term{object}
  2672. other than \nil\ is considered \term{true},
  2673. \t\ is generally used when there is no special reason
  2674. to prefer one such \term{object} over another.
  2675. The \term{symbol} \t\ is also sometimes used for other purposes as well.
  2676. For example,
  2677. as the \term{name} of a \term{class},
  2678. as a \term{designator} (\eg a \term{stream designator})
  2679. or as a special symbol for some syntactic reason
  2680. (\eg in \macref{case} and \macref{typecase} to label the \param{otherwise-clause}).
  2681. \label Examples::
  2682. \code
  2683. t \EV T
  2684. (eq t 't) \EV \term{true}
  2685. (find-class 't) \EV #<CLASS T 610703333>
  2686. (case 'a (a 1) (t 2)) \EV 1
  2687. (case 'b (a 1) (t 2)) \EV 2
  2688. (prin1 'hello t)
  2689. \OUT HELLO
  2690. \EV HELLO
  2691. \endcode
  2692. \label See Also::
  2693. \conref{nil}
  2694. \label Notes:\None.
  2695. \endcom
  2696. %-------------------- Identity Equality --------------------
  2697. %%% ========== EQ
  2698. \begincom{eq}\ftype{Function}
  2699. \label Syntax::
  2700. \DefunWithValues eq {x y} {generalized-boolean}
  2701. \label Arguments and Values::
  2702. \param{x}---an \term{object}.
  2703. \param{y}---an \term{object}.
  2704. \param{generalized-boolean}---a \term{generalized boolean}.
  2705. \label Description::
  2706. %% 6.3.0 3
  2707. Returns \term{true} if its \term{arguments} are the same, identical \term{object};
  2708. otherwise, returns \term{false}.
  2709. \label Examples::
  2710. \code
  2711. (eq 'a 'b) \EV \term{false}
  2712. (eq 'a 'a) \EV \term{true}
  2713. (eq 3 3)
  2714. \EV \term{true}
  2715. \OV \term{false}
  2716. (eq 3 3.0) \EV \term{false}
  2717. (eq 3.0 3.0)
  2718. \EV \term{true}
  2719. \OV \term{false}
  2720. (eq #c(3 -4) #c(3 -4))
  2721. \EV \term{true}
  2722. \OV \term{false}
  2723. (eq #c(3 -4.0) #c(3 -4)) \EV \term{false}
  2724. (eq (cons 'a 'b) (cons 'a 'c)) \EV \term{false}
  2725. (eq (cons 'a 'b) (cons 'a 'b)) \EV \term{false}
  2726. (eq '(a . b) '(a . b))
  2727. \EV \term{true}
  2728. \OV \term{false}
  2729. (progn (setq x (cons 'a 'b)) (eq x x)) \EV \term{true}
  2730. (progn (setq x '(a . b)) (eq x x)) \EV \term{true}
  2731. (eq #\\A #\\A)
  2732. \EV \term{true}
  2733. \OV \term{false}
  2734. (let ((x "Foo")) (eq x x)) \EV \term{true}
  2735. (eq "Foo" "Foo")
  2736. \EV \term{true}
  2737. \OV \term{false}
  2738. (eq "Foo" (copy-seq "Foo")) \EV \term{false}
  2739. (eq "FOO" "foo") \EV \term{false}
  2740. (eq "string-seq" (copy-seq "string-seq")) \EV \term{false}
  2741. (let ((x 5)) (eq x x))
  2742. \EV \term{true}
  2743. \OV \term{false}
  2744. \endcode
  2745. \label Side Effects:\None.
  2746. \label Affected By:\None.
  2747. \label Exceptional Situations:\None!
  2748. \label See Also::
  2749. \funref{eql},
  2750. \funref{equal},
  2751. \funref{equalp},
  2752. \funref{=},
  2753. {\secref\Compilation}
  2754. \label Notes::
  2755. %% 6.3.0 4
  2756. \term{Objects} that appear the same when printed are not necessarily
  2757. \funref{eq} to each other. \term{Symbols} that print the same
  2758. usually are \funref{eq} to each other because of the use of the
  2759. \funref{intern} function. However, \term{numbers} with the
  2760. same value need not be \funref{eq}, and two similar
  2761. \term{lists} are usually not \term{identical}.
  2762. An implementation is permitted to make ``copies'' of
  2763. \term{characters} and \term{numbers} at any time.
  2764. The effect is that \clisp\ makes no guarantee that \funref{eq}
  2765. is true even when both its arguments are ``the same thing'' if
  2766. that thing is a \term{character} or \term{number}.
  2767. Most \clisp\ \term{operators} use \funref{eql} rather than
  2768. \funref{eq} to compare objects, or else they default to \funref{eql}
  2769. and only use \funref{eq} if specifically requested to do so.
  2770. However, the following \term{operators} are defined to use \funref{eq}
  2771. rather than \funref{eql} in a way that cannot be overridden by the
  2772. \term{code} which employs them:
  2773. \displaythree{Operators that always prefer EQ over EQL}{
  2774. catch&getf&throw\cr
  2775. get&remf&\cr
  2776. get-properties&remprop\cr
  2777. }
  2778. \endcom
  2779. %%% ========== EQL
  2780. \begincom{eql}\ftype{Function}
  2781. \label Syntax::
  2782. \DefunWithValues eql {x y} {generalized-boolean}
  2783. \label Arguments and Values::
  2784. \param{x}---an \term{object}.
  2785. \param{y}---an \term{object}.
  2786. \param{generalized-boolean}---a \term{generalized boolean}.
  2787. \label Description::
  2788. %% 6.3.0 7
  2789. The value of \funref{eql} is \term{true} of two objects, \param{x} and
  2790. \param{y}, in the folowing cases:
  2791. \beginlist
  2792. \itemitem{1.} If \param{x} and \param{y} are \funref{eq}.
  2793. \itemitem{2.} If \param{x} and \param{y} are both \term{numbers}
  2794. of the same \term{type} and the same value.
  2795. \itemitem{3.} If they are both \term{characters} that represent the
  2796. same character.
  2797. \endlist
  2798. Otherwise the value of \funref{eql} is \term{false}.
  2799. %% 6.3.0 8
  2800. If an implementation supports positive and negative zeros as \term{distinct} values,
  2801. then \f{(eql 0.0 -0.0)} returns \term{false}.
  2802. Otherwise, when the syntax \f{-0.0} is read it is interpreted as the value \f{0.0},
  2803. and so \f{(eql 0.0 -0.0)} returns \term{true}.
  2804. \label Examples::
  2805. \code
  2806. (eql 'a 'b) \EV \term{false}
  2807. (eql 'a 'a) \EV \term{true}
  2808. (eql 3 3) \EV \term{true}
  2809. (eql 3 3.0) \EV \term{false}
  2810. (eql 3.0 3.0) \EV \term{true}
  2811. (eql #c(3 -4) #c(3 -4)) \EV \term{true}
  2812. (eql #c(3 -4.0) #c(3 -4)) \EV \term{false}
  2813. (eql (cons 'a 'b) (cons 'a 'c)) \EV \term{false}
  2814. (eql (cons 'a 'b) (cons 'a 'b)) \EV \term{false}
  2815. (eql '(a . b) '(a . b))
  2816. \EV \term{true}
  2817. \OV \term{false}
  2818. (progn (setq x (cons 'a 'b)) (eql x x)) \EV \term{true}
  2819. (progn (setq x '(a . b)) (eql x x)) \EV \term{true}
  2820. (eql #\\A #\\A) \EV \term{true}
  2821. (eql "Foo" "Foo")
  2822. \EV \term{true}
  2823. \OV \term{false}
  2824. (eql "Foo" (copy-seq "Foo")) \EV \term{false}
  2825. (eql "FOO" "foo") \EV \term{false}
  2826. \endcode
  2827. Normally \f{(eql 1.0s0 1.0d0)} is false, under the assumption
  2828. that \f{1.0s0} and \f{1.0d0} are of distinct data types.
  2829. However, implementations that do not provide four distinct floating-point
  2830. formats are permitted to ``collapse'' the four formats into some
  2831. smaller number of them; in such an implementation \f{(eql 1.0s0 1.0d0)}
  2832. might be true.
  2833. \label Side Effects:\None.
  2834. \label Affected By:\None.
  2835. \label Exceptional Situations:\None!
  2836. \label See Also::
  2837. \funref{eq},
  2838. \funref{equal},
  2839. \funref{equalp},
  2840. \funref{=},
  2841. \funref{char=}
  2842. \label Notes::
  2843. \funref{eql} is the same as \funref{eq}, except that if the
  2844. arguments are \term{characters} or \term{numbers}
  2845. of the same type then their
  2846. values are compared. Thus \funref{eql} tells whether two \term{objects}
  2847. are conceptually the same, whereas \funref{eq} tells whether two
  2848. \term{objects} are implementationally identical. It is for this reason
  2849. that \funref{eql}, not \funref{eq}, is the default comparison predicate
  2850. for \term{operators} that take \term{sequences}
  2851. as arguments.
  2852. \funref{eql} may not be true of two \term{floats}
  2853. even when they represent the same
  2854. value. \funref{=} is used to compare
  2855. mathematical values.
  2856. %% 6.3.0 9
  2857. Two \term{complex} numbers are considered to be \funref{eql}
  2858. if their real parts are \funref{eql}
  2859. and their imaginary parts are \funref{eql}.
  2860. For example, \f{(eql \#C(4 5) \#C(4 5))} is \term{true} and
  2861. \f{(eql \#C(4 5) \#C(4.0 5.0))} is \term{false}.
  2862. Note that while \f{(eql \#C(5.0 0.0) 5.0)} is \term{false},
  2863. \f{(eql \#C(5 0) 5)} is \term{true}.
  2864. In the case of \f{(eql \#C(5.0 0.0) 5.0)} the
  2865. two arguments are of different types,
  2866. and so cannot satisfy \funref{eql}.
  2867. In the case of \f{(eql \#C(5 0) 5)},
  2868. \f{\#C(5 0)} is not a \term{complex} number, but
  2869. is automatically reduced
  2870. to the \term{integer} \f{5}.
  2871. \endcom
  2872. %%% ========== EQUAL
  2873. \begincom{equal}\ftype{Function}
  2874. \label Syntax::
  2875. \DefunWithValues equal {x y} {generalized-boolean}
  2876. \label Arguments and Values::
  2877. \param{x}---an \term{object}.
  2878. \param{y}---an \term{object}.
  2879. \param{generalized-boolean}---a \term{generalized boolean}.
  2880. \label Description::
  2881. %% 6.3.0 12
  2882. Returns \term{true} if \param{x} and \param{y} are structurally similar
  2883. (isomorphic) \term{objects}. \term{Objects} are treated as follows by
  2884. \funref{equal}.
  2885. \beginlist
  2886. \itemitem{\term{Symbols}, \term{Numbers}, and \term{Characters}}
  2887. %% 6.3.0 13
  2888. \funref{equal} is \term{true} of two \term{objects}
  2889. if they are \term{symbols} that are \funref{eq},
  2890. if they are \term{numbers} that are \funref{eql}, or
  2891. if they are \term{characters} that are \funref{eql}.
  2892. \itemitem{\term{Conses}}
  2893. %% 6.3.0 15
  2894. For \term{conses}, \funref{equal} is defined recursively as
  2895. the two \term{cars} being \funref{equal}
  2896. and the two \term{cdrs} being \funref{equal}.
  2897. \itemitem{\term{Arrays}}
  2898. %% 6.3.0 16
  2899. Two \term{arrays} are \funref{equal} only if they are \funref{eq},
  2900. with one exception:
  2901. \term{strings} and \term{bit vectors} are compared element-by-element (using \funref{eql}).
  2902. If either \param{x} or \param{y} has a \term{fill pointer}, the
  2903. \term{fill pointer} limits
  2904. the number of elements examined by \funref{equal}.
  2905. Uppercase and lowercase letters in \term{strings} are considered by
  2906. \funref{equal} to be different.
  2907. \itemitem{\term{Pathnames}}
  2908. %% 6.3.0 18
  2909. Two \term{pathnames} are \funref{equal} if and only if
  2910. all the corresponding components
  2911. (host, device, and so on) are
  2912. %!!! Barmar: "equivalent" ???
  2913. equivalent. Whether or not
  2914. uppercase and lowercase letters are considered equivalent
  2915. in \term{strings} appearing in components is \term{implementation-dependent}.
  2916. \term{pathnames}
  2917. that are \funref{equal} should be functionally equivalent.
  2918. %Barmar didn't think this belonged here. I agree.
  2919. % %% 23.1.1 19
  2920. % For \term{pathnames}, \funref{eql} is the same as \funref{eq}.
  2921. \issue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  2922. \itemitem{\bf Other (Structures, hash-tables, instances, $\ldots$)}
  2923. Two other \term{objects} are \funref{equal} only if they are \funref{eq}.
  2924. %% Barmar: "EQUAL" or "EQUALP" in this next ???
  2925. %% Moon: Delete this. This is EQUAL, not EQUALP
  2926. % %% The following was added at the June 1989 meeting
  2927. % A structure defined by \macref{defstruct} without an explicit
  2928. % \kwd{type} option is called non-typed; otherwise it is typed.
  2929. % The definition of \funref{equalp} on \macref{defstruct}
  2930. % instances is as follows:
  2931. % \funref{equalp} on two \macref{defstruct} instances \f{s1} and \f{s2},
  2932. % where both are non-typed structures, is \term{true} if and only if:
  2933. % \beginlist
  2934. % \itemitem{1.}
  2935. % The \term{type} of \f{s1} is the same as the type of \f{s2}.
  2936. % \itemitem{2.}
  2937. % The value of each \term{slot} of \f{s1}
  2938. % is \funref{equalp} to the value of the same \term{slot} of \f{s2}.
  2939. % \endlist
  2940. \endissue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  2941. \endlist
  2942. \issue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  2943. \funref{equal} does not descend any \term{objects} other than the
  2944. ones explicitly specified above.
  2945. \Thenextfigure\ summarizes the information given in the previous list.
  2946. % !!! Moon: Strange way to phrase it.
  2947. In addition, the figure specifies the priority of the behavior of \funref{equal},
  2948. with upper
  2949. entries taking priority over lower ones.
  2950. \tablefigtwo{Summary and priorities of behavior of \funref{equal}}{Type}{Behavior}{
  2951. \term{number} & uses \funref{eql} \cr
  2952. \term{character} & uses \funref{eql} \cr
  2953. \term{cons} & descends \cr
  2954. \term{bit vector} & descends \cr
  2955. \term{string} & descends \cr
  2956. \term{pathname} & ``functionally equivalent'' \cr
  2957. \term{structure} & uses \funref{eq} \cr
  2958. Other \term{array} & uses \funref{eq} \cr
  2959. \term{hash table} & uses \funref{eq} \cr
  2960. % Redundant. -kmp 3-Feb-92
  2961. % \term{standard object} & uses \funref{eq} \cr
  2962. Other \term{object} & uses \funref{eq} \cr
  2963. }
  2964. \endissue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  2965. Any two \term{objects} that are \funref{eql} are also \funref{equal}.
  2966. \funref{equal} may fail to terminate if \param{x} or \param{y} is circular.
  2967. \label Examples::
  2968. %% 6.3.0 19
  2969. \code
  2970. (equal 'a 'b) \EV \term{false}
  2971. (equal 'a 'a) \EV \term{true}
  2972. (equal 3 3) \EV \term{true}
  2973. (equal 3 3.0) \EV \term{false}
  2974. (equal 3.0 3.0) \EV \term{true}
  2975. (equal #c(3 -4) #c(3 -4)) \EV \term{true}
  2976. (equal #c(3 -4.0) #c(3 -4)) \EV \term{false}
  2977. (equal (cons 'a 'b) (cons 'a 'c)) \EV \term{false}
  2978. (equal (cons 'a 'b) (cons 'a 'b)) \EV \term{true}
  2979. (equal #\\A #\\A) \EV \term{true}
  2980. (equal #\\A #\\a) \EV \term{false}
  2981. (equal "Foo" "Foo") \EV \term{true}
  2982. (equal "Foo" (copy-seq "Foo")) \EV \term{true}
  2983. (equal "FOO" "foo") \EV \term{false}
  2984. (equal "This-string" "This-string") \EV \term{true}
  2985. (equal "This-string" "this-string") \EV \term{false}
  2986. \endcode
  2987. \label Side Effects:\None.
  2988. \label Affected By:\None.
  2989. \label Exceptional Situations:\None.
  2990. \label See Also::
  2991. \funref{eq}, \funref{eql}, \funref{equalp}, \funref{=},
  2992. \funref{string=}, \funref{string-equal}, \funref{char=},
  2993. \funref{char-equal}, \funref{tree-equal}
  2994. \label Notes::
  2995. \issue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  2996. \term{Object} equality is not a concept for which there is a uniquely
  2997. determined correct algorithm. The appropriateness of an equality
  2998. predicate can be judged only in the context of the needs of some
  2999. particular program. Although these functions take any type of
  3000. argument and their names sound very generic,
  3001. \funref{equal} and \funref{equalp} are
  3002. not appropriate for every application.
  3003. \endissue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3004. A rough rule of thumb is that two \term{objects} are \funref{equal}
  3005. if and only if their printed representations are the same.
  3006. \endcom
  3007. %%% ========== EQUALP
  3008. \begincom{equalp}\ftype{Function}
  3009. \label Syntax::
  3010. \DefunWithValues equalp {x y} {generalized-boolean}
  3011. \label Arguments and Values::
  3012. \param{x}---an \term{object}.
  3013. \param{y}---an \term{object}.
  3014. \param{generalized-boolean}---a \term{generalized boolean}.
  3015. \label Description::
  3016. %% 6.3.0 21
  3017. %% 6.3.0 22
  3018. Returns \term{true} if \param{x} and \param{y} are \funref{equal},
  3019. or if they have components that are of the same \term{type} as each other
  3020. and if those components are \funref{equalp};
  3021. specifically, \funref{equalp} returns \term{true} in the following cases:
  3022. \beginlist
  3023. \itemitem{\term{Characters}}
  3024. If two \term{characters} are \funref{char-equal}.
  3025. \itemitem{\term{Numbers}}
  3026. If two \term{numbers} are the \term{same} under \funref{=}.
  3027. %% Change made due to v8 of EQUAL-STRUCTURE. -kmp 30-Jan-92
  3028. % have the same numerical value (even if they are of different
  3029. % \term{types}),
  3030. % or if they have components that are all \funref{equalp}.
  3031. \itemitem{\term{Conses}}
  3032. If the two \term{cars} in the \term{conses} are \funref{equalp}
  3033. and the two \term{cdrs} in the \term{conses} are \funref{equalp}.
  3034. %% Laubsch thinks this goes without saying (and I agree.) -kmp 19-Jan-92
  3035. %(defined recursively).
  3036. \itemitem{\term{Arrays}}
  3037. %% 6.3.0 23
  3038. If two \term{arrays} have the same
  3039. number of dimensions, the dimensions match,
  3040. and the corresponding
  3041. %"components" => "active elements" -kmp 30-Jan-92
  3042. \term{active elements}
  3043. are \funref{equalp}.
  3044. The \term{types} for which the \term{arrays} are \term{specialized} need not match;
  3045. for example, a \term{string} and a general \term{array} that happens to contain the same
  3046. \term{characters} are \funref{equalp}.
  3047. %% Not needed with "components" => "active elements" above. -kmp 30-Jan-92
  3048. % If either \param{x} or \param{y} has a \term{fill pointer},
  3049. % the \term{fill pointer} limits the number of elements examined by \funref{equalp}.
  3050. Because \funref{equalp} performs \term{element}-by-\term{element} comparisons
  3051. of \term{strings} and ignores the \term{case} of \term{characters},
  3052. \term{case} distinctions are ignored when \funref{equalp} compares \term{strings}.
  3053. %% Barmar points out these are implied by the remarks about EQUAL in the first paragraph.
  3054. % \itemitem{\term{Symbols}}
  3055. %
  3056. % %% 6.3.0 24
  3057. % If two \term{symbols} are \term{identical}.
  3058. %
  3059. %\issue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3060. % \itemitem{\term {Structures}, \term{Instances}, other}
  3061. %
  3062. % If two \term{structures}, \term{hash tables}, \term{instances},
  3063. % or other \term{objects} are \term{identical}.
  3064. %\endissue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3065. \issue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3066. \itemitem{\term{Structures}}
  3067. %% Here's the text of the cleanup issue.
  3068. % EQUALP on two DEFSTRUCT objects 's1' and 's2', where one is a
  3069. % non-:TYPEed DEFSTRUCT and the other is typed, is false.
  3070. %
  3071. % EQUALP on two DEFSTRUCT objects 's1' and 's2', where both are
  3072. % non-:TYPEed DEFSTRUCTS is true iff:
  3073. %
  3074. % (1) The type of 's1' is the same as the type of 's2' (this is
  3075. % the same as saying that the defstruct name for 's1' is the same
  3076. % as that for 's2').
  3077. %
  3078. % (2) The value of each slot of 's1' is EQUALP to the value of the
  3079. % same slot of 's2' (where "same" means same name) (this is not the
  3080. %
  3081. %% This doesn't use the same wording as in the cleanup, but I couldn't figure
  3082. %% out that wording. -kmp 30-Jan-92
  3083. If two \term{structures} $S\sub 1$ and $S\sub 2$ have the same \term{class}
  3084. and the value of each \term{slot} in $S\sub 1$ is the \term{same} under \funref{equalp}
  3085. as the value of the corresponding \term{slot} in $S\sub 2$.
  3086. \itemitem{\term{Hash Tables}}
  3087. %If two \term{hash tables} are \funref{equalp}.
  3088. \funref{equalp} descends \term{hash-tables} by first comparing the count of entries
  3089. and the \kwd{test} function; if those are the same, it compares the
  3090. keys of the tables using the \kwd{test} function and then the values
  3091. of the matching keys using \funref{equalp} recursively.
  3092. \endissue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3093. \endlist
  3094. \issue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3095. \funref{equalp} does not descend any \term{objects}
  3096. other than the ones explicitly specified above.
  3097. \Thenextfigure\ summarizes the information given in the previous list.
  3098. In addition, the figure specifies the priority of the behavior of \funref{equalp},
  3099. with upper
  3100. entries taking priority over lower ones.
  3101. \tablefigtwo{Summary and priorities of behavior of \funref{equalp}}{Type}{Behavior}{
  3102. \term{number} & uses \funref{=} \cr
  3103. \term{character} & uses \funref{char-equal} \cr
  3104. \term{cons} & descends \cr
  3105. \term{bit vector} & descends \cr
  3106. \term{string} & descends \cr
  3107. \term{pathname} & same as \funref{equal} \cr
  3108. \term{structure} & descends, as described above \cr
  3109. Other \term{array} & descends \cr
  3110. \term{hash table} & descends, as described above \cr
  3111. %% This is redundant. -kmp 25-Aug-91
  3112. % \term{standard object} & uses \funref{eq} \cr
  3113. Other \term{object} & uses \funref{eq} \cr
  3114. }
  3115. \endissue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3116. \label Examples::
  3117. %% 6.3.0 25
  3118. \code
  3119. (equalp 'a 'b) \EV \term{false}
  3120. (equalp 'a 'a) \EV \term{true}
  3121. (equalp 3 3) \EV \term{true}
  3122. (equalp 3 3.0) \EV \term{true}
  3123. (equalp 3.0 3.0) \EV \term{true}
  3124. (equalp #c(3 -4) #c(3 -4)) \EV \term{true}
  3125. (equalp #c(3 -4.0) #c(3 -4)) \EV \term{true}
  3126. (equalp (cons 'a 'b) (cons 'a 'c)) \EV \term{false}
  3127. (equalp (cons 'a 'b) (cons 'a 'b)) \EV \term{true}
  3128. (equalp #\\A #\\A) \EV \term{true}
  3129. (equalp #\\A #\\a) \EV \term{true}
  3130. (equalp "Foo" "Foo") \EV \term{true}
  3131. (equalp "Foo" (copy-seq "Foo")) \EV \term{true}
  3132. (equalp "FOO" "foo") \EV \term{true}
  3133. \endcode
  3134. \code
  3135. (setq array1 (make-array 6 :element-type 'integer
  3136. :initial-contents '(1 1 1 3 5 7)))
  3137. \EV #(1 1 1 3 5 7)
  3138. (setq array2 (make-array 8 :element-type 'integer
  3139. :initial-contents '(1 1 1 3 5 7 2 6)
  3140. :fill-pointer 6))
  3141. \EV #(1 1 1 3 5 7)
  3142. (equalp array1 array2) \EV \term{true}
  3143. (setq vector1 (vector 1 1 1 3 5 7)) \EV #(1 1 1 3 5 7)
  3144. (equalp array1 vector1) \EV \term{true}
  3145. \endcode
  3146. \label Side Effects:\None.
  3147. \label Affected By:\None.
  3148. \label Exceptional Situations:\None.
  3149. \label See Also::
  3150. \funref{eq}, \funref{eql}, \funref{equal}, \funref{=},
  3151. \funref{string=}, \funref{string-equal}, \funref{char=},
  3152. \funref{char-equal}
  3153. \label Notes::
  3154. \issue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3155. \term{Object} equality is not a concept for which there is a uniquely
  3156. determined correct algorithm. The appropriateness of an equality
  3157. predicate can be judged only in the context of the needs of some
  3158. particular program. Although these functions take any type of
  3159. argument and their names sound very generic,
  3160. \funref{equal} and \funref{equalp} are
  3161. not appropriate for every application.
  3162. \endissue{EQUAL-STRUCTURE:MAYBE-STATUS-QUO}
  3163. \endcom
  3164. %%% ========== IDENTITY
  3165. \begincom{identity}\ftype{Function}
  3166. \label Syntax::
  3167. \DefunWithValues identity {object} {object}
  3168. \label Arguments and Values::
  3169. \param{object}---an \term{object}.
  3170. \label Description::
  3171. %% 25.5.0 2
  3172. Returns its argument \param{object}.
  3173. \label Examples::
  3174. \code
  3175. (identity 101) \EV 101
  3176. (mapcan #'identity (list (list 1 2 3) '(4 5 6))) \EV (1 2 3 4 5 6)
  3177. \endcode
  3178. \label Side Effects:\None!
  3179. \label Affected By:\None!
  3180. \label Exceptional Situations:\None!
  3181. \label See Also:\None.
  3182. \label Notes::
  3183. \funref{identity} is intended for use with functions that require
  3184. a \term{function} as an argument.
  3185. \f{(eql x (identity x))} returns \term{true} for all possible values of \param{x},
  3186. but \f{(eq x (identity x))} might return \term{false} when \param{x} is a \term{number}
  3187. or \term{character}.
  3188. \funref{identity} could be defined by
  3189. \code
  3190. (defun identity (x) x)
  3191. \endcode
  3192. \endcom
  3193. %-------------------- Functional Composition --------------------
  3194. %%% ========== COMPLEMENT
  3195. \begincom{complement}\ftype{Function}
  3196. \issue{FUNCTION-COMPOSITION:JAN89-X3J13}
  3197. \label Syntax::
  3198. \DefunWithValues complement {function} {complement-function}
  3199. \label Arguments and Values::
  3200. \param{function}---a \term{function}.
  3201. \param{complement-function}---a \term{function}.
  3202. \label Description::
  3203. Returns a \term{function} that
  3204. takes the same \term{arguments} as \param{function},
  3205. and has the same side-effect behavior as \param{function},
  3206. but returns only a single value:
  3207. a \term{generalized boolean} with the opposite truth value of that
  3208. which would be returned as the \term{primary value} of \param{function}.
  3209. That is, when the \param{function} would have returned
  3210. \term{true} as its \term{primary value}
  3211. the \param{complement-function} returns \term{false},
  3212. and when the \param{function} would have returned
  3213. \term{false} as its \term{primary value}
  3214. the \param{complement-function} returns \term{true}.
  3215. \label Examples::
  3216. \code
  3217. (funcall (complement #'zerop) 1) \EV \term{true}
  3218. (funcall (complement #'characterp) #\\A) \EV \term{false}
  3219. (funcall (complement #'member) 'a '(a b c)) \EV \term{false}
  3220. (funcall (complement #'member) 'd '(a b c)) \EV \term{true}
  3221. \endcode
  3222. \label Side Effects:\None.
  3223. \label Affected By:\None.
  3224. \label Exceptional Situations:\None.
  3225. \label See Also::
  3226. \funref{not}
  3227. \label Notes::
  3228. \code
  3229. (complement \i{x}) \EQ #'(lambda (&rest arguments) (not (apply \i{x} arguments)))
  3230. \endcode
  3231. In \clisp, functions with names like ``\f{\i{xxx}-if-not}''
  3232. are related to functions with names like ``\f{{\it xxx}-if}''
  3233. in that
  3234. \code
  3235. (\i{xxx}-if-not \i{f} . \i{arguments}) \EQ (\i{xxx}-if (complement \i{f}) . \i{arguments})
  3236. \endcode
  3237. For example,
  3238. \code
  3239. (find-if-not #'zerop '(0 0 3)) \EQ
  3240. (find-if (complement #'zerop) '(0 0 3)) \EV 3
  3241. \endcode
  3242. Note that since the ``\f{\i{xxx}-if-not}'' \term{functions}
  3243. and the \kwd{test-not} arguments have been deprecated,
  3244. uses of ``\f{\i{xxx}-if}'' \term{functions} or
  3245. \kwd{test} arguments with \funref{complement} are preferred.
  3246. \endissue{FUNCTION-COMPOSITION:JAN89-X3J13}
  3247. \endcom
  3248. %%% ========== CONSTANTLY
  3249. \begincom{constantly}\ftype{Function}
  3250. \issue{FUNCTION-COMPOSITION:JAN89-X3J13}
  3251. \label Syntax::
  3252. \DefunWithValues constantly {value} {function}
  3253. \label Arguments and Values::
  3254. \param{value}---an \term{object}.
  3255. \param{function}---a \term{function}.
  3256. \label Description::
  3257. \funref{constantly} returns a \term{function} that accepts any number of
  3258. arguments, that has no side-effects, and that always returns \param{value}.
  3259. \label Examples::
  3260. \code
  3261. (mapcar (constantly 3) '(a b c d)) \EV (3 3 3 3)
  3262. (defmacro with-vars (vars &body forms)
  3263. `((lambda ,vars ,@forms) ,@(mapcar (constantly nil) vars)))
  3264. \EV WITH-VARS
  3265. (macroexpand '(with-vars (a b) (setq a 3 b (* a a)) (list a b)))
  3266. \EV ((LAMBDA (A B) (SETQ A 3 B (* A A)) (LIST A B)) NIL NIL), \term{true}
  3267. \endcode
  3268. \label Affected By:\None.
  3269. \label Exceptional Situations:\None.
  3270. \label See Also::
  3271. %% "not" => "identity" per Boyer/Kaufmann/Moore #10 (by X3J13 vote at May 4-5, 1994 meeting)
  3272. %% -kmp 9-May-94
  3273. \funref{identity}
  3274. \label Notes::
  3275. \funref{constantly} could be defined by:
  3276. \code
  3277. (defun constantly (object)
  3278. #'(lambda (&rest arguments) object))
  3279. \endcode
  3280. \endissue{FUNCTION-COMPOSITION:JAN89-X3J13}
  3281. \endcom
  3282. %-------------------- Boolean Composition --------------------
  3283. %%% ========== EVERY
  3284. %%% ========== SOME
  3285. %%% ========== NOTEVERY
  3286. %%% ========== NOTANY
  3287. \begincom{every, some, notevery, notany}\ftype{Function}
  3288. \label Syntax::
  3289. %Moon: "result"=>"boolean" in NOTEVERY
  3290. \DefunWithValues every {predicate {\rest} \plus{sequences}} {generalized-boolean}
  3291. \DefunWithValues some {predicate {\rest} \plus{sequences}} {result}
  3292. \DefunWithValues notevery {predicate {\rest} \plus{sequences}} {generalized-boolean}
  3293. \DefunWithValues notany {predicate {\rest} \plus{sequences}} {generalized-boolean}
  3294. \label Arguments and Values::
  3295. \param{predicate}---a \term{designator} for a \term{function} of
  3296. as many \term{arguments} as there are \param{sequences}.
  3297. \param{sequence}---a \term{sequence}.
  3298. \param{result}---an \term{object}.
  3299. \param{generalized-boolean}---a \term{generalized boolean}.
  3300. \label Description::
  3301. %% 14.2.0 10
  3302. %% 14.2.0 11
  3303. \funref{every}, \funref{some}, \funref{notevery}, and \funref{notany}
  3304. test \term{elements} of \param{sequences} for satisfaction of a given \param{predicate}.
  3305. %% Redundant with arg info.
  3306. % These \term{functions}
  3307. % operate on as many \param{sequences} as the given \param{predicate}
  3308. % takes \term{arguments}.
  3309. The first argument to \param{predicate} is an \term{element} of the first \param{sequence};
  3310. each succeeding argument is an \term{element} of a succeeding \param{sequence}.
  3311. \param{Predicate} is first applied to the elements
  3312. with index \f{0} in each of the \param{sequences}, and possibly then to
  3313. the elements with index \f{1}, and so on, until a termination
  3314. criterion is met or the end of the shortest of the \param{sequences} is reached.
  3315. %% 14.2.0 13
  3316. \funref{every} returns \term{false} as soon
  3317. as any invocation of \param{predicate} returns \term{false}.
  3318. If the end of a \param{sequence} is reached,
  3319. \funref{every} returns \term{true}.
  3320. Thus, \funref{every} returns \term{true} if and only if
  3321. every invocation of \param{predicate} returns \term{true}.
  3322. \funref{some} returns the first \term{non-nil} value
  3323. which is returned by an invocation of \param{predicate}.
  3324. If the end of a \param{sequence} is reached without any invocation of the
  3325. \param{predicate} returning \term{true}, \funref{some} returns \term{false}.
  3326. Thus, \funref{some} returns \term{true} if and only if
  3327. some invocation of \param{predicate} returns \term{true}.
  3328. %% 14.2.0 14
  3329. \funref{notany} returns \term{false}
  3330. as soon as any invocation of \param{predicate} returns \term{true}.
  3331. If the end of a \param{sequence} is reached,
  3332. \funref{notany} returns \term{true}.
  3333. Thus, \funref{notany} returns \term{true} if and only if
  3334. it is not the case that any invocation of \param{predicate} returns \term{true}.
  3335. %% 14.2.0 15
  3336. \funref{notevery} returns \term{true} as soon as any invocation of
  3337. \param{predicate} returns \term{false}.
  3338. If the end of a \param{sequence} is reached,
  3339. \funref{notevery} returns \term{false}.
  3340. Thus, \funref{notevery} returns \term{true} if and only if
  3341. it is not the case that every invocation of \param{predicate} returns \term{true}.
  3342. \label Examples::
  3343. \code
  3344. (every #'characterp "abc") \EV \term{true}
  3345. (some #'= '(1 2 3 4 5) '(5 4 3 2 1)) \EV \term{true}
  3346. (notevery #'< '(1 2 3 4) '(5 6 7 8) '(9 10 11 12)) \EV \term{false}
  3347. (notany #'> '(1 2 3 4) '(5 6 7 8) '(9 10 11 12)) \EV \term{true}
  3348. \endcode
  3349. \label Affected By:\None.
  3350. \label Exceptional Situations::
  3351. Should signal \typeref{type-error} if its first argument is neither a
  3352. \term{symbol} nor a \term{function} or if any subsequent
  3353. argument is not a \term{proper sequence}.
  3354. Other exceptional situations are possible, depending on the nature
  3355. of the \param{predicate}.
  3356. \label See Also::
  3357. \macref{and},
  3358. \macref{or},
  3359. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3360. {\secref\TraversalRules}
  3361. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3362. \label Notes::
  3363. \code
  3364. (notany \param{predicate} \starparam{sequence}) \EQ (not (some \param{predicate} \starparam{sequence}))
  3365. (notevery \param{predicate} \starparam{sequence}) \EQ (not (every \param{predicate} \starparam{sequence}))
  3366. \endcode
  3367. \endcom
  3368. %-------------------- Conditionals --------------------
  3369. %%% ========== AND
  3370. \begincom{and}\ftype{Macro}
  3371. \label Syntax::
  3372. \DefmacWithValues and {\starparam{form}} {\starparam{result}}
  3373. \label Arguments and Values::
  3374. \param{form}---a \term{form}.
  3375. %!!! Look more at this.
  3376. \param{results}---the \term{values} resulting from the evaluation of
  3377. the last \param{form}, or the symbols \nil\ or \t.
  3378. \label Description::
  3379. %% 6.4.0 5
  3380. The macro \macref{and} evaluates each \param{form} one at a time from left to right.
  3381. As soon as any \param{form} evaluates to \nil, \macref{and} returns
  3382. \nil\ without evaluating the remaining \param{forms}. If all \param{forms}
  3383. but the last evaluate to \term{true} values, \macref{and} returns the results
  3384. produced by evaluating the last \param{form}.
  3385. If no \param{forms} are supplied, \f{(and)} returns \t.
  3386. %% 7.9.2 9
  3387. \macref{and} passes back multiple values from the last \term{subform}
  3388. but not from subforms other than the last.
  3389. \label Examples::
  3390. \code
  3391. (if (and (>= n 0)
  3392. (< n (length a-simple-vector))
  3393. (eq (elt a-simple-vector n) 'foo))
  3394. (princ "Foo!"))
  3395. \endcode
  3396. The above expression prints \f{Foo!} if element \f{n} of \f{a-simple-vector}
  3397. is the symbol \f{foo}, provided also that \f{n} is indeed a valid index
  3398. for \f{a-simple-vector}. Because \macref{and} guarantees
  3399. left-to-right testing
  3400. of its parts, \funref{elt} is not called if \f{n} is out of range.
  3401. \code
  3402. (setq temp1 1 temp2 1 temp3 1) \EV 1
  3403. (and (incf temp1) (incf temp2) (incf temp3)) \EV 2
  3404. (and (eql 2 temp1) (eql 2 temp2) (eql 2 temp3)) \EV \term{true}
  3405. (decf temp3) \EV 1
  3406. (and (decf temp1) (decf temp2) (eq temp3 'nil) (decf temp3)) \EV NIL
  3407. (and (eql temp1 temp2) (eql temp2 temp3)) \EV \term{true}
  3408. (and) \EV T
  3409. \endcode
  3410. \label Affected By:\None.
  3411. \label Exceptional Situations:\None.
  3412. \label See Also::
  3413. \macref{cond},
  3414. \funref{every},
  3415. \specref{if},
  3416. \macref{or},
  3417. \macref{when}
  3418. \label Notes::
  3419. % The first example is wrong because it violates issue
  3420. % MACRO-SUBFORMS-TOP-LEVEL-P. --sjl 5 Mar 92
  3421. % \code
  3422. % (and \param{form}) \EQ \param{form}
  3423. % (and \param{form1} \param{form2} ...) \EQ (when \param{form1} (and \param{form2} ...))
  3424. %\endcode
  3425. \code
  3426. (and \param{form}) \EQ (let () \param{form})
  3427. (and \param{form1} \param{form2} ...) \EQ (when \param{form1} (and \param{form2} ...))
  3428. \endcode
  3429. \endcom
  3430. %%% ========== COND
  3431. \begincom{cond}\ftype{Macro}
  3432. \label Syntax::
  3433. %% 7.6.0 7
  3434. \DefmacWithValues cond
  3435. {\stardown{clause}}
  3436. {\starparam{result}}
  3437. \auxbnf{clause}{\paren{test-form \starparam{form}}}
  3438. \label Arguments and Values::
  3439. \param{test-form}---a \term{form}.
  3440. \param{forms}---an \term{implicit progn}.
  3441. \param{results}---the \term{values} of the \param{forms}
  3442. in the first \param{clause} whose \param{test-form} \term{yields} \term{true},
  3443. or the \term{primary value} of the \param{test-form}
  3444. if there are no \param{forms} in that \param{clause},
  3445. or else \nil\ if no \param{test-form} \term{yields} \term{true}.
  3446. \label Description::
  3447. \macref{cond} allows the execution of \param{forms} to be dependent
  3448. on \param{test-form}.
  3449. \param{Test-forms} are evaluated one at a time in the order in which
  3450. they are given in the argument list until a \param{test-form} is found that
  3451. evaluates to \term{true}.
  3452. %% 7.6.0 8
  3453. If there are no \term{forms} in that clause, the \term{primary value}
  3454. of the \param{test-form} is returned by the \macref{cond} \term{form}.
  3455. Otherwise, the \param{forms} associated with this \param{test-form} are
  3456. evaluated in order, left to right, as an \term{implicit progn}, and the
  3457. \term{values} returned by the last \param{form}
  3458. are returned by the \macref{cond} \term{form}.
  3459. Once one \param{test-form} has \term{yielded} \term{true},
  3460. no additional \param{test-forms} are \term{evaluated}.
  3461. If no \param{test-form} \term{yields} \term{true}, \nil\ is returned.
  3462. \label Examples::
  3463. \code
  3464. (defun select-options ()
  3465. (cond ((= a 1) (setq a 2))
  3466. ((= a 2) (setq a 3))
  3467. ((and (= a 3) (floor a 2)))
  3468. (t (floor a 3)))) \EV SELECT-OPTIONS
  3469. (setq a 1) \EV 1
  3470. (select-options) \EV 2
  3471. a \EV 2
  3472. (select-options) \EV 3
  3473. a \EV 3
  3474. (select-options) \EV 1
  3475. (setq a 5) \EV 5
  3476. (select-options) \EV 1, 2
  3477. \endcode
  3478. \label Side Effects:\None.
  3479. \label Affected By:\None.
  3480. \label Exceptional Situations:\None.
  3481. \label See Also::
  3482. \specref{if}, \macref{case}.
  3483. \label Notes:\None.
  3484. \endcom
  3485. %%% ========== IF
  3486. \begincom{if}\ftype{Special Operator}
  3487. \label Syntax::
  3488. \DefspecWithValues if
  3489. {\param{test-form} \param{then-form} \brac{\param{else-form}}}
  3490. {\starparam{result}}
  3491. \label Arguments and Values::
  3492. \param{Test-form}---a \term{form}.
  3493. \param{Then-form}---a \term{form}.
  3494. %% 7.6.0 4
  3495. \param{Else-form}---a \term{form}.
  3496. \Default{\nil}
  3497. %% 7.9.2 7
  3498. %% 7.9.2 8
  3499. \param{results}---if the \param{test-form} \term{yielded} \term{true},
  3500. the \term{values} returned by the \param{then-form}; otherwise,
  3501. the \term{values} returned by the \param{else-form}.
  3502. \label Description::
  3503. \specref{if} allows the execution of a \term{form} to be dependent
  3504. on a single \param{test-form}.
  3505. %% 7.6.0 3
  3506. First \param{test-form} is evaluated.
  3507. If the result is \term{true}, then \param{then-form} is selected;
  3508. otherwise \param{else-form} is selected.
  3509. Whichever form is selected is then evaluated.
  3510. \label Examples::
  3511. \code
  3512. (if t 1) \EV 1
  3513. (if nil 1 2) \EV 2
  3514. (defun test ()
  3515. (dolist (truth-value '(t nil 1 (a b c)))
  3516. (if truth-value (print 'true) (print 'false))
  3517. (prin1 truth-value))) \EV TEST
  3518. (test)
  3519. \OUT TRUE T
  3520. \OUT FALSE NIL
  3521. \OUT TRUE 1
  3522. \OUT TRUE (A B C)
  3523. \EV NIL
  3524. \endcode
  3525. \label Affected By:\None.
  3526. \label Exceptional Situations:\None.
  3527. \label See Also::
  3528. \macref{cond},
  3529. \macref{unless},
  3530. \macref{when}
  3531. \label Notes::
  3532. %!!! Barmar thinks we should encourage implementations to signal an error or issue a
  3533. % warning if additional subforms are detected.
  3534. \code
  3535. (if \param{test-form} \param{then-form} \param{else-form})
  3536. \EQ (cond (\param{test-form} \param{then-form}) (t \param{else-form}))
  3537. \endcode
  3538. \endcom
  3539. %%% ========== OR
  3540. \begincom{or}\ftype{Macro}
  3541. \label Syntax::
  3542. \DefmacWithValues or {\starparam{form}} {\starparam{results}}
  3543. \label Arguments and Values::
  3544. \param{form}---a \term{form}.
  3545. %!!! Look more at this.
  3546. \param{results}---the \term{values} or \term{primary value} (see below)
  3547. resulting from the evaluation of
  3548. the last \param{form} executed or \nil.
  3549. \label Description::
  3550. %% 6.4.0 11
  3551. \macref{or} evaluates each \param{form}, one at a time, from left to right.
  3552. The evaluation of all \param{forms} terminates when a \param{form} evaluates
  3553. to \term{true} (\ie something other than \nil).
  3554. If the \term{evaluation} of any \param{form} other than the last returns a
  3555. \term{primary value} that is \term{true}, \macref{or} immediately returns
  3556. that \term{value} (but no additional \term{values}) without evaluating the
  3557. remaining \param{forms}.
  3558. If every \param{form} but the last returns \term{false} as its \term{primary value},
  3559. \macref{or} returns all \term{values} returned by the last \param{form}.
  3560. If no \param{forms} are supplied, \macref{or} returns \nil.
  3561. % I've rewritten the above so that this is now implied. -kmp 1-Jan-91
  3562. % %% 7.9.2 9
  3563. % \macref{or} returns multiple values from
  3564. % the last \param{form}
  3565. % but not from \param{forms} other than the last.
  3566. \label Examples::
  3567. \code
  3568. (or) \EV NIL
  3569. (setq temp0 nil temp1 10 temp2 20 temp3 30) \EV 30
  3570. (or temp0 temp1 (setq temp2 37)) \EV 10
  3571. temp2 \EV 20
  3572. (or (incf temp1) (incf temp2) (incf temp3)) \EV 11
  3573. temp1 \EV 11
  3574. temp2 \EV 20
  3575. temp3 \EV 30
  3576. (or (values) temp1) \EV 11
  3577. (or (values temp1 temp2) temp3) \EV 11
  3578. (or temp0 (values temp1 temp2)) \EV 11, 20
  3579. (or (values temp0 temp1) (values temp2 temp3)) \EV 20, 30
  3580. \endcode
  3581. \label Side Effects:\None.
  3582. \label Affected By:\None.
  3583. \label Exceptional Situations:\None.
  3584. \label See Also::
  3585. \macref{and},
  3586. \macref{some},
  3587. \macref{unless}
  3588. \label Notes:\None.
  3589. \endcom
  3590. %%% ========== WHEN
  3591. \begincom{when, unless}\ftype{Macro}
  3592. \label Syntax::
  3593. \DefmacWithValues when
  3594. {test-form \starparam{form}}
  3595. {\starparam{result}}
  3596. \DefmacWithValues unless
  3597. {test-form \starparam{form}}
  3598. {\starparam{result}}
  3599. \label Arguments and Values::
  3600. \param{test-form}---a \term{form}.
  3601. \param{forms}---an \term{implicit progn}.
  3602. \param{results}---the \term{values} of the \term{forms}
  3603. in a \macref{when} \term{form} if the \param{test-form} \term{yields} \term{true}
  3604. or in an \macref{unless} \term{form} if the \param{test-form} \term{yields} \term{false};
  3605. otherwise \nil.
  3606. \label Description::
  3607. \macref{when} and \macref{unless} allow the execution of \param{forms}
  3608. to be dependent on a single \param{test-form}.
  3609. %% 7.6.0 5
  3610. In a \macref{when} \term{form},
  3611. if the \param{test-form} \term{yields} \term{true},
  3612. the \param{forms} are \term{evaluated} in order from left to right
  3613. and the \term{values} returned by the \param{forms}
  3614. are returned from the \macref{when} \term{form}.
  3615. Otherwise, if the \param{test-form} \term{yields} \term{false},
  3616. the \param{forms} are not \term{evaluated},
  3617. and the \macref{when} \term{form} returns \nil.
  3618. %% 7.6.0 6
  3619. In an \macref{unless} \term{form},
  3620. if the \param{test-form} \term{yields} \term{false},
  3621. the \param{forms} are \term{evaluated} in order from left to right
  3622. and the \term{values} returned by the \param{forms}
  3623. are returned from the \macref{unless} \term{form}.
  3624. Otherwise, if the \param{test-form} \term{yields} \term{false},
  3625. the \param{forms} are not \term{evaluated},
  3626. and the \macref{unless} \term{form} returns \nil.
  3627. \label Examples::
  3628. \code
  3629. (when t 'hello) \EV HELLO
  3630. (unless t 'hello) \EV NIL
  3631. (when nil 'hello) \EV NIL
  3632. (unless nil 'hello) \EV HELLO
  3633. (when t) \EV NIL
  3634. (unless nil) \EV NIL
  3635. (when t (prin1 1) (prin1 2) (prin1 3))
  3636. \OUT 123
  3637. \EV 3
  3638. (unless t (prin1 1) (prin1 2) (prin1 3)) \EV NIL
  3639. (when nil (prin1 1) (prin1 2) (prin1 3)) \EV NIL
  3640. (unless nil (prin1 1) (prin1 2) (prin1 3))
  3641. \OUT 123
  3642. \EV 3
  3643. (let ((x 3))
  3644. (list (when (oddp x) (incf x) (list x))
  3645. (when (oddp x) (incf x) (list x))
  3646. (unless (oddp x) (incf x) (list x))
  3647. (unless (oddp x) (incf x) (list x))
  3648. (if (oddp x) (incf x) (list x))
  3649. (if (oddp x) (incf x) (list x))
  3650. (if (not (oddp x)) (incf x) (list x))
  3651. (if (not (oddp x)) (incf x) (list x))))
  3652. \EV ((4) NIL (5) NIL 6 (6) 7 (7))
  3653. \endcode
  3654. \label Side Effects:\None.
  3655. \label Affected By:\None.
  3656. \label Exceptional Situations:\None.
  3657. \label See Also::
  3658. \macref{and},
  3659. \macref{cond},
  3660. \macref{if},
  3661. \macref{or}
  3662. \label Notes::
  3663. \code
  3664. (when \param{test} \plus{\curly{\param{form}}}) \EQ (and \param{test} (progn \plus{\curly{\param{form}}}))
  3665. (when \param{test} \plus{\curly{\param{form}}}) \EQ (cond (\param{test} \plus{\curly{\param{form}}}))
  3666. (when \param{test} \plus{\curly{\param{form}}}) \EQ (if \param{test} (progn \plus{\curly{\param{form}}}) nil)
  3667. (when \param{test} \plus{\curly{\param{form}}}) \EQ (unless (not \param{test}) \plus{\curly{\param{form}}})
  3668. (unless \param{test} \plus{\curly{\param{form}}}) \EQ (cond ((not \param{test}) \plus{\curly{\param{form}}}))
  3669. (unless \param{test} \plus{\curly{\param{form}}}) \EQ (if \param{test} nil (progn \plus{\curly{\param{form}}}))
  3670. (unless \param{test} \plus{\curly{\param{form}}}) \EQ (when (not \param{test}) \plus{\curly{\param{form}}})
  3671. \endcode
  3672. \endcom
  3673. %-------------------- Dispatch --------------------
  3674. %%% ========== CASE
  3675. %%% ========== CCASE
  3676. %%% ========== ECASE
  3677. %%% ========== OTHERWISE
  3678. %%% ========== T
  3679. \begincom{case, ccase, ecase}\ftype{Macro}
  3680. \label Syntax::
  3681. \DefmacWithValues case
  3682. {keyform \stardown{normal-clause} \brac{\down{otherwise-clause}}}
  3683. {\starparam{result}}
  3684. \DefmacWithValues ccase
  3685. {keyplace \stardown{normal-clause}}
  3686. {\starparam{result}}
  3687. \DefmacWithValues ecase
  3688. {keyform \stardown{normal-clause}}
  3689. {\starparam{result}}
  3690. \auxbnf{normal-clause}{\paren{keys \starparam{form}}}
  3691. \auxbnf{otherwise-clause}{\paren{\curly{otherwise | t} \starparam{form}}}
  3692. \auxbnf{clause}{normal-clause | otherwise-clause}
  3693. \idxref{otherwise}\idxref{t}
  3694. \label Arguments and Values::
  3695. %% 7.6.0 13
  3696. %% 7.6.0 14
  3697. \param{keyform}---a \term{form}; evaluated to produce a \param{test-key}.
  3698. \param{keyplace}---a \term{form}; evaluated initially to produce a \param{test-key}.
  3699. Possibly also used later as a \term{place} if no \param{keys} match.
  3700. \param{test-key}---an object produced by evaluating \param{keyform} or \param{keyplace}.
  3701. \param{keys}---a \term{designator} for a \term{list} of \term{objects}.
  3702. In the case of \macref{case}, the \term{symbols} \t\ and \misc{otherwise} may
  3703. not be used as the \param{keys} \term{designator}. To refer to these \term{symbols}
  3704. by themselves as \param{keys}, the designators \f{(t)} and \f{(otherwise)}, respectively,
  3705. must be used instead.
  3706. \param{forms}---an \term{implicit progn}.
  3707. \param{results}---the \term{values} returned by the \param{forms}
  3708. in the matching \param{clause}.
  3709. \label Description::
  3710. %% 7.6.0 11
  3711. These \term{macros} allow the conditional execution of a body of \param{forms}
  3712. in a \param{clause} that is selected by matching the \param{test-key} on the
  3713. basis of its identity.
  3714. %% 7.6.0 12
  3715. The \param{keyform} or \param{keyplace} is \term{evaluated} to produce the
  3716. \param{test-key}.
  3717. Each of the \param{normal-clauses} is then considered in turn.
  3718. If the \param{test-key} is the \term{same} as any \term{key} for
  3719. that \param{clause}, the \param{forms} in that \param{clause} are
  3720. \param{evaluated} as an \term{implicit progn}, and the \term{values}
  3721. it returns are returned as the value of the \macref{case},
  3722. \macref{ccase}, or \macref{ecase} \term{form}.
  3723. These \term{macros} differ only in their \term{behavior} when
  3724. no \param{normal-clause} matches; specifically:
  3725. \beginlist
  3726. \itemitem{\macref{case}}
  3727. If no \param{normal-clause} matches, and there is an \param{otherwise-clause},
  3728. then that \param{otherwise-clause} automatically matches; the \param{forms} in
  3729. that \param{clause} are \param{evaluated} as an \term{implicit progn},
  3730. and the \term{values} it returns are returned as the value of the \macref{case}.
  3731. If there is no \param{otherwise-clause}, \macref{case} returns \nil.
  3732. \itemitem{\macref{ccase}}
  3733. %% 7.6.0 15
  3734. If no \param{normal-clause} matches,
  3735. a \term{correctable} \term{error} \oftype{type-error} is signaled.
  3736. The offending datum is the \param{test-key} and
  3737. the expected type is \term{type equivalent} to \f{(member \param{key1} \param{key2} ...)}.
  3738. \Therestart{store-value} can be used to correct the error.
  3739. If \therestart{store-value} is invoked, its \term{argument} becomes the
  3740. new \param{test-key}, and is stored in \param{keyplace} as if by
  3741. \f{(setf \param{keyplace} \param{test-key})}.
  3742. Then \macref{ccase} starts over, considering each \param{clause} anew.
  3743. \reviewer{Barmar: Will it prompt for multiple values if keyplace is a VALUES general ref?}%!!!
  3744. The subforms of \param{keyplace} might be evaluated again if
  3745. none of the cases holds.
  3746. \itemitem{\macref{ecase}}
  3747. If no \param{normal-clause} matches,
  3748. a \term{non-correctable} \term{error} \oftype{type-error} is signaled.
  3749. The offending datum is the \param{test-key} and
  3750. the expected type is \term{type equivalent} to \f{(member \param{key1} \param{key2} ...)}.
  3751. Note that in contrast with \macref{ccase},
  3752. the caller of \macref{ecase} may rely on the fact that \macref{ecase}
  3753. does not return if a \param{normal-clause} does not match.
  3754. \endlist
  3755. \label Examples::
  3756. \code
  3757. (dolist (k '(1 2 3 :four #\\v () t 'other))
  3758. (format t "~S "
  3759. (case k ((1 2) 'clause1)
  3760. (3 'clause2)
  3761. (nil 'no-keys-so-never-seen)
  3762. ((nil) 'nilslot)
  3763. ((:four #\\v) 'clause4)
  3764. ((t) 'tslot)
  3765. (otherwise 'others))))
  3766. \OUT CLAUSE1 CLAUSE1 CLAUSE2 CLAUSE4 CLAUSE4 NILSLOT TSLOT OTHERS
  3767. \EV NIL
  3768. (defun add-em (x) (apply #'+ (mapcar #'decode x)))
  3769. \EV ADD-EM
  3770. (defun decode (x)
  3771. (ccase x
  3772. ((i uno) 1)
  3773. ((ii dos) 2)
  3774. ((iii tres) 3)
  3775. ((iv cuatro) 4)))
  3776. \EV DECODE
  3777. (add-em '(uno iii)) \EV 4
  3778. (add-em '(uno iiii))
  3779. \OUT Error: The value of X, IIII, is not I, UNO, II, DOS, III,
  3780. \OUT TRES, IV, or CUATRO.
  3781. \OUT 1: Supply a value to use instead.
  3782. \OUT 2: Return to Lisp Toplevel.
  3783. \OUT Debug> \IN{:CONTINUE 1}
  3784. \OUT Value to evaluate and use for X: \IN{'IV}
  3785. \EV 5
  3786. \endcode
  3787. \label Side Effects::
  3788. The debugger might be entered.
  3789. If \therestart{store-value} is invoked,
  3790. the \term{value} of \param{keyplace} might be changed.
  3791. \label Affected By::
  3792. \macref{ccase} and \macref{ecase}, since they might signal an error,
  3793. are potentially affected by existing \param{handlers} and \varref{*debug-io*}.
  3794. \label Exceptional Situations::
  3795. \macref{ccase} and \macref{ecase} signal an error \oftype{type-error}
  3796. if no \param{normal-clause} matches.
  3797. \label See Also::
  3798. \macref{cond},
  3799. \macref{typecase},
  3800. \macref{setf},
  3801. {\secref\GeneralizedReference}
  3802. \label Notes::
  3803. \code
  3804. (case \param{test-key}
  3805. \star{\curly{((\starparam{key}) \starparam{form})}})
  3806. \EQ
  3807. (let ((#1=#:g0001 \param{test-key}))
  3808. (cond \star{\curly{((member #1# '(\starparam{key})) \starparam{form})}}))
  3809. \endcode
  3810. The specific error message used by \macref{ecase} and \macref{ccase} can vary
  3811. between implementations. In situations where control of the specific wording
  3812. of the error message is important, it is better to use \macref{case} with an
  3813. \param{otherwise-clause} that explicitly signals an error with an appropriate
  3814. message.
  3815. \endcom
  3816. %%% ========== TYPECASE
  3817. %%% ========== CTYPECASE
  3818. %%% ========== ETYPECASE
  3819. %%% ========== OTHERWISE
  3820. %%% ========== T
  3821. \begincom{typecase, ctypecase, etypecase}\ftype{Macro}
  3822. \label Syntax::
  3823. \DefmacWithValues {typecase}
  3824. {keyform \stardown{normal-clause} \brac{\down{otherwise-clause}}}
  3825. {\starparam{result}}
  3826. \DefmacWithValues {ctypecase}
  3827. {keyplace \stardown{normal-clause}}
  3828. {\starparam{result}}
  3829. \DefmacWithValues {etypecase}
  3830. {keyform \stardown{normal-clause}}
  3831. {\starparam{result}}
  3832. \auxbnf{normal-clause}{\paren{type \starparam{form}}}
  3833. \auxbnf{otherwise-clause}{\paren{\curly{otherwise | t} \starparam{form}}}
  3834. \auxbnf{clause}{normal-clause | otherwise-clause}
  3835. \idxref{otherwise}\idxref{t}
  3836. \label Arguments and Values::
  3837. %% 7.6.0 13
  3838. %% 7.6.0 14
  3839. \param{keyform}---a \term{form}; evaluated to produce a \param{test-key}.
  3840. \param{keyplace}---a \term{form}; evaluated initially to produce a \param{test-key}.
  3841. Possibly also used later as a \term{place} if no \param{types} match.
  3842. \param{test-key}---an object produced by evaluating \param{keyform} or \param{keyplace}.
  3843. \param{type}---a \term{type specifier}.
  3844. \param{forms}---an \term{implicit progn}.
  3845. \param{results}---the \term{values} returned by the \param{forms}
  3846. in the matching \param{clause}.
  3847. \label Description::
  3848. %% 7.6.0 18
  3849. %% 7.6.0 19
  3850. %% 7.6.0 20
  3851. These \term{macros} allow the conditional execution of a body of \param{forms}
  3852. in a \param{clause} that is selected by matching the \param{test-key} on the basis
  3853. of its \term{type}.
  3854. The \param{keyform} or \param{keyplace} is \term{evaluated} to produce the
  3855. \param{test-key}.
  3856. Each of the \param{normal-clauses} is then considered in turn.
  3857. If the \param{test-key} is of the \term{type}
  3858. given by the \param{clauses}'s \param{type},
  3859. the \param{forms} in that \param{clause} are
  3860. \param{evaluated} as an \term{implicit progn}, and the \term{values}
  3861. it returns are returned as the value of the \macref{typecase},
  3862. \macref{ctypecase}, or \macref{etypecase} \term{form}.
  3863. These \term{macros} differ only in their \term{behavior} when
  3864. no \param{normal-clause} matches; specifically:
  3865. \beginlist
  3866. \itemitem{\macref{typecase}}
  3867. If no \param{normal-clause} matches, and there is an \param{otherwise-clause},
  3868. then that \param{otherwise-clause} automatically matches; the \param{forms} in
  3869. that \param{clause} are \param{evaluated} as an \term{implicit progn},
  3870. and the \term{values} it returns are returned as the value of the \macref{typecase}.
  3871. If there is no \param{otherwise-clause}, \macref{typecase} returns \nil.
  3872. \itemitem{\macref{ctypecase}}
  3873. If no \param{normal-clause} matches,
  3874. a \term{correctable} \term{error} \oftype{type-error} is signaled.
  3875. The offending datum is the \param{test-key} and
  3876. the expected type is \term{type equivalent} to \f{(or \param{type1} \param{type2} ...)}.
  3877. \Therestart{store-value} can be used to correct the error.
  3878. If \therestart{store-value} is invoked, its \term{argument} becomes the
  3879. new \param{test-key}, and is stored in \param{keyplace} as if by
  3880. \f{(setf \param{keyplace} \param{test-key})}.
  3881. Then \macref{ctypecase} starts over, considering each \param{clause} anew.
  3882. If \therestart{store-value} is invoked interactively,
  3883. the user is prompted for a new \param{test-key} to use.
  3884. The subforms of \param{keyplace} might be evaluated again if
  3885. none of the cases holds.
  3886. \itemitem{\macref{etypecase}}
  3887. If no \param{normal-clause} matches,
  3888. a \term{non-correctable} \term{error} \oftype{type-error} is signaled.
  3889. The offending datum is the \param{test-key} and
  3890. the expected type is \term{type equivalent} to \f{(or \param{type1} \param{type2} ...)}.
  3891. Note that in contrast with \macref{ctypecase},
  3892. the caller of \macref{etypecase} may rely on the fact that \macref{etypecase}
  3893. does not return if a \param{normal-clause} does not match.
  3894. \endlist
  3895. %% 7.6.0 22
  3896. In all three cases, is permissible for more than one \param{clause} to specify a
  3897. matching \term{type}, particularly if one is a \term{subtype} of another;
  3898. the earliest applicable \param{clause} is chosen.
  3899. \label Examples::
  3900. \code
  3901. ;;; (Note that the parts of this example which use TYPE-OF
  3902. ;;; are implementation-dependent.)
  3903. (defun what-is-it (x)
  3904. (format t "~&~S is ~A.~%"
  3905. x (typecase x
  3906. (float "a float")
  3907. (null "a symbol, boolean false, or the empty list")
  3908. (list "a list")
  3909. (t (format nil "a(n) ~(~A~)" (type-of x))))))
  3910. \EV WHAT-IS-IT
  3911. (map 'nil #'what-is-it '(nil (a b) 7.0 7 box))
  3912. \OUT NIL is a symbol, boolean false, or the empty list.
  3913. \OUT (A B) is a list.
  3914. \OUT 7.0 is a float.
  3915. \OUT 7 is a(n) integer.
  3916. \OUT BOX is a(n) symbol.
  3917. \EV NIL
  3918. (setq x 1/3)
  3919. \EV 1/3
  3920. (ctypecase x
  3921. (integer (* x 4))
  3922. (symbol (symbol-value x)))
  3923. \OUT Error: The value of X, 1/3, is neither an integer nor a symbol.
  3924. \OUT To continue, type :CONTINUE followed by an option number:
  3925. \OUT 1: Specify a value to use instead.
  3926. \OUT 2: Return to Lisp Toplevel.
  3927. \OUT Debug> \IN{:CONTINUE 1}
  3928. \OUT Use value: \IN{3.7}
  3929. \OUT Error: The value of X, 3.7, is neither an integer nor a symbol.
  3930. \OUT To continue, type :CONTINUE followed by an option number:
  3931. \OUT 1: Specify a value to use instead.
  3932. \OUT 2: Return to Lisp Toplevel.
  3933. \OUT Debug> \IN{:CONTINUE 1}
  3934. \OUT Use value: \IN{12}
  3935. \EV 48
  3936. x \EV 12
  3937. \endcode
  3938. \label Affected By::
  3939. \macref{ctypecase} and \macref{etypecase}, since they might signal an error,
  3940. are potentially affected by existing \param{handlers} and \varref{*debug-io*}.
  3941. \label Exceptional Situations::
  3942. \macref{ctypecase} and \macref{etypecase} signal an error \oftype{type-error}
  3943. if no \param{normal-clause} matches.
  3944. The \term{compiler} may choose to issue a warning \oftype{style-warning}
  3945. if a \param{clause} will never be selected because it is completely
  3946. shadowed by earlier clauses.
  3947. \label See Also::
  3948. \macref{case},
  3949. \macref{cond},
  3950. \macref{setf},
  3951. {\secref\GeneralizedReference}
  3952. \label Notes::
  3953. \code
  3954. (typecase \param{test-key}
  3955. \star{\curly{(\param{type} \starparam{form})}})
  3956. \EQ
  3957. (let ((#1=#:g0001 \param{test-key}))
  3958. (cond \star{\curly{((typep #1# '\param{type}) \starparam{form})}}))
  3959. \endcode
  3960. The specific error message used by \macref{etypecase} and \macref{ctypecase} can vary
  3961. between implementations. In situations where control of the specific wording
  3962. of the error message is important, it is better to use \macref{typecase} with an
  3963. \param{otherwise-clause} that explicitly signals an error with an appropriate
  3964. message.
  3965. \endcom
  3966. %-------------------- Multiple Values --------------------
  3967. %%% ========== MULTIPLE-VALUE-BIND
  3968. \begincom{multiple-value-bind}\ftype{Macro}
  3969. \issue{DECLS-AND-DOC}
  3970. \label Syntax::
  3971. \DefmacWithValuesNewline multiple-value-bind
  3972. {\paren{\starparam{var}}
  3973. \param{values-form}
  3974. \starparam{declaration}
  3975. \starparam{form}}
  3976. {\starparam{result}}
  3977. \label Arguments and Values::
  3978. \param{var}---a \term{symbol} naming a variable; \noeval.
  3979. \param{values-form}---a \term{form}; \eval.
  3980. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  3981. \param{forms}---an \term{implicit progn}.
  3982. \param{results}---the \term{values} returned by the \param{forms}.
  3983. \label Description::
  3984. Creates new variable \term{bindings} for the \param{vars} and
  3985. executes a series of \param{forms} that use these \term{bindings}.
  3986. The variable \term{bindings} created are lexical unless
  3987. \declref{special} declarations are specified.
  3988. %% 7.9.1 13
  3989. \param{Values-form} is evaluated, and each of the \param{vars} is
  3990. bound to the respective value returned by that \term{form}. If there are more
  3991. \param{vars} than values returned, extra values of \nil\ are given to the
  3992. remaining \param{vars}. If there are more values than
  3993. \param{vars}, the excess
  3994. values are discarded. The \param{vars} are bound to the values over
  3995. the execution of the \param{forms}, which make up an implicit \specref{progn}.
  3996. The consequences are unspecified if a type \param{declaration} is specified
  3997. for a \param{var}, but the value to which
  3998. that \param{var} is bound is not consistent with
  3999. the type \param{declaration}.
  4000. The \term{scopes} of the name binding and \param{declarations}
  4001. do not include the \param{values-form}.
  4002. % KMP: Surely this must refer only to bound declarations.
  4003. % Moon: No, the stupid DECLARATION-SCOPE:NO-HOISTING vote made it this way.
  4004. \label Examples::
  4005. \code
  4006. (multiple-value-bind (f r)
  4007. (floor 130 11)
  4008. (list f r)) \EV (11 9)
  4009. \endcode
  4010. \label Affected By:\None.
  4011. \label Exceptional Situations:\None.
  4012. \label See Also::
  4013. \specref{let},
  4014. \specref{multiple-value-call}
  4015. \label Notes::
  4016. \code
  4017. (multiple-value-bind (\starparam{var}) \param{values-form} \starparam{form})
  4018. \EQ (multiple-value-call #'(lambda (&optional \starparam{var} &rest #1=#:ignore)
  4019. (declare (ignore #1#))
  4020. \starparam{form})
  4021. \param{values-form})
  4022. \endcode
  4023. \endissue{DECLS-AND-DOC}
  4024. \endcom
  4025. %%% ========== MULTIPLE-VALUE-CALL
  4026. \begincom{multiple-value-call}\ftype{Special Operator}
  4027. \label Syntax::
  4028. \DefspecWithValues multiple-value-call
  4029. {\param{function-form} \star{\param{form}}}
  4030. {\starparam{result}}
  4031. \label Arguments and Values::
  4032. \param{function-form}---a \term{form}; evaluated to produce \param{function}.
  4033. \param{function}---a \term{function designator}
  4034. resulting from the evaluation of \param{function-form}.
  4035. \param{form}---a \term{form}.
  4036. %% 7.9.2 5
  4037. \param{results}---the \term{values} returned by the \param{function}.
  4038. \label Description::
  4039. Applies \param{function} to a \term{list} of the \term{objects} collected from groups of
  4040. \term{multiple values}\meaning{2}.
  4041. %% 7.9.1 11
  4042. \specref{multiple-value-call} first evaluates the \param{function-form}
  4043. to obtain \param{function}, and then evaluates each \param{form}.
  4044. All the values
  4045. of each \param{form} are gathered together (not just one value from each)
  4046. and given as arguments to the \param{function}.
  4047. \label Examples::
  4048. \code
  4049. (multiple-value-call #'list 1 '/ (values 2 3) '/ (values) '/ (floor 2.5))
  4050. \EV (1 / 2 3 / / 2 0.5)
  4051. (+ (floor 5 3) (floor 19 4)) \EQ (+ 1 4)
  4052. \EV 5
  4053. (multiple-value-call #'+ (floor 5 3) (floor 19 4)) \EQ (+ 1 2 4 3)
  4054. \EV 10
  4055. \endcode
  4056. \label Affected By:\None.
  4057. \label Exceptional Situations:\None.
  4058. \label See Also::
  4059. \macref{multiple-value-list}, \macref{multiple-value-bind}
  4060. \label Notes:\None.
  4061. \endcom
  4062. %%% ========== MULTIPLE-VALUE-LIST
  4063. \begincom{multiple-value-list}\ftype{Macro}
  4064. \label Syntax::
  4065. \DefmacWithValues multiple-value-list {form} {list}
  4066. \label Arguments and Values::
  4067. \param{form}---a \term{form}; \evalspecial.
  4068. \param{list}---a \term{list} of the \term{values} returned by \param{form}.
  4069. \label Description::
  4070. %% 7.9.1 10
  4071. \macref{multiple-value-list} evaluates \param{form}
  4072. and creates a \term{list} of the \term{multiple values}\meaning{2} it returns.
  4073. \label Examples::
  4074. \code
  4075. (multiple-value-list (floor -3 4)) \EV (-1 1)
  4076. \endcode
  4077. \label Side Effects:\None.
  4078. \label Affected By:\None.
  4079. \label Exceptional Situations:\None.
  4080. \label See Also::
  4081. \funref{values-list},
  4082. \specref{multiple-value-call}
  4083. \label Notes::
  4084. \macref{multiple-value-list} and \funref{values-list} are inverses
  4085. of each other.
  4086. \code
  4087. (multiple-value-list form) \EQ (multiple-value-call #'list form)
  4088. \endcode
  4089. \endcom
  4090. %%% ========== MULTIPLE-VALUE-PROG1
  4091. \begincom{multiple-value-prog1}\ftype{Special Operator}
  4092. \label Syntax::
  4093. \DefspecWithValues multiple-value-prog1
  4094. {first-form \starparam{form}}
  4095. {first-form-results}
  4096. \label Arguments and Values::
  4097. \param{first-form}---a \term{form}; \evalspecial.
  4098. \param{form}---a \term{form}; \evalspecial.
  4099. %% 7.9.2 17
  4100. \param{first-form-results}---the \term{values} resulting from
  4101. the \term{evaluation} of \param{first-form}.
  4102. \label Description::
  4103. %% 7.9.1 12
  4104. \macref{multiple-value-prog1} evaluates \param{first-form} and saves
  4105. all the values produced by that \term{form}. It then evaluates each
  4106. \param{form} from left to right, discarding their values.
  4107. \label Examples::
  4108. \code
  4109. (setq temp '(1 2 3)) \EV (1 2 3)
  4110. (multiple-value-prog1
  4111. (values-list temp)
  4112. (setq temp nil)
  4113. (values-list temp)) \EV 1, 2, 3
  4114. \endcode
  4115. \label Side Effects:\None.
  4116. \label Affected By:\None.
  4117. \label Exceptional Situations:\None.
  4118. \label See Also::
  4119. \macref{prog1}
  4120. \label Notes:\None.
  4121. \endcom
  4122. %%% ========== MULTIPLE-VALUE-SETQ
  4123. \begincom{multiple-value-setq}\ftype{Macro}
  4124. \label Syntax::
  4125. \DefmacWithValues multiple-value-setq {vars form} {result}
  4126. \label Arguments and Values::
  4127. \param{vars}---a \term{list} of \term{symbols}
  4128. that are either \term{variable} \term{names}
  4129. or \term{names} of \term{symbol macros}.
  4130. \param{form}---a \term{form}.
  4131. %% 7.9.1 17
  4132. \param{result}---The \term{primary value} returned by the \param{form}.
  4133. \label Description::
  4134. \macref{multiple-value-setq} assigns values to \param{vars}.
  4135. %% 7.9.1 15
  4136. The \param{form} is evaluated,
  4137. and each \param{var} is \term{assigned}
  4138. to the corresponding \term{value} returned by that \term{form}.
  4139. If there are more \param{vars} than \term{values} returned,
  4140. \nil\ is \term{assigned} to the extra \param{vars}.
  4141. If there are more \term{values} than \param{vars},
  4142. the extra \term{values} are discarded.
  4143. \issue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  4144. If any \param{var} is the \term{name} of a \term{symbol macro},
  4145. then it is \term{assigned} as if by \macref{setf}. Specifically,
  4146. \issue{MULTIPLE-VALUE-SETQ-ORDER:LIKE-SETF-OF-VALUES}
  4147. \begingroup
  4148. \def\subOne{$\sub1$}
  4149. \def\subN{$\sub{n}$}
  4150. \code
  4151. (multiple-value-setq (\i{symbol}\subOne ... \i{symbol}\subN) \i{value-producing-form})
  4152. \endcode
  4153. is defined to always behave in the same way as
  4154. \code
  4155. (values (setf (values \i{symbol}\subOne ... \i{symbol}\subN) \i{value-producing-form}))
  4156. \endcode
  4157. \endgroup
  4158. in order that the rules for order of evaluation and side-effects be consistent
  4159. with those used by \macref{setf}.\idxtext{order of evaluation}\idxtext{evaluation order}
  4160. % added --sjl 4 Mar 92
  4161. \Seesection\SETFofVALUES.
  4162. \endissue{MULTIPLE-VALUE-SETQ-ORDER:LIKE-SETF-OF-VALUES}
  4163. \endissue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  4164. \label Examples::
  4165. \code
  4166. (multiple-value-setq (quotient remainder) (truncate 3.2 2)) \EV 1
  4167. quotient \EV 1
  4168. remainder \EV 1.2
  4169. (multiple-value-setq (a b c) (values 1 2)) \EV 1
  4170. a \EV 1
  4171. b \EV 2
  4172. c \EV NIL
  4173. (multiple-value-setq (a b) (values 4 5 6)) \EV 4
  4174. a \EV 4
  4175. b \EV 5
  4176. \endcode
  4177. \label Side Effects:\None.
  4178. \label Affected By:\None.
  4179. \label Exceptional Situations:\None.
  4180. \label See Also::
  4181. \specref{setq},
  4182. \specref{symbol-macrolet}
  4183. \label Notes:\None.
  4184. \endcom
  4185. %%% ========== VALUES
  4186. % incorporated issue SETF-OF-VALUES --sjl 4 Mar 92
  4187. \begincom{values}\ftype{Accessor}
  4188. \label Syntax::
  4189. \DefunWithValues values {{\rest} object} {\starparam{object}}
  4190. \issue{SETF-OF-VALUES:ADD}
  4191. \Defsetf values {{\rest} place} {new-values}
  4192. \endissue{SETF-OF-VALUES:ADD}
  4193. \label Arguments and Values::
  4194. \param{object}---an \term{object}.
  4195. \issue{SETF-OF-VALUES:ADD}
  4196. \param{place}---a \term{place}.
  4197. \param{new-value}---an \term{object}.
  4198. \endissue{SETF-OF-VALUES:ADD}
  4199. \label Description::
  4200. %% 7.9.1 4
  4201. %% 7.9.1 5
  4202. \funref{values}
  4203. returns the \param{objects} as \term{multiple values}\meaning{2}.
  4204. \issue{SETF-OF-VALUES:ADD}
  4205. \macref{setf} of \funref{values} is used to store the
  4206. \term{multiple values}\meaning{2} \param{new-values} into the \param{places}.
  4207. \Seesection\SETFofVALUES.
  4208. \endissue{SETF-OF-VALUES:ADD}
  4209. \label Examples::
  4210. \code
  4211. (values) \EV \novalues
  4212. (values 1) \EV 1
  4213. (values 1 2) \EV 1, 2
  4214. (values 1 2 3) \EV 1, 2, 3
  4215. (values (values 1 2 3) 4 5) \EV 1, 4, 5
  4216. (defun polar (x y)
  4217. (values (sqrt (+ (* x x) (* y y))) (atan y x))) \EV POLAR
  4218. (multiple-value-bind (r theta) (polar 3.0 4.0)
  4219. (vector r theta))
  4220. \EV #(5.0 0.927295)
  4221. \endcode
  4222. %% 7.9.1 6
  4223. Sometimes it is desirable to indicate explicitly that a function returns
  4224. exactly one value. For example, the function
  4225. \code
  4226. (defun foo (x y)
  4227. (floor (+ x y) y)) \EV FOO
  4228. \endcode
  4229. returns two values because \funref{floor} returns
  4230. two values. It may be that the second value makes no sense,
  4231. or that for efficiency reasons it is desired not to compute the
  4232. second value. \funref{values} is the standard idiom
  4233. for indicating that only one value is to be returned:
  4234. \code
  4235. (defun foo (x y)
  4236. (values (floor (+ x y) y))) \EV FOO
  4237. \endcode
  4238. This works because \funref{values}
  4239. returns exactly one value for each of
  4240. \param{args}; as for any function call,
  4241. if any of \param{args} produces more than one value, all but the
  4242. first are discarded.
  4243. \label Affected By:\None!
  4244. \label Exceptional Situations:\None!
  4245. \label See Also::
  4246. \funref{values-list},
  4247. \macref{multiple-value-bind},
  4248. \conref{multiple-values-limit},
  4249. {\secref\Evaluation}
  4250. \label Notes::
  4251. Since \funref{values} is a \term{function}, not a \term{macro} or \term{special form},
  4252. it receives as \term{arguments} only the \term{primary values} of
  4253. its \term{argument} \term{forms}.
  4254. \endcom
  4255. %%% ========== VALUES-LIST
  4256. \begincom{values-list}\ftype{Function}
  4257. \label Syntax::
  4258. \DefunWithValues values-list {list} {\starparam{element}}
  4259. \label Arguments and Values::
  4260. \param{list}---a \term{list}.
  4261. \param{elements}---the \term{elements} of the \param{list}.
  4262. \label Description::
  4263. %% 7.9.1 9
  4264. Returns the \term{elements} of the \param{list} as \term{multiple values}\meaning{2}.
  4265. \label Examples::
  4266. \code
  4267. (values-list nil) \EV \novalues
  4268. (values-list '(1)) \EV 1
  4269. (values-list '(1 2)) \EV 1, 2
  4270. (values-list '(1 2 3)) \EV 1, 2, 3
  4271. \endcode
  4272. \label Affected By:\None.
  4273. \label Exceptional Situations::
  4274. Should signal \typeref{type-error} if its argument is not a \term{proper list}.
  4275. %KMP: Isn't there also some issue to do with max number of values?
  4276. %Moon: No different than in VALUES if (> CALL-ARGUMENTS-LIMIT MULTIPLE-VALUES-LIMIT).
  4277. \label See Also::
  4278. \macref{multiple-value-bind},
  4279. \conref{multiple-value-list},
  4280. \conref{multiple-values-limit},
  4281. \funref{values}
  4282. \label Notes::
  4283. \code
  4284. (values-list \param{list}) \EQ (apply #'values \param{list})
  4285. \endcode
  4286. \f{(equal \param{x} (multiple-value-list (values-list \param{x})))}
  4287. returns \term{true} for all \term{lists} \param{x}.
  4288. \endcom
  4289. %%% ========== MULTIPLE-VALUES-LIMIT
  4290. \begincom{multiple-values-limit}\ftype{Constant Variable}
  4291. \label Constant Value::
  4292. An \term{integer} not smaller than \f{20},
  4293. the exact magnitude of which is \term{implementation-dependent}.
  4294. \label Description::
  4295. %% 7.9.1 8
  4296. The upper exclusive bound on the number of \term{values} that may be
  4297. returned from a \term{function},
  4298. \issue{MULTIPLE-VALUES-LIMIT-ON-VARIABLES:UNDEFINED}
  4299. bound or assigned by \macref{multiple-value-bind} or \macref{multiple-value-setq},
  4300. or passed as a first argument to \macref{nth-value}.
  4301. (If these individual limits might differ, the minimum value is used.)
  4302. \endissue{MULTIPLE-VALUES-LIMIT-ON-VARIABLES:UNDEFINED}
  4303. \label Examples:\None.
  4304. \label See Also::
  4305. \conref{lambda-parameters-limit}, \conref{call-arguments-limit}
  4306. \label Notes::
  4307. Implementors are encouraged to make this limit as large as possible.
  4308. \endcom
  4309. %%% ========== NTH-VALUE
  4310. \begincom{nth-value}\ftype{Macro}
  4311. \issue{NTH-VALUE:ADD}
  4312. \label Syntax::
  4313. \DefmacWithValues nth-value {n form} {object}
  4314. \label Arguments and Values::
  4315. \param{n}---a non-negative \term{integer}; \eval.
  4316. \param{form}---a \term{form}; \evalspecial.
  4317. \param{object}---an \term{object}.
  4318. \label Description::
  4319. Evaluates \param{n} and then \param{form},
  4320. returning as its only value the \param{n}th value \term{yielded} by \param{form},
  4321. or \nil\ if \param{n} is greater than or equal to the number of \term{values}
  4322. returned by \param{form}. (The first returned value is numbered \f{0}.)
  4323. \label Examples::
  4324. \code
  4325. (nth-value 0 (values 'a 'b)) \EV A
  4326. (nth-value 1 (values 'a 'b)) \EV B
  4327. (nth-value 2 (values 'a 'b)) \EV NIL
  4328. (let* ((x 83927472397238947423879243432432432)
  4329. (y 32423489732)
  4330. (a (nth-value 1 (floor x y)))
  4331. (b (mod x y)))
  4332. (values a b (= a b)))
  4333. \EV 3332987528, 3332987528, \term{true}
  4334. \endcode
  4335. \label Side Effects:\None.
  4336. \label Affected By:\None.
  4337. \label Exceptional Situations:\None.
  4338. \label See Also::
  4339. \macref{multiple-value-list},
  4340. \funref{nth}
  4341. \label Notes::
  4342. Operationally, the following relationship is true, although \specref{nth-value}
  4343. might be more efficient in some \term{implementations}
  4344. because, for example, some \term{consing} might be avoided.
  4345. \code
  4346. (nth-value \param{n} \param{form}) \EQ (nth \param{n} (multiple-value-list \param{form}))
  4347. \endcode
  4348. \endissue{NTH-VALUE:ADD}
  4349. \endcom
  4350. %-------------------- Data and Control --------------------
  4351. %%% ========== PROG
  4352. %%% ========== PROG*
  4353. \begincom{prog, prog*}\ftype{Macro}
  4354. \issue{DECLS-AND-DOC}
  4355. \label Syntax::
  4356. \DefmacWithValuesNewline prog
  4357. {\paren{\star{\curly{\param{var} $\vert$
  4358. \paren{\param{var} \brac{\param{init-form}}}}}}
  4359. \starparam{declaration}
  4360. \star{\curly{\param{tag} $\vert$ \param{statement}}}}
  4361. {\starparam{result}}
  4362. \DefmacWithValuesNewline {prog*}
  4363. {\paren{\star{\curly{\param{var} $\vert$
  4364. \paren{\param{var} \brac{\param{init-form}}}}}}
  4365. \starparam{declaration}
  4366. \star{\curly{\param{tag} $\vert$ \param{statement}}}}
  4367. {\starparam{result}}
  4368. \label Arguments and Values::
  4369. \param{var}---variable name.
  4370. \param{init-form}---a \term{form}.
  4371. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  4372. \param{tag}---a \term{go tag}; \noeval.
  4373. \param{statement}---a \term{compound form}; \evalspecial.
  4374. \param{results}---\nil\ if a \term{normal return} occurs,
  4375. or else, if an \term{explicit return} occurs, the \term{values} that were transferred.
  4376. \label Description::
  4377. %% 7.8.5 3
  4378. Three distinct operations are performed by \macref{prog} and
  4379. \macref{prog*}:
  4380. they bind local variables,
  4381. they permit use of the \macref{return}
  4382. statement, and they permit use of the \specref{go}
  4383. statement.
  4384. A typical \macref{prog} looks like this:
  4385. \code
  4386. (prog (var1 var2 (var3 init-form-3) var4 (var5 init-form-5))
  4387. \starparam{declaration}
  4388. statement1
  4389. tag1
  4390. statement2
  4391. statement3
  4392. statement4
  4393. tag2
  4394. statement5
  4395. ...
  4396. )
  4397. \endcode
  4398. For \macref{prog},
  4399. \param{init-forms} are evaluated first, in the order in which they are
  4400. supplied. The \param{vars} are then bound to the corresponding values in
  4401. parallel. If no \param{init-form}
  4402. is supplied for a given \param{var},
  4403. that \param{var} is bound to \nil.
  4404. %% 7.8.5 11
  4405. The body of \macref{prog} is executed as if it were a \specref{tagbody} \term{form};
  4406. the \specref{go} statement can be used to transfer control
  4407. to a \param{tag}.
  4408. \param{Tags} label \param{statements}.
  4409. %% 7.8.5 12
  4410. \macref{prog} implicitly establishes a \specref{block} named \nil\ around
  4411. the entire \macref{prog} \term{form}, so that \macref{return} can be used
  4412. at any time to exit from the \macref{prog} \term{form}.
  4413. %% 7.8.5 15
  4414. The difference between \macref{prog*} and \macref{prog} is that
  4415. in \macref{prog*} the \term{binding} and initialization of the \param{vars}
  4416. is done \term{sequentially}, so that the \param{init-form} for each
  4417. one can use the values of previous ones.
  4418. % I don't think anything in this next paragraph hasn't been stated
  4419. % elsewhere. --sjl 5 Mar 92
  4420. %Any \param{declaration} appearing in the \macref{prog} is used as
  4421. %if appearing at the top of \specref{let}.
  4422. %It is an error if a \term{type declaration} is supplied for a
  4423. %\param{var} and the initial value of
  4424. %that \param{var} is not consistent with the \param{declaration}.
  4425. %Similarly, declarations in \macref{prog*} are like in \macref{let*}.
  4426. %% Moon: Redundant.
  4427. % For \macref{prog}, the
  4428. % \term{scope} of the name binding does not include any
  4429. % \param{init-form}.
  4430. % For \macref{prog*}, a variable's \term{scope} also includes the
  4431. % remaining \param{init-forms} for subsequent variable bindings.
  4432. \label Examples::
  4433. \code
  4434. (prog* ((y z) (x (car y)))
  4435. (return x))
  4436. \endcode
  4437. returns the \term{car} of the value of \f{z}.
  4438. \code
  4439. (setq a 1) \EV 1
  4440. (prog ((a 2) (b a)) (return (if (= a b) '= '/=))) \EV /=
  4441. (prog* ((a 2) (b a)) (return (if (= a b) '= '/=))) \EV =
  4442. (prog () 'no-return-value) \EV NIL
  4443. \endcode
  4444. %% 7.8.5 13
  4445. \code
  4446. (defun king-of-confusion (w)
  4447. "Take a cons of two lists and make a list of conses.
  4448. Think of this function as being like a zipper."
  4449. (prog (x y z) ;Initialize x, y, z to NIL
  4450. (setq y (car w) z (cdr w))
  4451. loop
  4452. (cond ((null y) (return x))
  4453. ((null z) (go err)))
  4454. rejoin
  4455. (setq x (cons (cons (car y) (car z)) x))
  4456. (setq y (cdr y) z (cdr z))
  4457. (go loop)
  4458. err
  4459. (cerror "Will self-pair extraneous items"
  4460. "Mismatch - gleep! ~S" y)
  4461. (setq z y)
  4462. (go rejoin))) \EV KING-OF-CONFUSION
  4463. \endcode
  4464. This can be accomplished more perspicuously as follows:
  4465. \code
  4466. (defun prince-of-clarity (w)
  4467. "Take a cons of two lists and make a list of conses.
  4468. Think of this function as being like a zipper."
  4469. (do ((y (car w) (cdr y))
  4470. (z (cdr w) (cdr z))
  4471. (x '\empty (cons (cons (car y) (car z)) x)))
  4472. ((null y) x)
  4473. (when (null z)
  4474. (cerror "Will self-pair extraneous items"
  4475. "Mismatch - gleep! ~S" y)
  4476. (setq z y)))) \EV PRINCE-OF-CLARITY
  4477. \endcode
  4478. \label Affected By:\None.
  4479. \label Exceptional Situations:\None.
  4480. \label See Also::
  4481. \specref{block}, \specref{let}, \specref{tagbody}, \specref{go},
  4482. \macref{return}, {\secref\Evaluation}
  4483. \label Notes::
  4484. %% 7.8.5 14
  4485. \macref{prog} can be explained in terms of
  4486. \specref{block}, \specref{let}, and \specref{tagbody} as
  4487. follows:
  4488. \code
  4489. (prog \param{variable-list} \param{declaration} . \param{body})
  4490. \EQ (block nil (let \param{variable-list} \param{declaration} (tagbody . \param{body})))
  4491. \endcode
  4492. \endissue{DECLS-AND-DOC}
  4493. \endcom
  4494. %%% ========== PROG1
  4495. %%% ========== PROG2
  4496. \begincom{prog1, prog2}\ftype{Macro}
  4497. \label Syntax::
  4498. \DefmacWithValues prog1 {first-form \starparam{form}} {result-1}
  4499. \DefmacWithValues prog2 {first-form second-form \starparam{form}} {result-2}
  4500. \label Arguments and Values::
  4501. \param{first-form}---a \term{form}; \evalspecial.
  4502. \param{second-form}---a \term{form}; \evalspecial.
  4503. \param{forms}---an \term{implicit progn}; \evalspecial.
  4504. %% 7.4.0 8
  4505. \param{result-1}---the \term{primary value} resulting from
  4506. the \term{evaluation} of \param{first-form}.
  4507. %% 7.4.0 11
  4508. \param{result-2}---the \term{primary value} resulting from
  4509. the \term{evaluation} of \param{second-form}.
  4510. \label Description::
  4511. %% 7.4.0 6
  4512. \macref{prog1} \term{evaluates} \param{first-form}
  4513. and then \param{forms},
  4514. \term{yielding} as its only \term{value}
  4515. the \term{primary value} \term{yielded} by \param{first-form}.
  4516. %% 7.4.0 9
  4517. \macref{prog2} \term{evaluates} \param{first-form},
  4518. then \param{second-form},
  4519. and then \param{forms},
  4520. \term{yielding} as its only \term{value}
  4521. the \term{primary value} \term{yielded} by \param{first-form}.
  4522. %% I hope this is implied by the above. -kmp 22-Oct-91
  4523. %The arguments are evaluated in the order in which they are given.
  4524. \label Examples::
  4525. \code
  4526. (setq temp 1) \EV 1
  4527. (prog1 temp (print temp) (incf temp) (print temp))
  4528. \OUT 1
  4529. \OUT 2
  4530. \EV 1
  4531. (prog1 temp (setq temp nil)) \EV 2
  4532. temp \EV NIL
  4533. (prog1 (values 1 2 3) 4) \EV 1
  4534. (setq temp (list 'a 'b 'c))
  4535. (prog1 (car temp) (setf (car temp) 'alpha)) \EV A
  4536. temp \EV (ALPHA B C)
  4537. (flet ((swap-symbol-values (x y)
  4538. (setf (symbol-value x)
  4539. (prog1 (symbol-value y)
  4540. (setf (symbol-value y) (symbol-value x))))))
  4541. (let ((*foo* 1) (*bar* 2))
  4542. (declare (special *foo* *bar*))
  4543. (swap-symbol-values '*foo* '*bar*)
  4544. (values *foo* *bar*)))
  4545. \EV 2, 1
  4546. (setq temp 1) \EV 1
  4547. (prog2 (incf temp) (incf temp) (incf temp)) \EV 3
  4548. temp \EV 4
  4549. (prog2 1 (values 2 3 4) 5) \EV 2
  4550. \endcode
  4551. \label Side Effects:\None.
  4552. \label Affected By:\None.
  4553. \label Exceptional Situations:\None.
  4554. \label See Also::
  4555. \specref{multiple-value-prog1},
  4556. \specref{progn}
  4557. \label Notes::
  4558. %% 7.4.0 7
  4559. \macref{prog1} and \macref{prog2} are typically used to \term{evaluate}
  4560. one or more \term{forms} with side effects and return a \term{value} that
  4561. must be computed before some or all of the side effects happen.
  4562. % The second example is wrong because it passes top-level-ness to form1,
  4563. % which is forbidden by issue MACRO-SUBFORMS-TOP-LEVEL-P. --sjl 5 Mar 92
  4564. %\code
  4565. % (prog1 \starparam{form}) \EQ (values (multiple-value-prog1 \starparam{form}))
  4566. % (prog2 \param{form1} \starparam{form}) \EQ (progn \param{form1} (prog1 \starparam{form}))
  4567. %\endcode
  4568. \code
  4569. (prog1 \starparam{form}) \EQ (values (multiple-value-prog1 \starparam{form}))
  4570. (prog2 \param{form1} \starparam{form}) \EQ (let () \param{form1} (prog1 \starparam{form}))
  4571. \endcode
  4572. \endcom
  4573. %%% ========== PROGN
  4574. \begincom{progn}\ftype{Special Operator}
  4575. \label Syntax::
  4576. \DefspecWithValues progn {\starparam{form}} {\starparam{result}}
  4577. \label Arguments and Values::
  4578. \param{forms}---an \term{implicit progn}.
  4579. %% 7.9.2 6
  4580. %% 7.4.0 5
  4581. \param{results}---the \term{values} of the \term{forms}.
  4582. \label Description::
  4583. %% 7.4.0 3
  4584. \specref{progn} evaluates \param{forms},
  4585. in the order in which they are given.
  4586. The values of each \param{form} but the last are discarded.
  4587. %% 5.3 2
  4588. If \specref{progn} appears as a \term{top level form}, then all \term{forms}
  4589. within that \specref{progn} are considered by the compiler to be
  4590. \term{top level forms}.
  4591. \label Examples::
  4592. \code
  4593. (progn) \EV NIL
  4594. (progn 1 2 3) \EV 3
  4595. (progn (values 1 2 3)) \EV 1, 2, 3
  4596. (setq a 1) \EV 1
  4597. (if a
  4598. (progn (setq a nil) 'here)
  4599. (progn (setq a t) 'there)) \EV HERE
  4600. a \EV NIL
  4601. \endcode
  4602. \label Affected By:\None.
  4603. \label Exceptional Situations:\None.
  4604. \label See Also::
  4605. \macref{prog1}, \macref{prog2}, {\secref\Evaluation}
  4606. \label Notes::
  4607. %% 7.4.0 4
  4608. Many places in \clisp\ involve syntax that uses \term{implicit progns}.
  4609. That is, part of their syntax allows many \term{forms} to be written
  4610. that are to be evaluated sequentially, discarding the results
  4611. of all \term{forms} but the last and returning the results of the last \term{form}.
  4612. Such places include, but are not limited to, the following:
  4613. the body of a \term{lambda expression};
  4614. the bodies of various control and conditional \term{forms}
  4615. (\eg \macref{case}, \specref{catch}, \specref{progn}, and \macref{when}).
  4616. %% This list could go on and on. Just keep it simple. -kmp&moon 13-Feb-92
  4617. % \specref{block},
  4618. % \specref{catch},
  4619. % \specref{evalwhen},
  4620. % \specref{let},
  4621. % \specref{let*},
  4622. % \macref{multiple-value-bind},
  4623. % \specref{progv},
  4624. % \macref{unless},
  4625. % and \macref{when};
  4626. %
  4627. %
  4628. % (\eg \specref{block}, \specref{catch}, \specref{eval-when})
  4629. % and clauses in the
  4630. % \macref{case},
  4631. % \macref{ccase},
  4632. % \macref{cond},
  4633. % \macref{ctypecase},
  4634. % \macref{ecase},
  4635. % \macref{etypecase},
  4636. % and \macref{typecase}
  4637. % conditional \term{forms}.
  4638. \endcom
  4639. %-------------------- Setf --------------------
  4640. %%% ========== DEFINE-MODIFY-MACRO
  4641. \begincom{define-modify-macro}\ftype{Macro}
  4642. \label Syntax::
  4643. \DefmacWithValues define-modify-macro
  4644. {name lambda-list function \brac{documentation}}
  4645. {name}
  4646. \label Arguments and Values::
  4647. \param{name}---a \term{symbol}.
  4648. % The lambda-list here was screwed up. GET-SETF-METHOD-ENVIRONMENT:ADD-ARG
  4649. % did *not* add an &environment argument to define-modify-macro.
  4650. % I moved the details of the lambda-list syntax to chapter 3, for
  4651. % consistency with everything else. --sjl 5 Mar 92
  4652. %\issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  4653. %\param{lambda-list}---a \term{lambda list}
  4654. % containing the
  4655. % \keyref{environment},
  4656. % \keyref{optional},
  4657. % and
  4658. % \keyref{rest}
  4659. % keywords only.
  4660. %\endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  4661. \param{lambda-list}---a \term{define-modify-macro lambda list}
  4662. \param{function}---a \term{symbol}.
  4663. \param{documentation}---a \term{string}; \noeval.
  4664. \label Description::
  4665. %% 7.2.0 42
  4666. \macref{define-modify-macro} defines a \term{macro} named
  4667. \param{name} to \term{read} and \term{write} a \term{place}.
  4668. The arguments to the new \term{macro} are a \term{place},
  4669. followed
  4670. by the arguments that are supplied in \param{lambda-list}.
  4671. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  4672. \term{Macros} defined with \macref{define-modify-macro}
  4673. correctly pass the \term{environment parameter} to
  4674. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4675. \funref{get-setf-expansion}.
  4676. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4677. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  4678. % I see no &environment argument here. --sjl 5 Mar 92
  4679. %\issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  4680. % The \keyref{environment} argument has \term{dynamic extent};
  4681. %the consequences are undefined if the \keyref{environment} argument is
  4682. %referred to outside the \term{dynamic extent} of the macro call.
  4683. %\endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  4684. When the \term{macro} is invoked, \param{function}
  4685. is applied to the old contents of the \term{place}
  4686. and the \param{lambda-list} arguments to obtain the new value,
  4687. and the \term{place} is updated to contain the result.
  4688. %% 7.2.0 43
  4689. Except for the issue of avoiding multiple evaluation (see below), the expansion
  4690. of a \macref{define-modify-macro} is equivalent to the following:
  4691. \code
  4692. (defmacro \param{name} (reference . \param{lambda-list})
  4693. \param{documentation}
  4694. \bq(setf ,reference
  4695. (\param{function} ,reference ,\i{arg1} ,\i{arg2} ...)))
  4696. \endcode
  4697. where \i{arg1}, \i{arg2}, ...,
  4698. are the parameters appearing in \param{lambda-list};
  4699. appropriate provision is made for a \term{rest parameter}.
  4700. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  4701. The \term{subforms} of the macro calls defined by \macref{define-modify-macro}
  4702. are evaluated as specified in \secref\GenRefSubFormEval.
  4703. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  4704. \issue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  4705. \param{Documentation} is attached as a \term{documentation string}
  4706. to \param{name} (as kind \specref{function})
  4707. and to the \term{macro function}.
  4708. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  4709. % Added. --sjl 5 Mar 92
  4710. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  4711. % added qualification about top-level-ness --sjl 5 Mar 92
  4712. If a \macref{define-modify-macro} \term{form} appears as a \term{top level form},
  4713. the \term{compiler} must store the \term{macro} definition at compile time,
  4714. so that occurrences of the macro later on in the file can be expanded correctly.
  4715. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  4716. \label Examples::
  4717. %% 7.2.0 44
  4718. %% 7.2.0 45
  4719. \code
  4720. (define-modify-macro appendf (&rest args)
  4721. append "Append onto list") \EV APPENDF
  4722. (setq x '(a b c) y x) \EV (A B C)
  4723. (appendf x '(d e f) '(1 2 3)) \EV (A B C D E F 1 2 3)
  4724. x \EV (A B C D E F 1 2 3)
  4725. y \EV (A B C)
  4726. (define-modify-macro new-incf (&optional (delta 1)) +)
  4727. (define-modify-macro unionf (other-set &rest keywords) union)
  4728. \endcode
  4729. \label Side Effects::
  4730. A macro definition is assigned to \param{name}.
  4731. \label Affected By:\None.
  4732. \label Exceptional Situations:\None.
  4733. \label See Also::
  4734. \macref{defsetf},
  4735. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4736. \macref{define-setf-expander},
  4737. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4738. \funref{documentation},
  4739. {\secref\DocVsDecls}
  4740. \label Notes:\None.
  4741. \endcom
  4742. %%% ========== DEFSETF
  4743. \begincom{defsetf}\ftype{Macro}
  4744. \issue{DECLS-AND-DOC}
  4745. \label Syntax::
  4746. The ``short form'':
  4747. \DefmacWithValuesNewline defsetf
  4748. {access-fn update-fn \brac{documentation}}
  4749. {access-fn}
  4750. The ``long form'':
  4751. \DefmacWithValuesNewline defsetf
  4752. {access-fn lambda-list \paren{\starparam{store-variable}}
  4753. {\DeclsAndDoc} \starparam{form}}
  4754. {access-fn}
  4755. \label Arguments and Values::
  4756. %!!! Barmar: Does the function or macro needs to already be defined?
  4757. \param{access-fn}---a \term{symbol} which names a \term{function} or a \term{macro}.
  4758. \param{update-fn}---a \term{symbol} naming a \term{function} or \term{macro}.
  4759. \param{lambda-list}---a \term{defsetf lambda list}.
  4760. \param{store-variable}---a \term{symbol} (a \term{variable} \term{name}).
  4761. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  4762. \param{documentation}---a \term{string}; \noeval.
  4763. \param{form}---a \term{form}.
  4764. \label Description::
  4765. %% 7.2.0 46
  4766. \macref{defsetf} defines how to
  4767. \macref{setf} a \term{place}
  4768. of the form \f{(\i{access-fn} ...)} for relatively simple cases.
  4769. (See \macref{define-setf-expander} for more general access to this facility.)
  4770. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  4771. % These next two paragraphs apply only to the short form. This information
  4772. % is presented more succinctly below anyway. --sjl 5 Mar 92
  4773. %
  4774. % When \macref{setf} is given a \term{place} that is
  4775. % specified in terms of \param{access-fn} and a new value for the
  4776. % \term{place},
  4777. % it is expanded into a call on \param{update-fn}.
  4778. % The arguments of \param{access-fn} and the new value are passed to
  4779. % \param{update-fn},
  4780. % and \param{update-fn} is invoked to modify the value of the
  4781. % \term{place}.
  4782. %
  4783. % The \term{function} or \term{macro} named by \param{access-fn}
  4784. % evaluates all of its arguments.
  4785. % %Barmar: Why?
  4786. % %Barmar (later): Answer is CLtL2, p138, para 2.
  4787. % \param{Update-fn} must take one more argument than
  4788. % \param{access-fn}. This last argument corresponds to the new value that is
  4789. % to be assigned to the \term{place}. \param{Update-fn} must return
  4790. % the new value as its result.
  4791. It must be the case that the \term{function} or \term{macro} named by \param{access-fn}
  4792. evaluates all of its arguments.
  4793. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  4794. %% 7.2.0 49
  4795. \macref{defsetf} may take one of two forms, called the ``short form'' and the ``long form,''
  4796. which are distinguished by the \term{type} of the second \term{argument}.
  4797. When the short form is used,
  4798. % The simple form
  4799. %
  4800. % \code
  4801. % (defsetf access-fn update-fn \lbracket\ doc-string\rbracket)
  4802. % \endcode
  4803. \param{update-fn} must name
  4804. a \term{function} (or \term{macro}) that takes one more argument
  4805. than \param{access-fn} takes. When \macref{setf} is given a \term{place}
  4806. that is a call on \param{access-fn}, it expands into
  4807. a call on \param{update-fn} that is given all the arguments to
  4808. \param{access-fn} and also, as its last argument, the new value
  4809. (which must be returned by \param{update-fn} as its value).
  4810. %% 7.2.0 51
  4811. The long form \macref{defsetf}
  4812. % looks like
  4813. %
  4814. % \code
  4815. % (defsetf access-fn lambda-list (store-variable) . body)
  4816. % \endcode
  4817. % and
  4818. resembles \macref{defmacro}.
  4819. %% 7.2.0 52
  4820. The \param{lambda-list} describes the arguments of \param{access-fn}.
  4821. The \param{store-variables} describe the
  4822. value
  4823. \issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  4824. or values
  4825. \endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  4826. to be stored into the \term{place}.
  4827. The \param{body} must
  4828. compute the expansion of a \macref{setf} of a call on \param{access-fn}.
  4829. \issue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  4830. % Reworded garbled text. --sjl 7 Mar 92
  4831. % When the expansion function is called, the \param{forms} are evaluated
  4832. % in the lexical environment in which the \macref{defsetf} \term{form} was evaluated.
  4833. The expansion function is defined in the same \term{lexical environment}
  4834. in which the \macref{defsetf} \term{form} appears.
  4835. \endissue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  4836. %% 7.2.0 54
  4837. During the evaluation of the
  4838. \param{forms}, the variables in the \param{lambda-list} and the
  4839. %Ikky. --sjl 5 Mar 92
  4840. %\param{store-variable}
  4841. %\issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  4842. %or \param{store-variables}
  4843. %\endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  4844. \param{store-variables}
  4845. are bound to names of temporary variables,
  4846. generated as if by \funref{gensym}
  4847. % !!! Moon doesn't like this. Neither do I. He's sent mail about this. -kmp 13-Feb-92
  4848. or \funref{gentemp},
  4849. that will be bound by the
  4850. expansion of \macref{setf}
  4851. to the values of those \term{subforms}. This binding
  4852. permits the
  4853. \param{forms} to be written without regard for order-of-evaluation
  4854. issues. \macref{defsetf} arranges for the temporary variables to be
  4855. optimized out of the final result in cases where that is possible.
  4856. \issue{FLET-IMPLICIT-BLOCK:YES}
  4857. The body code in \macref{defsetf} is implicitly enclosed in a
  4858. \term{block} whose name is
  4859. %the same as the accessor.
  4860. \param{access-fn}
  4861. \endissue{FLET-IMPLICIT-BLOCK:YES}
  4862. %% 7.2.0 47
  4863. \macref{defsetf}
  4864. ensures that \term{subforms}
  4865. of the \term{place} are evaluated exactly once.
  4866. \param{Documentation} is attached to \param{access-fn} as a \term{documentation string}
  4867. of kind \misc{setf}.
  4868. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  4869. % added qualification about top-level-ness --sjl 5 Mar 92
  4870. If a \macref{defsetf} \term{form} appears as a \term{top level form},
  4871. the \term{compiler} must make the \term{setf expander} available so that
  4872. it may be used to expand calls to \macref{setf} later on in the \term{file}.
  4873. Users must ensure that the \param{forms}, if any, can be evaluated
  4874. at compile time if the \param{access-fn} is used in a \term{place}
  4875. later in the same \term{file}.
  4876. The \term{compiler} must make these \term{setf expanders} available to
  4877. compile-time calls to \funref{get-setf-expansion} when its \param{environment}
  4878. argument is a value received as the \term{environment parameter} of a \term{macro}.
  4879. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  4880. \label Examples::
  4881. The effect of
  4882. \code
  4883. (defsetf symbol-value set)
  4884. \endcode
  4885. is built into the \clisp\ system.
  4886. This causes the form \f{(setf (symbol-value foo) fu)}
  4887. to expand into \f{(set foo fu)}.
  4888. %% 7.2.0 50
  4889. Note that
  4890. \code
  4891. (defsetf car rplaca)
  4892. \endcode
  4893. would be incorrect because \funref{rplaca} does not return its last argument.
  4894. \code
  4895. (defun middleguy (x) (nth (truncate (1- (list-length x)) 2) x)) \EV MIDDLEGUY
  4896. (defun set-middleguy (x v)
  4897. (unless (null x)
  4898. (rplaca (nthcdr (truncate (1- (list-length x)) 2) x) v))
  4899. v) \EV SET-MIDDLEGUY
  4900. (defsetf middleguy set-middleguy) \EV MIDDLEGUY
  4901. (setq a (list 'a 'b 'c 'd)
  4902. b (list 'x)
  4903. c (list 1 2 3 (list 4 5 6) 7 8 9)) \EV (1 2 3 (4 5 6) 7 8 9)
  4904. (setf (middleguy a) 3) \EV 3
  4905. (setf (middleguy b) 7) \EV 7
  4906. (setf (middleguy (middleguy c)) 'middleguy-symbol) \EV MIDDLEGUY-SYMBOL
  4907. a \EV (A 3 C D)
  4908. b \EV (7)
  4909. c \EV (1 2 3 (4 MIDDLEGUY-SYMBOL 6) 7 8 9)
  4910. \endcode
  4911. %% 7.2.0 56
  4912. An example of the use of the long form of \macref{defsetf}:
  4913. \code
  4914. (defsetf subseq (sequence start &optional end) (new-sequence)
  4915. `(progn (replace ,sequence ,new-sequence
  4916. :start1 ,start :end1 ,end)
  4917. ,new-sequence)) \EV SUBSEQ
  4918. \endcode
  4919. %% People thought this comment was stupid. -kmp 10-Feb-92
  4920. % Experience with Common Lisp prior to this specification suggests that
  4921. % use of the fully general notation for \term{keyword parameters} in \term{function}
  4922. % definitions is rare, and that its use in \macref{defsetf} \term{forms}
  4923. % is even more rare. In spite of its obscure nature,
  4924. % the following is an illustration of \term{conforming code}:
  4925. \code
  4926. (defvar *xy* (make-array '(10 10)))
  4927. (defun xy (&key ((x x) 0) ((y y) 0)) (aref *xy* x y)) \EV XY
  4928. (defun set-xy (new-value &key ((x x) 0) ((y y) 0))
  4929. (setf (aref *xy* x y) new-value)) \EV SET-XY
  4930. (defsetf xy (&key ((x x) 0) ((y y) 0)) (store)
  4931. `(set-xy ,store 'x ,x 'y ,y)) \EV XY
  4932. (get-setf-expansion '(xy a b))
  4933. \EV (#:t0 #:t1),
  4934. (a b),
  4935. (#:store),
  4936. ((lambda (&key ((x #:x)) ((y #:y)))
  4937. (set-xy #:store 'x #:x 'y #:y))
  4938. #:t0 #:t1),
  4939. (xy #:t0 #:t1)
  4940. (xy 'x 1) \EV NIL
  4941. (setf (xy 'x 1) 1) \EV 1
  4942. (xy 'x 1) \EV 1
  4943. (let ((a 'x) (b 'y))
  4944. (setf (xy a 1 b 2) 3)
  4945. (setf (xy b 5 a 9) 14))
  4946. \EV 14
  4947. (xy 'y 0 'x 1) \EV 1
  4948. (xy 'x 1 'y 2) \EV 3
  4949. \endcode
  4950. \label Affected By:\None.
  4951. \label Exceptional Situations:\None.
  4952. \label See Also::
  4953. \funref{documentation},
  4954. \macref{setf},
  4955. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4956. \macref{define-setf-expander},
  4957. \funref{get-setf-expansion},
  4958. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4959. {\secref\GeneralizedReference},
  4960. {\secref\DocVsDecls}
  4961. \label Notes::
  4962. %% 7.2.0 55
  4963. \param{forms} must include provision
  4964. for returning the correct value (the value
  4965. \issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  4966. or values
  4967. \endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  4968. of \param{store-variable}).
  4969. This is
  4970. handled by \param{forms} rather than by \macref{defsetf} because
  4971. in many cases this value can be returned at no extra cost, by calling a
  4972. function that simultaneously stores into the \term{place} and
  4973. returns the correct value.
  4974. A \macref{setf} of a call on \param{access-fn} also evaluates
  4975. all of \param{access-fn}'s arguments; it cannot treat any of them specially.
  4976. %!!!
  4977. %Barmar: What if update-fn is a macro?
  4978. %Moon: That technique won't work because DEFSETF is allowed to introduce temporary
  4979. % variable bindings. I guess that ought to be explained in this note.
  4980. This means that \macref{defsetf}
  4981. cannot be used to describe how to store into
  4982. a \term{generalized reference} to a byte, such as \f{(ldb field reference)}.
  4983. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4984. \macref{define-setf-expander}
  4985. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4986. is used to handle situations that
  4987. do not fit the restrictions imposed by \macref{defsetf}
  4988. and gives the user additional control.
  4989. \endissue{DECLS-AND-DOC}
  4990. \endcom
  4991. %%% ========== DEFINE-SETF-METHOD
  4992. \begincom{define-setf-expander}\ftype{Macro}
  4993. \issue{DECLS-AND-DOC}
  4994. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  4995. \label Syntax::
  4996. \DefmacWithValuesNewline define-setf-expander
  4997. {\vtop{\hbox{access-fn lambda-list}
  4998. \hbox{{\DeclsAndDoc} \starparam{form}}}}
  4999. {access-fn}
  5000. \label Arguments and Values::
  5001. \param{access-fn}---a \term{symbol} that \term{names} a \term{function} or \term{macro}.
  5002. % tweaked. --sjl 5 Mar 92
  5003. %\issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5004. %\param{lambda-list} -- \term{lambda list};
  5005. % can contain the \term{lambda list keywords}
  5006. % \keyref{optional}, \keyref{rest}, \keyref{key}, \keyref{allow-other-keys}, \keyref{aux},
  5007. % and \keyref{environment}.
  5008. %\endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5009. \param{lambda-list} -- \term{macro lambda list}.
  5010. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  5011. \param{documentation}---a \term{string}; \noeval.
  5012. \param{forms}---an \term{implicit progn}.
  5013. \label Description::
  5014. %% 7.2.0 72
  5015. \macref{define-setf-expander} specifies the means by which \macref{setf}
  5016. updates a \term{place} that is referenced by \param{access-fn}.
  5017. When \macref{setf} is given a \term{place} that is
  5018. specified in terms of \param{access-fn} and a new value for the
  5019. \term{place}, it is expanded into a form that performs
  5020. the appropriate update.
  5021. %% Moon doesn't think this belongs.
  5022. % Neither do I. It's all described in gory detail in chapter 3 already.
  5023. % --sjl 5 Mar 92
  5024. % %When \macref{setf} is called with the \param{access-fn},
  5025. % \param{lambda-list}
  5026. % parameters are bound to the
  5027. % corresponding \param{access-fn} arguments in the \term{place}.
  5028. % %% 7.2.0 73
  5029. % \param{lambda-list} specifies the arguments of \param{access-fn} by
  5030. % describing the \term{subforms} of the \term{place}.
  5031. % \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5032. % %% 8.1.0 12
  5033. % \keyref{environment}
  5034. % is followed by a single variable that is bound
  5035. % to an \term{environment} representing the lexical environment in which the
  5036. % \term{macro form} is to be interpreted. This \term{environment} might not be the
  5037. % complete lexical environment; it should be used only with
  5038. % \funref{macroexpand} or \funref{get-setf-expansion} for the sake of any local
  5039. % macro definitions that the \specref{macrolet} \term{form} could have
  5040. % established within that lexical environment.
  5041. % \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5042. % \issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  5043. % The \keyref{environment} argument has \term{dynamic extent};
  5044. % the consequences are undefined if the \keyref{environment} argument is
  5045. % referred to outside the \term{dynamic extent} of the \term{macro form}.
  5046. % \endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  5047. %
  5048. % Destructuring can be used, as in \macref{defmacro}.
  5049. The \param{lambda-list} supports destructuring.
  5050. \Seesection\MacroLambdaLists.
  5051. \issue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  5052. \param{Documentation} is attached to \param{access-fn} as a \term{documentation string}
  5053. of kind \misc{setf}.
  5054. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  5055. \param{Forms} constitute the body of the
  5056. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  5057. \term{setf expander}
  5058. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  5059. definition and must compute the \term{setf expansion} for a call on \macref{setf}
  5060. that references the \term{place} by means of the given
  5061. \param{access-fn}.
  5062. \issue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  5063. % Reworded garbled text. --sjl 7 Mar 92
  5064. %When the expansion function is called, the \param{forms} are
  5065. %evaluated in the lexical environment in which the
  5066. %\macref{define-setf-expander} form was evaluated.
  5067. The \term{setf expander} function is defined in the same \term{lexical environment}
  5068. in which the \macref{define-setf-expander} \term{form} appears.
  5069. \endissue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  5070. While \param{forms} are being executed,
  5071. the variables in \param{lambda-list} are bound to parts of the \term{place} \term{form}.
  5072. \issue{FLET-IMPLICIT-BLOCK:YES}
  5073. \issue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  5074. The body \param{forms} (but not the \param{lambda-list})
  5075. \endissue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  5076. in a \macref{define-setf-expander} \term{form} are implicitly enclosed in a
  5077. \term{block} whose name is
  5078. %the same as the accessor.
  5079. \param{access-fn}.
  5080. \endissue{FLET-IMPLICIT-BLOCK:YES}
  5081. % We don't need to duplicate all this verbiage again here. --sjl 5 Mar 92
  5082. % The evaluation of \term{forms} must result in the following
  5083. % five values:
  5084. %
  5085. % \beginlist
  5086. % \itemitem{1.} A \term{list} of the temporary variables used.
  5087. %
  5088. % \itemitem{2.} A \term{list} of the value forms to whose values
  5089. % the temporary variables are bound.
  5090. %
  5091. % \itemitem{3.} A \term{list} consisting of the store variables
  5092. % (the temporary variables that are bound to the new values).
  5093. %
  5094. % \itemitem{4.} The \term{writer} \term{form}
  5095. % (the form that changes the \term{value}
  5096. % of the \term{place}
  5097. % and returns the new \term{value}).
  5098. %
  5099. % \itemitem{5.} The \term{reader} \term{form}
  5100. % (the \term{form} that retrieves the \term{value}
  5101. % of the \term{place}).
  5102. % \endlist
  5103. The evaluation of \param{forms} must result in the five values
  5104. described in \secref\SetfExpansions.
  5105. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  5106. % added qualification about top-level-ness --sjl 5 Mar 92
  5107. If a \macref{define-setf-expander} \term{form} appears as a \term{top level form},
  5108. the \term{compiler} must make the \term{setf expander} available so that
  5109. it may be used to expand calls to \macref{setf} later on in the \term{file}.
  5110. \term{Programmers} must ensure that the \param{forms} can be evaluated
  5111. at compile time if the \param{access-fn} is used in a \term{place}
  5112. later in the same \term{file}.
  5113. The \term{compiler} must make these \term{setf expanders} available to
  5114. compile-time calls to \funref{get-setf-expansion} when its \param{environment}
  5115. argument is a value received as the \term{environment parameter} of a \term{macro}.
  5116. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  5117. \label Examples::
  5118. \code
  5119. (defun lastguy (x) (car (last x))) \EV LASTGUY
  5120. (define-setf-expander lastguy (x &environment env)
  5121. "Set the last element in a list to the given value."
  5122. (multiple-value-bind (dummies vals newval setter getter)
  5123. (get-setf-expansion x env)
  5124. (let ((store (gensym)))
  5125. (values dummies
  5126. vals
  5127. `(,store)
  5128. `(progn (rplaca (last ,getter) ,store) ,store)
  5129. `(lastguy ,getter))))) \EV LASTGUY
  5130. (setq a (list 'a 'b 'c 'd)
  5131. b (list 'x)
  5132. c (list 1 2 3 (list 4 5 6))) \EV (1 2 3 (4 5 6))
  5133. (setf (lastguy a) 3) \EV 3
  5134. (setf (lastguy b) 7) \EV 7
  5135. (setf (lastguy (lastguy c)) 'lastguy-symbol) \EV LASTGUY-SYMBOL
  5136. a \EV (A B C 3)
  5137. b \EV (7)
  5138. c \EV (1 2 3 (4 5 LASTGUY-SYMBOL))
  5139. \endcode
  5140. %% 7.2.0 74
  5141. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  5142. \code
  5143. ;;; Setf expander for the form (LDB bytespec int).
  5144. ;;; Recall that the int form must itself be suitable for SETF.
  5145. (define-setf-expander ldb (bytespec int &environment env)
  5146. (multiple-value-bind (temps vals stores
  5147. store-form access-form)
  5148. (get-setf-expansion int env);Get setf expansion for int.
  5149. (let ((btemp (gensym)) ;Temp var for byte specifier.
  5150. (store (gensym)) ;Temp var for byte to store.
  5151. (stemp (first stores))) ;Temp var for int to store.
  5152. (if (cdr stores) (error "Can't expand this."))
  5153. ;;; Return the setf expansion for LDB as five values.
  5154. (values (cons btemp temps) ;Temporary variables.
  5155. (cons bytespec vals) ;Value forms.
  5156. (list store) ;Store variables.
  5157. \bq(let ((,stemp (dpb ,store ,btemp ,access-form)))
  5158. ,store-form
  5159. ,store) ;Storing form.
  5160. \bq(ldb ,btemp ,access-form) ;Accessing form.
  5161. ))))
  5162. \endcode
  5163. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  5164. \label Affected By:\None.
  5165. \label Exceptional Situations:\None.
  5166. \label See Also::
  5167. \macref{setf},
  5168. \macref{defsetf},
  5169. \funref{documentation},
  5170. \funref{get-setf-expansion},
  5171. {\secref\DocVsDecls}
  5172. \label Notes::
  5173. \macref{define-setf-expander} differs from the long form of \macref{defsetf}
  5174. in that while the body is being executed the \term{variables}
  5175. in \param{lambda-list} are bound to parts of the \term{place} \term{form},
  5176. not to temporary variables that will be bound to the values of such parts.
  5177. In addition, \macref{define-setf-expander} does not have \macref{defsetf}'s
  5178. restriction that \param{access-fn} must be a \term{function}
  5179. or a function-like \term{macro}; an arbitrary \macref{defmacro} destructuring
  5180. pattern is permitted in \param{lambda-list}.
  5181. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  5182. \endissue{DECLS-AND-DOC}
  5183. \endcom
  5184. %%% ========== GET-SETF-EXPANSION
  5185. \begincom{get-setf-expansion}\ftype{Function}
  5186. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  5187. \label Syntax::
  5188. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5189. \DefunWithValuesNewline get-setf-expansion
  5190. {place {\opt} environment}
  5191. {vars, vals, store-vars, writer-form, reader-form}
  5192. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5193. \label Arguments and Values::
  5194. \param{place}---a \term{place}.
  5195. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5196. \param{environment}---an \term{environment} \term{object}.
  5197. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5198. \param{vars, vals, store-vars, writer-form, reader-form}---a \term{setf expansion}.
  5199. \label Description::
  5200. %% 7.2.0 75
  5201. %% 7.2.0 77
  5202. Determines
  5203. five values constituting the \term{setf expansion} for \param{place}
  5204. in \param{environment}; \seesection\SetfExpansions.
  5205. %% Redundat with concept info.
  5206. % \beginlist
  5207. %
  5208. % \itemitem{\bull} A \term{list} of the temporary variables.
  5209. %
  5210. % \itemitem{\bull} A \term{list} of the value \term{forms} to whose values
  5211. % the temporary variables are bound.
  5212. %
  5213. % \itemitem{\bull} A \term{list} of the store variables.
  5214. %
  5215. % \itemitem{\bull} The \term{writer} \term{form}.
  5216. %
  5217. % \itemitem{\bull} The \term{reader} \term{form}.
  5218. %
  5219. % \endlist
  5220. % \funref{get-setf-method-multiple-value}
  5221. % does not check the number of store variables.
  5222. % The intent of \funref{get-setf-method-multiple-value}
  5223. % is that it be used in cases
  5224. % that allow storing multiple values into a \term{place}.
  5225. %
  5226. % \funref{get-setf-method} takes care of
  5227. % error-checking and macro expansion.
  5228. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5229. If \param{environment} is not supplied or \nil,
  5230. the environment is the \term{null lexical environment}.
  5231. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5232. % The consequences are undefined if \param{place} is not
  5233. % %a reference to a \term{place}.
  5234. \label Examples::
  5235. \code
  5236. (get-setf-expansion 'x)
  5237. \EV NIL, NIL, (#:G0001), (SETQ X #:G0001), X
  5238. \endcode
  5239. %% Moon: This is so monumentally confusing that it would be better to remove it.
  5240. %% Note that it never uses the store-variables.
  5241. %
  5242. % \code
  5243. % (define-setf-expander multivalue (x)
  5244. % (values '() '() `(,(gensym) ,(gensym)) `(setq ,x 3) '4))
  5245. % \EV MULTIVALUE
  5246. % (get-setf-expansion '(multivalue dummy-symbol))
  5247. % \EV NIL, NIL, (#:G0002 #:G0003), (SETQ DUMMY-SYMBOL 3), 4
  5248. % \endcode
  5249. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5250. % The following example is suspect
  5251. \code
  5252. ;;; This macro is like POP
  5253. (defmacro xpop (place &environment env)
  5254. (multiple-value-bind (dummies vals new setter getter)
  5255. (get-setf-expansion place env)
  5256. `(let* (,@(mapcar #'list dummies vals) (,(car new) ,getter))
  5257. (if (cdr new) (error "Can't expand this."))
  5258. (prog1 (car ,(car new))
  5259. (setq ,(car new) (cdr ,(car new)))
  5260. ,setter))))
  5261. (defsetf frob (x) (value)
  5262. `(setf (car ,x) ,value)) \EV FROB
  5263. ;;; The following is an error; an error might be signaled at macro expansion time
  5264. (flet ((frob (x) (cdr x))) ;Invalid
  5265. (xpop (frob z)))
  5266. \endcode
  5267. %;;; The following will modify (cdr z) and not (car z)
  5268. % (macrolet ((frob (x) `(cdr ,x)))
  5269. % (xpop (frob z)))
  5270. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  5271. %%% 7.2.0 76
  5272. %A version of \macref{setf}
  5273. %allowing exactly two
  5274. %\term{subforms}, containing no optimization to remove unnecessary variables, and
  5275. %not allowing storing of multiple values, could be defined by:
  5276. %\code
  5277. % (defmacro setf (reference value)
  5278. % (multiple-value-bind (vars vals stores store-form access-form)
  5279. % (get-setf-expansion reference)
  5280. % (declare (ignore access-form))
  5281. % \bq(let* ,(mapcar #'list
  5282. % (append vars stores)
  5283. % (append vals (list value)))
  5284. % ,store-form)))
  5285. %\endcode
  5286. \label Affected By:\None.
  5287. \label Exceptional Situations:\None.%Probably not true.
  5288. %Removed per SETF-METHOD-VS-SETF-METHOD.
  5289. % An error \oftype{error} is signaled by \funref{get-setf-expansion}
  5290. % if there would be more than one store variable.
  5291. \label See Also::
  5292. \macref{defsetf},
  5293. \macref{define-setf-expander},
  5294. \macref{setf}
  5295. \label Notes::
  5296. Any \term{compound form} is a valid \term{place},
  5297. since any \term{compound form} whose \term{operator} \param{f} has no \term{setf expander}
  5298. are expanded into a call to \f{(setf \param{f})}.
  5299. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  5300. \endcom
  5301. %%% ========== SETF
  5302. %%% ========== PSETF
  5303. \begincom{setf, psetf}\ftype{Macro}
  5304. \label Syntax::
  5305. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  5306. \DefmacWithValues setf {\stardown{pair}} {\starparam{result}}
  5307. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  5308. \DefmacWithValues psetf {\stardown{pair}} {\nil}
  5309. \auxbnf{pair}{place newvalue}
  5310. \label Arguments and Values::
  5311. \param{place}---a \term{place}.
  5312. \param{newvalue}---a \term{form}.
  5313. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  5314. % \param{result}---the \term{primary value} of the last \param{newvalue},
  5315. % or \nil\ if there are no \param{pairs}.
  5316. \param{results}---the \term{multiple values}\meaning{2}
  5317. returned by the storing form for the last \param{place},
  5318. or \nil\ if there are no \param{pairs}.
  5319. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  5320. \label Description::
  5321. \macref{setf} changes the \term{value} of \param{place} to be \param{newvalue}.
  5322. %% Moon: Also returns a different value; anyway, this is redundant.
  5323. %\macref{psetf} is like \macref{setf} except when multiple argument \param{pairs} are supplied.
  5324. %% 7.2.0 5
  5325. \f{(setf place newvalue)}
  5326. expands into an update form that stores the
  5327. result
  5328. of evaluating
  5329. \param{newvalue} into the location referred to by \param{place}.
  5330. %%dussud removed.
  5331. %\issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  5332. %If \param{newvalue} produces more values than there
  5333. %are store variables, the extra values are ignored. If \param{newvalue}
  5334. %produces fewer values than there are store variables, the missing values
  5335. %are set to \nil.
  5336. %\endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  5337. %%% KMP/clean-up suggested additional wording.
  5338. Some \param{place} forms
  5339. involve uses of accessors that take optional arguments.
  5340. Whether those optional arguments are permitted by
  5341. \macref{setf}, or what their use
  5342. is, is up to the
  5343. \macref{setf} expander function and is not under the control
  5344. of \macref{setf}.
  5345. The documentation for any \term{function}
  5346. that accepts \keyref{optional}, \keyref{rest},
  5347. or {\tt &key} arguments and that
  5348. claims to be usable with \macref{setf} must specify
  5349. how those arguments are treated.
  5350. %% End KMP/clean-up suggested additional wording.
  5351. %% 7.2.0 6
  5352. If more than one \param{pair} is supplied,
  5353. the \param{pairs} are processed sequentially; that is,
  5354. \code
  5355. (setf place-1 newvalue-1
  5356. place-2 newvalue-2
  5357. ...
  5358. place-N newvalue-N)
  5359. \endcode
  5360. is precisely equivalent to
  5361. \code
  5362. (progn (setf place-1 newvalue-1)
  5363. (setf place-2 newvalue-2)
  5364. ...
  5365. (setf place-N newvalue-N))
  5366. \endcode
  5367. %% 7.2.0 21
  5368. %% 7.2.0 22
  5369. For \macref{psetf},
  5370. if more than one \param{pair} is supplied then the assignments of new values to places are
  5371. done in parallel. More precisely, all \term{subforms} (in both the \param{place}
  5372. and \param{newvalue} \term{forms}) that are to be evaluated
  5373. are evaluated from left to right; after all evaluations have been performed,
  5374. all of the assignments are performed in an unpredictable order.
  5375. %% Removed per X3J13. -kmp 5-Oct-93
  5376. % The unpredictability matters only if more than one \param{place} form
  5377. % refers to the same place.
  5378. For detailed treatment of the expansion of \macref{setf} and \macref{psetf},
  5379. \seesection\KindsOfPlaces.
  5380. \label Examples::
  5381. \code
  5382. (setq x (cons 'a 'b) y (list 1 2 3)) \EV (1 2 3)
  5383. (setf (car x) 'x (cadr y) (car x) (cdr x) y) \EV (1 X 3)
  5384. x \EV (X 1 X 3)
  5385. y \EV (1 X 3)
  5386. (setq x (cons 'a 'b) y (list 1 2 3)) \EV (1 2 3)
  5387. (psetf (car x) 'x (cadr y) (car x) (cdr x) y) \EV NIL
  5388. x \EV (X 1 A 3)
  5389. y \EV (1 A 3)
  5390. \endcode
  5391. \label Affected By::
  5392. \macref{define-setf-expander},
  5393. \macref{defsetf},
  5394. \varref{*macroexpand-hook*}
  5395. \label Exceptional Situations:\None.
  5396. \label See Also::
  5397. \macref{define-setf-expander},
  5398. \macref{defsetf},
  5399. \funref{macroexpand-1},
  5400. \macref{rotatef},
  5401. \macref{shiftf},
  5402. {\secref\GeneralizedReference}
  5403. \label Notes:\None.
  5404. \endcom
  5405. %%% ========== SHIFTF
  5406. \begincom{shiftf}\ftype{Macro}
  5407. \label Syntax::
  5408. \DefmacWithValues shiftf {\plusparam{place} newvalue} {old-value-1}
  5409. \label Arguments and Values::
  5410. %% 7.2.0 23
  5411. \param{place}---a \term{place}.
  5412. \param{newvalue}---a \term{form}; \eval.
  5413. \param{old-value-1}---an \term{object} (the old \term{value} of the first \param{place}).
  5414. \label Description::
  5415. \macref{shiftf} modifies the values of each
  5416. \param{place} by storing \param{newvalue}
  5417. into the last \param{place}, and shifting the
  5418. values of the second through the last \param{place}
  5419. into the remaining \param{places}.
  5420. \issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  5421. If \param{newvalue} produces more values than there
  5422. are store variables, the extra values are ignored. If \param{newvalue}
  5423. produces fewer values than there are store variables, the missing values
  5424. are set to \nil.
  5425. \endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  5426. In the form {\tt (shiftf \i{place1} \i{place2} ... \i{placen} \i{newvalue})},
  5427. the values in \i{place1} through \i{placen} are \term{read} and saved,
  5428. and \i{newvalue} is evaluated, for a total of \f{n}+1 values in all.
  5429. Values 2 through \f{n}+1 are then stored into \i{place1} through \i{placen}, respectively.
  5430. It is as if all the \param{places} form a shift register; the \param{newvalue}
  5431. is shifted in from the right, all values shift over to the left one place,
  5432. and the value shifted out of \i{place1} is returned.
  5433. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  5434. For information about the \term{evaluation} of \term{subforms} of \param{places},
  5435. \seesection\GenRefSubFormEval.
  5436. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  5437. \label Examples::
  5438. \code
  5439. (setq x (list 1 2 3) y 'trash) \EV TRASH
  5440. (shiftf y x (cdr x) '(hi there)) \EV TRASH
  5441. x \EV (2 3)
  5442. y \EV (1 HI THERE)
  5443. (setq x (list 'a 'b 'c)) \EV (A B C)
  5444. (shiftf (cadr x) 'z) \EV B
  5445. x \EV (A Z C)
  5446. (shiftf (cadr x) (cddr x) 'q) \EV Z
  5447. x \EV (A (C) . Q)
  5448. (setq n 0) \EV 0
  5449. (setq x (list 'a 'b 'c 'd)) \EV (A B C D)
  5450. (shiftf (nth (setq n (+ n 1)) x) 'z) \EV B
  5451. x \EV (A Z C D)
  5452. \endcode
  5453. \label Affected By::
  5454. \macref{define-setf-expander},
  5455. \macref{defsetf},
  5456. \varref{*macroexpand-hook*}
  5457. \label Exceptional Situations:\None.
  5458. \label See Also::
  5459. \macref{setf}, \macref{rotatef}, {\secref\GeneralizedReference}
  5460. \label Notes::
  5461. %% Removed per Kawabe's comment #2, first public review.
  5462. % \macref{shiftf} can assign values to lexical as well as dynamic variables.
  5463. The effect of
  5464. \f{(shiftf \param{place1} \param{place2} ... \param{placen} \param{newvalue})}
  5465. is roughly equivalent to
  5466. \code
  5467. (let ((var1 \param{place1})
  5468. (var2 \param{place2})
  5469. ...
  5470. (varn \param{placen})
  5471. (var0 \param{newvalue}))
  5472. (setf \param{place1} var2)
  5473. (setf \param{place2} var3)
  5474. ...
  5475. (setf \param{placen} var0)
  5476. var1)
  5477. \endcode
  5478. except that the latter would evaluate any \term{subforms}
  5479. of each \f{place} twice, whereas \macref{shiftf} evaluates them once.
  5480. For example,
  5481. \code
  5482. (setq n 0) \EV 0
  5483. (setq x (list 'a 'b 'c 'd)) \EV (A B C D)
  5484. (prog1 (nth (setq n (+ n 1)) x)
  5485. (setf (nth (setq n (+ n 1)) x) 'z)) \EV B
  5486. x \EV (A B Z D)
  5487. \endcode
  5488. \endcom
  5489. %%% ========== ROTATEF
  5490. \begincom{rotatef}\ftype{Macro}
  5491. \label Syntax::
  5492. %% 7.2.0 27
  5493. \DefmacWithValues rotatef {\starparam{place}} {\nil}
  5494. \label Arguments and Values::
  5495. \param{place}---a \term{place}.
  5496. \label Description::
  5497. \macref{rotatef} modifies the values of each \param{place} by
  5498. rotating values from one \param{place} into another.
  5499. \issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  5500. If a \param{place} produces more values than there
  5501. are store variables, the extra values are ignored. If a \param{place}
  5502. produces fewer values than there are store variables, the missing values
  5503. are set to \nil.
  5504. \endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  5505. %% 7.2.0 25
  5506. In the form \f{(rotatef \i{place1} \i{place2} ... \i{placen})},
  5507. the values in \i{place1} through \i{placen} are \term{read} and \term{written}.
  5508. Values 2 through \i{n}
  5509. and value 1 are then stored into \i{place1} through \i{placen}.
  5510. It is as if all the places form an end-around shift register
  5511. that is rotated one place to the left, with the value of \i{place1}
  5512. being shifted around the end to \i{placen}.
  5513. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  5514. For information about the \term{evaluation} of \term{subforms} of \param{places},
  5515. \seesection\GenRefSubFormEval.
  5516. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  5517. \label Examples::
  5518. \code
  5519. (let ((n 0)
  5520. (x (list 'a 'b 'c 'd 'e 'f 'g)))
  5521. (rotatef (nth (incf n) x)
  5522. (nth (incf n) x)
  5523. (nth (incf n) x))
  5524. x) \EV (A C D B E F G)
  5525. \endcode
  5526. \label Affected By:\None.
  5527. \label Exceptional Situations:\None.
  5528. \label See Also::
  5529. \macref{define-setf-expander},
  5530. \macref{defsetf},
  5531. \macref{setf},
  5532. \macref{shiftf},
  5533. \varref{*macroexpand-hook*},
  5534. {\secref\GeneralizedReference}
  5535. \label Notes::
  5536. % \macref{rotatef} can be used to assign values to \term{lexical variables}
  5537. % as well as to \term{dynamic variables}.
  5538. %% 7.2.0 26
  5539. The effect of
  5540. \f{(rotatef \param{place1} \param{place2} ... \param{placen})}
  5541. is roughly equivalent to
  5542. \code
  5543. (psetf \param{place1} \param{place2}
  5544. \param{place2} \param{place3}
  5545. ...
  5546. \param{placen} \param{place1})
  5547. \endcode
  5548. except that the latter would evaluate any \term{subforms}
  5549. of each \f{place} twice, whereas \macref{rotatef} evaluates them once.
  5550. \endcom
  5551. %-------------------- Flow Errors --------------------
  5552. \begincom{control-error}\ftype{Condition Type}
  5553. \label Class Precedence List::
  5554. \typeref{control-error},
  5555. \typeref{error},
  5556. \typeref{serious-condition},
  5557. \typeref{condition},
  5558. \typeref{t}
  5559. \label Description::
  5560. \Thetype{control-error} consists of error conditions that result from
  5561. invalid dynamic transfers of control in a program. The errors that
  5562. result from giving \specref{throw} a tag that is not active or from
  5563. giving \specref{go} or \specref{return-from} a tag that is no longer
  5564. dynamically available are \oftype{control-error}.
  5565. \endcom%{control-error}\ftype{Condition Type}
  5566. \begincom{program-error}\ftype{Condition Type}
  5567. \label Class Precedence List::
  5568. \typeref{program-error},
  5569. \typeref{error},
  5570. \typeref{serious-condition},
  5571. \typeref{condition},
  5572. \typeref{t}
  5573. \label Description::
  5574. \Thetype{program-error}
  5575. consists of error conditions related to incorrect program syntax. The
  5576. errors that result from naming a \term{go tag} or a \term{block tag}
  5577. that is not lexically apparent are \oftype{program-error}.
  5578. \endcom%{program-error}\ftype{Condition Type}
  5579. \begincom{undefined-function}\ftype{Condition Type}
  5580. \label Class Precedence List::
  5581. \typeref{undefined-function},
  5582. \typeref{cell-error},
  5583. \typeref{error},
  5584. \typeref{serious-condition},
  5585. \typeref{condition},
  5586. \typeref{t}
  5587. \label Description::
  5588. \Thetype{undefined-function} consists of \term{error} \term{conditions}
  5589. that represent attempts to \term{read} the definition of an \term{undefined function}.
  5590. %Barrett: "name"?
  5591. %KMP: An "undefined function" is by definition just a "name". See glossary.
  5592. The name of the cell (see \typeref{cell-error}) is the \term{function name}
  5593. which was \term{funbound}.
  5594. \label See Also::
  5595. \funref{cell-error-name}
  5596. \endcom%{undefined-function}\ftype{Condition Type}