dict-eval-compile.tex 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358
  1. % -*- Mode: TeX -*-
  2. % Evaluation Control
  3. % Macros
  4. % Declarations
  5. % Introspection
  6. %-------------------- Lambda Expressions --------------------
  7. %%% ========== LAMBDA (symbol)
  8. \begincom{lambda}\ftype{Symbol}
  9. \issue{DECLS-AND-DOC}
  10. \label Syntax::
  11. \Defspec lambda {lambda-list {\DeclsAndDoc} \starparam{form}}
  12. \label Arguments::
  13. \param{lambda-list}---an \term{ordinary lambda list}.
  14. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  15. \param{documentation}---a \term{string}; \noeval.
  16. \param{form}---a \term{form}.
  17. \label Description::
  18. A \term{lambda expression} is a \term{list} that can be used in place of a
  19. \term{function name} in certain contexts to denote a \term{function} by
  20. directly describing its behavior rather than indirectly by referring to the
  21. name of an \term{established} \term{function}.
  22. \param{Documentation} is attached to the denoted \param{function} (if any
  23. is actually created) as a \term{documentation string}.
  24. \label See Also::
  25. \specref{function},
  26. \specref{documentation},
  27. {\secref\LambdaExpressions},
  28. {\secref\LambdaForms},
  29. {\secref\DocVsDecls}
  30. \label Notes::
  31. The \term{lambda form}
  32. \code
  33. ((lambda \param{lambda-list} . \param{body}) . \param{arguments})
  34. \endcode
  35. is semantically equivalent to the \term{function form}
  36. \code
  37. (funcall #'(lambda \param{lambda-list} . \param{body}) . \param{arguments})
  38. \endcode
  39. \endissue{DECLS-AND-DOC}
  40. \endcom%{lambda}
  41. %%% ========== LAMBDA (macro)
  42. \issue{ISO-COMPATIBILITY:ADD-SUBSTRATE}
  43. \begincom{lambda}\ftype{Macro}
  44. \label Syntax::
  45. %% 7.6.0 7
  46. \DefmacWithValues lambda
  47. {lambda-list {\DeclsAndDoc} \starparam{form}}
  48. {\param{function}}
  49. \label Arguments and Values::
  50. \param{lambda-list}---an \term{ordinary lambda list}.
  51. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  52. \param{documentation}---a \term{string}; \noeval.
  53. \param{form}---a \term{form}.
  54. \param{function}---a \term{function}.
  55. \label Description::
  56. Provides a shorthand notation for a \specref{function} \term{special form}
  57. involving a \term{lambda expression} such that:
  58. \code
  59. (lambda \param{lambda-list} {\DeclsAndDoc} \starparam{form})
  60. \EQ (function (lambda \param{lambda-list} {\DeclsAndDoc} \starparam{form}))
  61. \EQ #'(lambda \param{lambda-list} {\DeclsAndDoc} \starparam{form})
  62. \endcode
  63. \label Examples::
  64. \code
  65. (funcall (lambda (x) (+ x 3)) 4) \EV 7
  66. \endcode
  67. \label Side Effects:\None.
  68. \label Affected By:\None.
  69. \label Exceptional Situations:\None.
  70. \label See Also::
  71. \misc{lambda} (symbol)
  72. \label Notes::
  73. This macro could be implemented by:
  74. \code
  75. (defmacro lambda (&whole form &rest bvl-decls-and-body)
  76. (declare (ignore bvl-decls-and-body))
  77. `#',form)
  78. \endcode
  79. \endcom%{lambda}
  80. \endissue{ISO-COMPATIBILITY:ADD-SUBSTRATE}
  81. %-------------------- Evaluation Control --------------------
  82. %%% ========== COMPILE
  83. \begincom{compile}\ftype{Function}
  84. \issue{FUNCTION-NAME:LARGE}
  85. %%\param{Name} has been changed to \param{function-name} throughout.}
  86. \endissue{FUNCTION-NAME:LARGE}
  87. \label Syntax::
  88. \DefunWithValues compile {name {\opt} definition} {function, warnings-p, failure-p}
  89. \label Arguments and Values::
  90. \param{name}---a \term{function name}, or \nil.
  91. %% 25.1.0 5
  92. \param{definition}---a \term{lambda expression} or a \term{function}.
  93. \Default{the function definition of \param{name} if it names a \term{function},
  94. or the \term{macro function} of \param{name} if it names a \term{macro}}
  95. The consequences are undefined if no \param{definition} is supplied
  96. when the \param{name} is \nil.
  97. %% 25.1.0 6
  98. \param{function}---the \param{function-name},
  99. \issue{COMPILED-FUNCTION-REQUIREMENTS:TIGHTEN}
  100. or a \term{compiled function}.
  101. \endissue{COMPILED-FUNCTION-REQUIREMENTS:TIGHTEN}
  102. \param{warnings-p}---a \term{generalized boolean}.
  103. \param{failure-p}---a \term{generalized boolean}.
  104. \label Description::
  105. Compiles an \term{interpreted function}.
  106. %% Moon: Intent is compilation envirionment = startup environment.
  107. %% Just delete this phrase, I think.
  108. %in the current \term{dynamic environment}.
  109. \funref{compile} produces a \term{compiled function} from \param{definition}.
  110. If the \param{definition} is a \term{lambda expression},
  111. it is coerced to a \term{function}.
  112. \issue{COMPILE-ARGUMENT-PROBLEMS-AGAIN:FIX}
  113. If the \param{definition} is already a \term{compiled function},
  114. \funref{compile} either produces that function itself (\ie is an identity operation)
  115. or an equivalent function.
  116. \endissue{COMPILE-ARGUMENT-PROBLEMS-AGAIN:FIX}
  117. \editornote{KMP: There are a number of ambiguities here that still need resolution.}%!!!
  118. % Cases of interest:
  119. % Given: (defmacro foist (x) `(car ,x))
  120. % What do these do:
  121. % (compile 'foist (macro-function 'foist))
  122. % (compile 'foist (symbol-function 'foist))
  123. % (compile 'foist '(lambda (x y) (+ x y)))
  124. If the \param{name} is \nil,
  125. the resulting \term{compiled function} is returned directly as the \term{primary value}.
  126. If a \term{non-nil} \param{name} is given,
  127. then the resulting \term{compiled function} replaces
  128. the existing \term{function} definition of \param{name}
  129. and the \param{name} is returned as the \term{primary value};
  130. if \param{name} is a \term{symbol} that names a \term{macro},
  131. its \term{macro function} is updated
  132. and the \param{name} is returned as the \term{primary value}.
  133. % I moved this paragraph so it isn't in the middle of the discussion
  134. % of compiler diagnostics. --sjl 7 Mar 92
  135. \issue{QUOTE-SEMANTICS:NO-COPYING}
  136. % Constants -> Literal objects. -kmp 15-Jan-91
  137. \term{Literal objects} appearing in code processed by
  138. the \funref{compile} function are neither copied nor \term{coalesced}.
  139. The code resulting from the execution of \funref{compile}
  140. references \term{objects} that are \funref{eql} to the corresponding
  141. \term{objects} in the source code.
  142. \endissue{QUOTE-SEMANTICS:NO-COPYING}
  143. \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  144. \funref{compile} is permitted, but not required, to \term{establish}
  145. a \term{handler} for \term{conditions} \oftype{error}.
  146. For example, the \term{handler} might issue a warning and
  147. restart compilation from some \term{implementation-dependent} point
  148. in order to let the compilation proceed without manual intervention.
  149. \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  150. The \term{secondary value}, \param{warnings-p}, is \term{false}
  151. % clarify ``compiler diagnostics'' --sjl 7 Mar 92
  152. %if no compiler diagnostics were issued, and \term{true} otherwise.
  153. if no \term{conditions} \oftype{error} or \typeref{warning}
  154. were detected by the compiler, and \term{true} otherwise.
  155. The \term{tertiary value}, \param{failure-p}, is \term{false}
  156. % clarify ``compiler diagnostics'' --sjl 7 Mar 92
  157. %if no compiler diagnostics other than \term{style warnings} were issued.
  158. %A value of \term{true} indicates that there were serious compiler diagnostics
  159. %issued, or that other \term{conditions} \oftype{error} or \typeref{warning}
  160. %(but not \oftype{style-warning}) were signaled during compilation.
  161. if no \term{conditions} \oftype{error} or \typeref{warning}
  162. (other than \typeref{style-warning})
  163. were detected by the compiler, and \term{true} otherwise.
  164. \label Examples::
  165. \code
  166. (defun foo () "bar") \EV FOO
  167. (compiled-function-p #'foo) \EV \term{implementation-dependent}
  168. (compile 'foo) \EV FOO
  169. (compiled-function-p #'foo) \EV \term{true}
  170. (setf (symbol-function 'foo)
  171. (compile nil '(lambda () "replaced"))) \EV #<Compiled-Function>
  172. (foo) \EV "replaced"
  173. \endcode
  174. % (defun foo ...) \EV foo ;A function definition.
  175. % (compile 'foo) \EV foo ;Compile it.
  176. % ;Now foo runs faster.
  177. \label Affected By::
  178. \issue{COMPILER-WARNING-STREAM}
  179. \varref{*error-output*},
  180. \endissue{COMPILER-WARNING-STREAM}
  181. \varref{*macroexpand-hook*}.
  182. The presence of macro definitions and proclamations.
  183. \label Exceptional Situations::
  184. \issue{COMPILE-ARGUMENT-PROBLEMS-AGAIN:FIX}
  185. The consequences are undefined if the \term{lexical environment} surrounding the
  186. \term{function} to be compiled contains any \term{bindings} other than those for
  187. \term{macros}, \term{symbol macros}, or \term{declarations}.
  188. % The consequences are undefined if the \term{function} to be compiled
  189. % was defined in a \term{non-null lexical environment}.
  190. % The consequences are unspecified if the \term{function} is already a
  191. % \term{compiled function}.
  192. \endissue{COMPILE-ARGUMENT-PROBLEMS-AGAIN:FIX}
  193. %% should be an error signaled if name is nil and no definition is supplied.
  194. %% also if function is already compiled.
  195. %ERROR and WARNING conditions may be signaled within
  196. % COMPILE or COMPILE-FILE, including arbitrary errors which may
  197. % occur due to compile-time processing of (EVAL-WHEN (:COMPILE-TOPLEVEL) ...)
  198. % forms or macro expansion.
  199. %
  200. % The following information is mostly redundant with info in the chapter 3
  201. % concept section, and contains some inconsistencies. Better to just
  202. % put in a cross-reference. --sjl 4 mar 92
  203. % \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  204. % The following list considers only
  205. % those conditions signaled by the compiler as
  206. % opposed to within the compiler.
  207. %
  208. % An error \oftype{error} might be signaled by the compiler in
  209. % situations where the compilation cannot proceed without
  210. % intervention.
  211. % Examples include
  212. % file open errors and
  213. % syntax errors.
  214. %
  215. % An error \oftype{warning} might be signaled by the compiler in
  216. % situations where the standard explicitly states
  217. % that a warning must, should, or might be signaled.
  218. % Also, an error \oftype{warning} might be signaled
  219. % by the compiler in situations where the compiler can determine
  220. % that a situation with undefined consequences or that would cause
  221. % an error to be signaled would result at runtime.
  222. % Examples include
  223. % violation of type declarations,
  224. % \term{assigning} or \term{binding} a \term{constant variable},
  225. % calling a built-in Lisp function with the wrong number of arguments
  226. % or malformed keyword argument lists,
  227. % referencing a variable declared \declref{ignore},
  228. % and the usage of unrecognized declaration specifiers.
  229. %
  230. % The compiler is permitted to signal errors \oftype{style-warning}
  231. % about matters of programming style. Although \term{style warnings} might
  232. % be signaled in these situations, no implementation is required to
  233. % signal them. However, if an implementation does choose to signal an
  234. % error about matters of programming style,
  235. % that error is \oftype{style-warning} and is signaled by a call to \funref{warn}.
  236. % Examples include
  237. % redefinition of a \term{function} with a different argument list,
  238. % calling a \term{function} with the wrong number of arguments,
  239. % \term{accessing} unreferenced local variables not declared \declref{ignore},
  240. % and usage of declaration specifiers described in the standard but ignored by the compiler.
  241. %
  242. % \issue{COMPILER-WARNING-STREAM}
  243. % %%This is now implied by the remarks about using WARN above.
  244. % %\funref{compile} is permitted to issue warnings through \term{error output}.
  245. % \endissue{COMPILER-WARNING-STREAM}
  246. %
  247. % \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  248. For information about errors detected during the compilation process,
  249. \seesection\FileCompilerExceptions.
  250. \label See Also::
  251. \funref{compile-file}
  252. \label Notes:\None.
  253. \endcom
  254. %%% ========== EVAL
  255. \begincom{eval}\ftype{Function}
  256. \label Syntax::
  257. \DefunWithValues eval {form} {\starparam{result}}
  258. \label Arguments and Values::
  259. \param{form}---a \term{form}.
  260. \param{results}---the \term{values} \term{yielded} by the \term{evaluation} of \param{form}.
  261. %% Goes without saying. -kmp 8-Aug-91
  262. % %% 7.9.2 4
  263. % Returns multiple values if \param{form} produces multiple values.
  264. \label Description::
  265. %% 20.1.0 2
  266. Evaluates \param{form} in the current \term{dynamic environment}
  267. and the \term{null lexical environment}.
  268. %% 20.1.0 1
  269. \funref{eval} is a user interface to the evaluator.
  270. %% 8.2.0 5
  271. The evaluator expands macro calls as if through the use of \funref{macroexpand-1}.
  272. %%% 9.1.0 3
  273. %It is an error to attempt to evaluate a declaration.
  274. %Those \term{forms} that permit declarations to appear
  275. %perform explicit checks for their presence.
  276. \issue{QUOTE-SEMANTICS:NO-COPYING}
  277. Constants appearing in code
  278. processed by \funref{eval} are
  279. not copied nor coalesced. The code resulting from the execution of
  280. \funref{eval}
  281. references \term{objects}
  282. that are \funref{eql} to the corresponding \term{objects} in
  283. the source code.
  284. \endissue{QUOTE-SEMANTICS:NO-COPYING}
  285. %!!! Barmar: What about compiler macros?
  286. \label Examples::
  287. \code
  288. (setq form '(1+ a) a 999) \EV 999
  289. (eval form) \EV 1000
  290. (eval 'form) \EV (1+ A)
  291. (let ((a '(this would break if eval used local value))) (eval form))
  292. \EV 1000
  293. \endcode
  294. \label Affected By:\None.
  295. \label Exceptional Situations:\None.
  296. \label See Also::
  297. \issue{EVALHOOK-STEP-CONFUSION:X3J13-NOV-89}
  298. %\funref{evalhook},
  299. %\funref{applyhook},
  300. \endissue{EVALHOOK-STEP-CONFUSION:X3J13-NOV-89}
  301. \funref{macroexpand-1},
  302. {\secref\EvaluationModel}
  303. \label Notes::
  304. %% 20.1.0 4
  305. To obtain the current dynamic value of a \term{symbol},
  306. use of \funref{symbol-value} is equivalent (and usually preferable)
  307. to use of \funref{eval}.
  308. %% 20.1.0 3
  309. Note that an \funref{eval} \term{form} involves two levels of \term{evaluation}
  310. for its \term{argument}. First, \param{form} is \term{evaluated} by the
  311. normal argument evaluation mechanism as would occur with any \term{call}.
  312. The \term{object} that results from this normal \term{argument} \term{evaluation}
  313. becomes the \term{value} of the \param{form} \term{parameter}, and is then
  314. \term{evaluated} as part of the \funref{eval} \term{form}.
  315. For example:
  316. \code
  317. (eval (list 'cdr (car '((quote (a . b)) c)))) \EV b
  318. \endcode
  319. The \term{argument} \term{form} \f{(list 'cdr (car '((quote (a . b)) c)))} is evaluated
  320. in the usual way to produce the \term{argument} \f{(cdr (quote (a . b)))};
  321. % this is then given to \funref{eval}
  322. % because \funref{eval} is being called explicitly,
  323. % and
  324. \funref{eval} then evaluates its \term{argument}, \f{(cdr (quote (a . b)))}, to produce \f{b}.
  325. Since a single \term{evaluation} already occurs for any \term{argument} \term{form}
  326. in any \term{function form},
  327. \funref{eval} is sometimes said to perform ``an extra level of evaluation.''
  328. \issue{EVALHOOK-STEP-CONFUSION:FIX}
  329. % Hooks are provided for user-supplied debugging routines
  330. % to obtain control during the execution of an interpretive evaluator.
  331. % \funref{evalhook} and \funref{applyhook} provide alternative
  332. % interfaces to the evaluator mechanism for use by these debugging routines.
  333. \endissue{EVALHOOK-STEP-CONFUSION:FIX}
  334. \endcom
  335. %%% ========== EVAL-WHEN
  336. \begincom{eval-when}\ftype{Special Operator}
  337. \label Syntax::
  338. \DefspecWithValues eval-when
  339. {\paren{\starparam{situation}} \starparam{form}}
  340. {\starparam{result}}
  341. \label Arguments and Values::
  342. \issue{EVAL-WHEN-NON-TOP-LEVEL:GENERALIZE-EVAL-NEW-KEYWORDS}
  343. \param{situation}---One of the \term{symbols}
  344. \kwd{compile-toplevel}\idxkwd{compile-toplevel},
  345. \kwd{load-toplevel}\idxkwd{load-toplevel},
  346. \kwd{execute}\idxkwd{execute},
  347. \misc{compile}\idxref{compile},
  348. \misc{load}\idxref{load}, or
  349. \misc{eval}\idxref{eval}.
  350. The use of \misc{eval}, \misc{compile}, and \misc{load} is deprecated.
  351. \issue{EVAL-WHEN-OBSOLETE-KEYWORDS:X3J13-MAR-1993}
  352. %They are supported when \specref{eval-when} is a \term{top level form},
  353. %but their meaning is not defined elsewhere.
  354. \endissue{EVAL-WHEN-OBSOLETE-KEYWORDS:X3J13-MAR-1993}
  355. \endissue{EVAL-WHEN-NON-TOP-LEVEL:GENERALIZE-EVAL-NEW-KEYWORDS}
  356. \param{forms}---an \term{implicit progn}.
  357. \param{results}---the \term{values} of the \term{forms} if they are executed,
  358. or \nil\ if they are not.
  359. \label Description::
  360. %%% 5.3.3 2
  361. %\specref{eval-when} specifies when a particular body
  362. %of code is to be evaluated.
  363. %%% 5.3.3 1.5
  364. %\specref{eval-when} allows pieces of code to
  365. %be executed only at compile time, only in compiled code, or
  366. %when interpreted but not compiled.
  367. %If no \param{forms} are executed, \specref{eval-when} returns
  368. %\nil.
  369. %
  370. %%% 5.3.3 3
  371. %\f{eval} specifies that the interpreter should process the body.
  372. %\f{compile} specifies that the compiler should evaluate the body
  373. %at compile time in the compilation context.
  374. %\f{load} specifies that the compiler should arrange to evaluate
  375. %the forms in the body when the compiled file containing the
  376. %\specref{eval-when} form is \term{loaded}.
  377. %
  378. %The body of \specref{eval-when} is processed as an implicit
  379. %\specref{progn}, but only in the allowed \param{situations}.
  380. %
  381. %
  382. \issue{EVAL-WHEN-NON-TOP-LEVEL:GENERALIZE-EVAL-NEW-KEYWORDS}
  383. The body of an \specref{eval-when} form is processed as an \term{implicit progn},
  384. but only in the \param{situations} listed.
  385. %Each \param{situation} must be a symbol,
  386. % either COMPILE, LOAD, or EVAL.
  387. % The file compilation section only describe processing by COMPILE-FILE.
  388. % We must say something explicit here about EVAL and COMPILE.
  389. % (The last paragraph from the eval-when cleanup has gotten lost.)
  390. % I have rewritten this below to include the missing info. --sjl 5 Mar 92
  391. % The use of the \param{situations} \kwd{compile-toplevel} ({\tt compile}) and
  392. % \kwd{load-toplevel} ({\tt load}) controls whether and when processing
  393. % occurs for \term{top level forms}. The use of
  394. % the situation \kwd{execute} ({\tt eval}) controls whether
  395. % processing occurs for \term{non-top-level forms}.
  396. %
  397. % For a description of \specref{eval-when} processing, \seesection\FileCompilation.
  398. The use of the \param{situations} \kwd{compile-toplevel} (or {\tt compile}) and
  399. \kwd{load-toplevel} (or {\tt load}) controls whether and when \term{evaluation}
  400. occurs when \specref{eval-when} appears as a \term{top level form} in
  401. code processed by \funref{compile-file}. \Seesection\FileCompilation.
  402. The use of the \param{situation} \kwd{execute} (or {\tt eval}) controls whether
  403. evaluation occurs for other \specref{eval-when} \term{forms}; that is,
  404. those that are not \term{top level forms}, or those in code processed by
  405. \funref{eval} or \varref{compile}. If the \kwd{execute} situation is
  406. specified in such a \term{form}, then the body \param{forms} are processed as
  407. an \term{implicit progn}; otherwise, the \specref{eval-when} \term{form}
  408. returns \nil.
  409. % The \specref{eval-when}
  410. %construct can be more precisely understood in terms of
  411. % a model of how the file compiler, COMPILE-FILE, processes forms in a
  412. % file to be compiled.
  413. %When successive \term{forms} are
  414. %read from the file by \funref{compile-file},
  415. %these \term{top level forms} are normally processed in
  416. % not-compile-time mode. There is one other mode, called
  417. % compile-time-too mode, that is also used for processing \term{top level forms}.
  418. % The \specref{eval-when} special form
  419. %is used to annotate a program
  420. % in a way that allows the program doing the processing to select
  421. % the appropriate mode.
  422. %
  423. %When \funref{compile-file}
  424. %encounters an \specref{eval-when} form, the \term{form}
  425. %is handled according to
  426. %the table in \thenextfigure.
  427. %
  428. %\boxfig
  429. %{\dimen0=.75pc
  430. %\tabskip \dimen0 plus .5 fil
  431. %\halign to \hsize {#\hfil\tabskip \dimen0 plus 1fil&#\hfil\tabskip
  432. %\dimen0 plus .5 fil&#\hfil\tabskip \dimen0 plus 1fil&#\hfil\tabskip \dimen0 plus 1fil
  433. %&#\hfil\cr
  434. %\noalign{\vskip -9pt}
  435. %\hfil{\bf A} & {\bf B} & {\bf C} & {\bf D}& {\bf Action} \cr
  436. %& & & & \cr
  437. % Yes & Yes &-- &-- &Process body in compile-time-too
  438. %mode\cr
  439. % No &Yes &Yes &Yes &Process body in compile-time-too mode\cr
  440. % No &Yes &Yes &No &Process body in not-compile-time mode\cr
  441. % No &Yes &No &-- &Process body in not-compile-time mode\cr
  442. % Yes &No &-- &-- &Evaluate body\cr
  443. % No &No &Yes &Yes &Evaluate body\cr
  444. % No &No &Yes &No &do nothing\cr
  445. % No &No &No &-- &do nothing\cr
  446. %\noalign{\vskip -9pt}
  447. %}}
  448. %\caption{\specref{eval-when} processing}
  449. %\endfig
  450. %Column A indicates
  451. %{\tt :compile-toplevel} processing.
  452. %Column B indicates \kwd{load-toplevel} processing.
  453. %Column C indicates {\tt :execute} processing.
  454. %Column D indicates compile-time-too processing.
  455. %
  456. % Process body means to process the body (using the procedure
  457. % outlined in this subsection) as an implicit toplevel \specref{progn}.
  458. %
  459. %
  460. % Evaluate body means to evaluate the body \param{forms} as an
  461. % \term{implicit progn} in the
  462. % % dynamic execution context
  463. % \term{dynamic environment} of the compiler and in the
  464. % \term{lexical environment} in which the \specref{eval-when} appears.
  465. %
  466. % For an \specref{eval-when}
  467. %form that is not a \term{top level form},
  468. %if the \kwd{execute} situation is specified,
  469. %the body of the \specref{eval-when}
  470. %is treated as an \term{implicit progn}. Otherwise, the
  471. %\specref{eval-when}
  472. % form returns \nil.
  473. %An \specref{eval-when} form is a \term{non-top-level form}
  474. %if it is one of the following:
  475. %in the interpreter, in \funref{compile}, or in \funref{compile-file}
  476. %but not a \term{top level form}.
  477. \endissue{EVAL-WHEN-NON-TOP-LEVEL:GENERALIZE-EVAL-NEW-KEYWORDS}
  478. %!!! Barmar: Redundant. (KMP: I'll have to think about that.)
  479. \issue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  480. \specref{eval-when}
  481. normally appears as a \term{top level form}, but it is meaningful
  482. for it to appear as a \term{non-top-level form}.
  483. However, the compile-time side
  484. effects described in {\secref\Compilation}
  485. only take place when \specref{eval-when} appears as a
  486. \term{top level form}.
  487. \endissue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  488. %\specref{eval-when} is meaningful only as a \term{top level form}.
  489. \label Examples::
  490. %!!! Are the EVAL-WHEN return values correct?? -kmp 29-Aug-91
  491. %% Moon: Why isn't this compile toplevel? Maybe this example is not portable?
  492. %% It's an obfuscating example anyway. Delete it.
  493. % \code
  494. % (setq temp 3) \EV 3
  495. % (eval-when (:compile-toplevel) (setq temp 2)) \EV NIL
  496. % temp \EV 3
  497. % (eval-when (:execute) (setq temp 2)) \EV 2
  498. % temp \EV 2
  499. % \endcode
  500. %% 5.3.3 10
  501. One example of the use of \specref{eval-when} is that for the
  502. compiler to be able to read a file properly when it uses user-defined
  503. \term{reader macros}, it is necessary to write
  504. \code
  505. (eval-when (:compile-toplevel :load-toplevel :execute)
  506. (set-macro-character #\\$ #'(lambda (stream char)
  507. (declare (ignore char))
  508. (list 'dollar (read stream))))) \EV T
  509. \endcode
  510. This causes the call to \funref{set-macro-character} to be executed
  511. in the compiler's execution environment, thereby modifying its
  512. reader syntax table.
  513. \code
  514. ;;; The EVAL-WHEN in this case is not at toplevel, so only the :EXECUTE
  515. ;;; keyword is considered. At compile time, this has no effect.
  516. ;;; At load time (if the LET is at toplevel), or at execution time
  517. ;;; (if the LET is embedded in some other form which does not execute
  518. ;;; until later) this sets (SYMBOL-FUNCTION 'FOO1) to a function which
  519. ;;; returns 1.
  520. (let ((x 1))
  521. (eval-when (:execute :load-toplevel :compile-toplevel)
  522. (setf (symbol-function 'foo1) #'(lambda () x))))
  523. ;;; If this expression occurs at the toplevel of a file to be compiled,
  524. ;;; it has BOTH a compile time AND a load-time effect of setting
  525. ;;; (SYMBOL-FUNCTION 'FOO2) to a function which returns 2.
  526. (eval-when (:execute :load-toplevel :compile-toplevel)
  527. (let ((x 2))
  528. (eval-when (:execute :load-toplevel :compile-toplevel)
  529. (setf (symbol-function 'foo2) #'(lambda () x)))))
  530. ;;; If this expression occurs at the toplevel of a file to be compiled,
  531. ;;; it has BOTH a compile time AND a load-time effect of setting the
  532. ;;; function cell of FOO3 to a function which returns 3.
  533. (eval-when (:execute :load-toplevel :compile-toplevel)
  534. (setf (symbol-function 'foo3) #'(lambda () 3)))
  535. ;;; #4: This always does nothing. It simply returns NIL.
  536. (eval-when (:compile-toplevel)
  537. (eval-when (:compile-toplevel)
  538. (print 'foo4)))
  539. ;;; If this form occurs at toplevel of a file to be compiled, FOO5 is
  540. ;;; printed at compile time. If this form occurs in a non-top-level
  541. ;;; position, nothing is printed at compile time. Regardless of context,
  542. ;;; nothing is ever printed at load time or execution time.
  543. (eval-when (:compile-toplevel)
  544. (eval-when (:execute)
  545. (print 'foo5)))
  546. ;;; If this form occurs at toplevel of a file to be compiled, FOO6 is
  547. ;;; printed at compile time. If this form occurs in a non-top-level
  548. ;;; position, nothing is printed at compile time. Regardless of context,
  549. ;;; nothing is ever printed at load time or execution time.
  550. (eval-when (:execute :load-toplevel)
  551. (eval-when (:compile-toplevel)
  552. (print 'foo6)))
  553. \endcode
  554. \label Affected By:\None.
  555. \label Exceptional Situations:\None.
  556. \label See Also::
  557. \funref{compile-file}, {\secref\Compilation}
  558. \label Notes::
  559. \issue{EVAL-WHEN-NON-TOP-LEVEL:GENERALIZE-EVAL-NEW-KEYWORDS}
  560. The following effects are logical consequences of the definition of
  561. \specref{eval-when}:
  562. \beginlist
  563. \itemitem{\bull}
  564. Execution of a single \specref{eval-when}
  565. expression executes the body code at most once.
  566. \itemitem{\bull}
  567. \term{Macros} intended for use in \term{top level forms}
  568. should be written so that side-effects are done by the \term{forms}
  569. in the macro expansion. The macro-expander itself should not do
  570. the side-effects.
  571. For example:
  572. Wrong:
  573. \code
  574. (defmacro foo ()
  575. (really-foo)
  576. `(really-foo))
  577. \endcode
  578. Right:
  579. \code
  580. (defmacro foo ()
  581. `(eval-when (:compile-toplevel :execute :load-toplevel) (really-foo)))
  582. \endcode
  583. Adherence to this convention means that such \term{macros} behave
  584. intuitively when appearing as \term{non-top-level forms}.
  585. \itemitem{\bull}
  586. Placing a variable binding around an \specref{eval-when} reliably
  587. captures the binding because the compile-time-too mode cannot occur
  588. (\ie introducing a variable binding means that the \specref{eval-when}
  589. is not a \term{top level form}).
  590. For example,
  591. \code
  592. (let ((x 3))
  593. (eval-when (:execute :load-toplevel :compile-toplevel) (print x)))
  594. \endcode
  595. prints {\tt 3}
  596. at execution (\ie load) time, and does not print anything at
  597. compile time. This is important so that expansions of
  598. \macref{defun} and
  599. \macref{defmacro}
  600. can be done in terms of \specref{eval-when} and can correctly capture
  601. the \term{lexical environment}.
  602. \code
  603. (defun bar (x) (defun foo () (+ x 3)))
  604. \endcode
  605. might expand into
  606. \code
  607. (defun bar (x)
  608. (progn (eval-when (:compile-toplevel)
  609. (compiler::notice-function-definition 'foo '(x)))
  610. (eval-when (:execute :load-toplevel)
  611. (setf (symbol-function 'foo) #'(lambda () (+ x 3))))))
  612. \endcode
  613. which would be treated by the above rules the same as
  614. \code
  615. (defun bar (x)
  616. (setf (symbol-function 'foo) #'(lambda () (+ x 3))))
  617. \endcode
  618. when the definition of \f{bar} is not a \term{top level form}.
  619. \endlist
  620. \endissue{EVAL-WHEN-NON-TOP-LEVEL:GENERALIZE-EVAL-NEW-KEYWORDS}
  621. \endcom
  622. %% Replaced per X3J13. -kmp 05-Oct-93
  623. % %%% ========== LOAD-TIME-VALUE
  624. % \begincom{load-time-value}\ftype{Special Operator}
  625. % \issue{LOAD-TIME-EVAL:R**3-NEW-SPECIAL-FORM}
  626. %
  627. % \label Syntax::
  628. %
  629. % \DefspecWithValues load-time-value {form {\opt} read-only-p} {object}
  630. %
  631. % \label Arguments and Values::
  632. %
  633. % \param{form}---a \term{form}; \evalspecial.
  634. %
  635. % \param{read-only-p}---one of the \term{symbols} \t\ or \nil; \noeval.
  636. %
  637. % \param{object}---the \term{primary value} resulting from evaluating \param{form}.
  638. %
  639. % \label Description::
  640. %
  641. % \specref{load-time-value} provides a mechanism for delaying evaluation of \param{form}
  642. % until the expression is in the run-time environment; \seesection\Compilation.
  643. %
  644. % \param{Read-only-p} designates whether the result can be considered a
  645. % \term{constant object}. If \nil\ (the default), the result must be considered
  646. % ordinary, modifiable data. If \t, the result is a read-only quantity
  647. % that can, if appropriate to the \term{implementation},
  648. % be copied into read-only space and/or \term{coalesced} with \term{similar}
  649. % \term{constant objects} from other \term{programs}.
  650. %
  651. % If a \specref{load-time-value} expression is processed by \funref{compile-file},
  652. % the compiler performs its normal semantic processing (such as macro expansion
  653. % and translation into machine code) on \param{form}, but arranges for the
  654. % execution of \param{form} to occur at load time in a \term{null lexical environment},
  655. % with the result of this \term{evaluation} then being treated as
  656. % %an immediate quantity
  657. % a \term{literal object}
  658. % at run time. It is guaranteed that the evaluation of \param{form}
  659. % will take place only once when the \term{file} is \term{loaded}, but
  660. % the order of evaluation with respect to the evaluation of
  661. % \term{top level forms} in the file is \term{implementation-dependent}.
  662. % \idxtext{order of evaluation}\idxtext{evaluation order}
  663. %
  664. % If a \specref{load-time-value} expression appears within a function compiled
  665. % with \funref{compile}, the \param{form} is evaluated at compile time in a
  666. % \term{null lexical environment}. The result of this compile-time evaluation
  667. % is treated as
  668. % %an immediate quantity
  669. % a \term{literal object}
  670. % in the compiled code.
  671. %
  672. % If a \specref{load-time-value} expression is processed by \funref{eval},
  673. % \param{form} is evaluated in a \term{null lexical environment},
  674. % and one value is returned. Implementations that implicitly compile
  675. % (or partially compile) expressions processed by \funref{eval}
  676. % %"can" => "might". Barrett thought "can" was clumsy.
  677. % might evaluate \param{form} only once, at the time this compilation is performed.
  678. % %This is intentionally similar to the
  679. % % freedom which implementations are given for the time of expanding
  680. % % macros in interpreted code.
  681. %
  682. % If the \term{same} \term{list} \f{(load-time-value \param{form})} is
  683. % evaluated or compiled more than once, it is \term{implementation-dependent}
  684. % whether \param{form} is evaluated only once or is evaluated more than once.
  685. % This can happen both when an expression being evaluated or compiled shares
  686. % substructure, and when the \term{same} \term{form} is processed by \funref{eval} or
  687. % \funref{compile} multiple times.
  688. % Since a \specref{load-time-value} expression can be
  689. % referenced in more than one place and can be evaluated multiple times
  690. % by \funref{eval}, it is
  691. % \term{implementation-dependent} whether each execution returns
  692. % a fresh \term{object}
  693. % or returns the same \term{object} as some other execution.
  694. % Users must use caution when destructively modifying the resulting
  695. % \term{object}.
  696. %
  697. % If two lists \f{(load-time-value \param{form})}
  698. % that are the \term{same} under \funref{equal} but are not \term{identical}
  699. % are evaluated or compiled,
  700. % their values always come from distinct evaluations of \param{form}.
  701. % %Per Barrett: "These forms" => "Their values"
  702. % Their \term{values} may not be coalesced
  703. % %Added per Barmar:
  704. % unless \param{read-only-p} is \t.
  705. %
  706. % \label Examples:\None.
  707. %
  708. % \label Affected By:\None.
  709. %
  710. % \label Exceptional Situations:\None.
  711. %
  712. % \label See Also::
  713. %
  714. % \funref{compile-file},
  715. % \funref{compile},
  716. % \funref{eval},
  717. % {\secref\MinimalCompilation},
  718. % {\secref\Compilation}
  719. %
  720. % \label Notes::
  721. %
  722. % \specref{load-time-value} must appear outside of quoted structure in a
  723. % ``for \term{evaluation}'' position. In situations which would appear to call
  724. % for use of \specref{load-time-value} within a quoted structure,
  725. % the \term{backquote} \term{reader macro} is probably called for;
  726. % \seesection\Backquote.
  727. %
  728. % \endissue{LOAD-TIME-EVAL:R**3-NEW-SPECIAL-FORM}
  729. %
  730. % \endcom
  731. %%% ========== LOAD-TIME-VALUE
  732. \begincom{load-time-value}\ftype{Special Operator}
  733. \issue{LOAD-TIME-EVAL:R**3-NEW-SPECIAL-FORM}
  734. \label Syntax::
  735. \DefspecWithValues load-time-value {form {\opt} read-only-p} {object}
  736. \label Arguments and Values::
  737. \param{form}---a \term{form}; \evalspecial.
  738. \param{read-only-p}---a \term{boolean}; \noeval.
  739. \param{object}---the \term{primary value} resulting from evaluating \param{form}.
  740. \label Description::
  741. \specref{load-time-value} provides a mechanism for delaying evaluation of \param{form}
  742. until the expression is in the run-time environment; \seesection\Compilation.
  743. \param{Read-only-p} designates whether the result can be considered a
  744. \term{constant object}.
  745. If \t,
  746. the result is a read-only quantity that can,
  747. if appropriate to the \term{implementation},
  748. be copied into read-only space and/or \term{coalesced} with \term{similar}
  749. \term{constant objects} from other \term{programs}.
  750. If \nil\ (the default),
  751. the result must be neither copied nor coalesced;
  752. it must be considered to be potentially modifiable data.
  753. If a \specref{load-time-value} expression is processed by \funref{compile-file},
  754. the compiler performs its normal semantic processing (such as macro expansion
  755. and translation into machine code) on \param{form}, but arranges for the
  756. execution of \param{form} to occur at load time in a \term{null lexical environment},
  757. with the result of this \term{evaluation} then being treated as
  758. %an immediate quantity
  759. a \term{literal object}
  760. at run time. It is guaranteed that the evaluation of \param{form}
  761. will take place only once when the \term{file} is \term{loaded}, but
  762. the order of evaluation with respect to the evaluation of
  763. \term{top level forms} in the file is \term{implementation-dependent}.
  764. \idxtext{order of evaluation}\idxtext{evaluation order}
  765. If a \specref{load-time-value} expression appears within a function compiled
  766. with \funref{compile}, the \param{form} is evaluated at compile time in a
  767. \term{null lexical environment}. The result of this compile-time evaluation
  768. is treated as
  769. %an immediate quantity
  770. a \term{literal object}
  771. in the compiled code.
  772. If a \specref{load-time-value} expression is processed by \funref{eval},
  773. \param{form} is evaluated in a \term{null lexical environment},
  774. and one value is returned. Implementations that implicitly compile
  775. (or partially compile) expressions processed by \funref{eval}
  776. %"can" => "might". Barrett thought "can" was clumsy.
  777. might evaluate \param{form} only once, at the time this compilation is performed.
  778. %This is intentionally similar to the
  779. % freedom which implementations are given for the time of expanding
  780. % macros in interpreted code.
  781. If the \term{same} \term{list} \f{(load-time-value \param{form})} is
  782. evaluated or compiled more than once, it is \term{implementation-dependent}
  783. whether \param{form} is evaluated only once or is evaluated more than once.
  784. This can happen both when an expression being evaluated or compiled shares
  785. substructure, and when the \term{same} \term{form} is processed by \funref{eval} or
  786. \funref{compile} multiple times.
  787. Since a \specref{load-time-value} expression can be
  788. referenced in more than one place and can be evaluated multiple times
  789. by \funref{eval}, it is
  790. \term{implementation-dependent} whether each execution returns
  791. a fresh \term{object}
  792. or returns the same \term{object} as some other execution.
  793. Users must use caution when destructively modifying the resulting
  794. \term{object}.
  795. If two lists \f{(load-time-value \param{form})}
  796. that are the \term{same} under \funref{equal} but are not \term{identical}
  797. are evaluated or compiled,
  798. their values always come from distinct evaluations of \param{form}.
  799. %Per Barrett: "These forms" => "Their values"
  800. Their \term{values} may not be coalesced
  801. %Added per Barmar:
  802. unless \param{read-only-p} is \t.
  803. \label Examples::
  804. \code
  805. ;;; The function INCR1 always returns the same value, even in different images.
  806. ;;; The function INCR2 always returns the same value in a given image,
  807. ;;; but the value it returns might vary from image to image.
  808. (defun incr1 (x) (+ x #.(random 17)))
  809. (defun incr2 (x) (+ x (load-time-value (random 17))))
  810. ;;; The function FOO1-REF references the nth element of the first of
  811. ;;; the *FOO-ARRAYS* that is available at load time. It is permissible for
  812. ;;; that array to be modified (e.g., by SET-FOO1-REF); FOO1-REF will see the
  813. ;;; updated values.
  814. (defvar *foo-arrays* (list (make-array 7) (make-array 8)))
  815. (defun foo1-ref (n) (aref (load-time-value (first *my-arrays*) nil) n))
  816. (defun set-foo1-ref (n val)
  817. (setf (aref (load-time-value (first *my-arrays*) nil) n) val))
  818. ;;; The function BAR1-REF references the nth element of the first of
  819. ;;; the *BAR-ARRAYS* that is available at load time. The programmer has
  820. ;;; promised that the array will be treated as read-only, so the system
  821. ;;; can copy or coalesce the array.
  822. (defvar *bar-arrays* (list (make-array 7) (make-array 8)))
  823. (defun bar1-ref (n) (aref (load-time-value (first *my-arrays*) t) n))
  824. ;;; This use of LOAD-TIME-VALUE permits the indicated vector to be coalesced
  825. ;;; even though NIL was specified, because the object was already read-only
  826. ;;; when it was written as a literal vector rather than created by a constructor.
  827. ;;; User programs must treat the vector v as read-only.
  828. (defun baz-ref (n)
  829. (let ((v (load-time-value #(A B C) nil)))
  830. (values (svref v n) v)))
  831. ;;; This use of LOAD-TIME-VALUE permits the indicated vector to be coalesced
  832. ;;; even though NIL was specified in the outer situation because T was specified
  833. ;;; in the inner situation. User programs must treat the vector v as read-only.
  834. (defun baz-ref (n)
  835. (let ((v (load-time-value (load-time-value (vector 1 2 3) t) nil)))
  836. (values (svref v n) v)))
  837. \endcode
  838. \label Affected By:\None.
  839. \label Exceptional Situations:\None.
  840. \label See Also::
  841. \funref{compile-file},
  842. \funref{compile},
  843. \funref{eval},
  844. {\secref\MinimalCompilation},
  845. {\secref\Compilation}
  846. \label Notes::
  847. \specref{load-time-value} must appear outside of quoted structure in a
  848. ``for \term{evaluation}'' position. In situations which would appear to call
  849. for use of \specref{load-time-value} within a quoted structure,
  850. the \term{backquote} \term{reader macro} is probably called for;
  851. \seesection\Backquote.
  852. Specifying \nil\ for \param{read-only-p} is not a way to force an object
  853. to become modifiable if it has already been made read-only. It is only a way
  854. to say that, for an object that is modifiable, this operation is not intended
  855. to make that object read-only.
  856. \endissue{LOAD-TIME-EVAL:R**3-NEW-SPECIAL-FORM}
  857. \endcom
  858. %%% ========== QUOTE
  859. \begincom{quote}\ftype{Special Operator}
  860. \label Syntax::
  861. \DefspecWithValues quote {object} {object}
  862. \label Arguments and Values::
  863. \param{object}---an \term{object}; \noeval.
  864. \label Description::
  865. %% 7.1.1 3
  866. \Thespecop{quote} just returns \param{object}.
  867. % added --sjl 3 Mar 92
  868. The consequences are undefined if \term{literal objects} (including
  869. \term{quoted objects}) are destructively modified.
  870. \label Examples::
  871. \code
  872. (setq a 1) \EV 1
  873. (quote (setq a 3)) \EV (SETQ A 3)
  874. a \EV 1
  875. 'a \EV A
  876. ''a \EV (QUOTE A)
  877. '''a \EV (QUOTE (QUOTE A))
  878. (setq a 43) \EV 43
  879. (list a (cons a 3)) \EV (43 (43 . 3))
  880. (list (quote a) (quote (cons a 3))) \EV (A (CONS A 3))
  881. 1 \EV 1
  882. '1 \EV 1
  883. "foo" \EV "foo"
  884. '"foo" \EV "foo"
  885. (car '(a b)) \EV A
  886. '(car '(a b)) \EV (CAR (QUOTE (A B)))
  887. #(car '(a b)) \EV #(CAR (QUOTE (A B)))
  888. '#(car '(a b)) \EV #(CAR (QUOTE (A B)))
  889. \endcode
  890. \label Affected By:\None.
  891. \label Exceptional Situations:\None.
  892. \label See Also::
  893. {\secref\Evaluation},
  894. {\secref\QuoteMacro},
  895. \issue{CONSTANT-MODIFICATION:DISALLOW}
  896. {\secref\ConstantModification}
  897. \endissue{CONSTANT-MODIFICATION:DISALLOW}
  898. \label Notes::
  899. The textual notation \f{'\param{object}} is equivalent to \f{(quote \param{object})};
  900. \seesection\ConstantModification.
  901. %% 7.1.0 1
  902. Some \term{objects}, called \term{self-evaluating objects},
  903. do not require quotation by \specref{quote}.
  904. However, \term{symbols} and \term{lists} are used to represent parts of programs,
  905. and so would not be useable as constant data in a program without \specref{quote}.
  906. Since \specref{quote} suppresses the \term{evaluation} of these \term{objects},
  907. they become data rather than program.
  908. \endcom
  909. %-------------------- Macros --------------------
  910. %%% ========== COMPILER-MACRO-FUNCTION
  911. \begincom{compiler-macro-function}\ftype{Accessor}
  912. \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  913. \label Syntax::
  914. \DefunWithValues compiler-macro-function {name {\opt} environment} {function}
  915. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  916. \Defsetf compiler-macro-function {name {\opt} environment} {new-function}
  917. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  918. \label Arguments and Values::
  919. \param{name}---a \term{function name}.
  920. \param{environment}---an \term{environment} \term{object}.
  921. \param{function}, \param{new-function}---a \term{compiler macro function}, or \nil.
  922. \label Description::
  923. \term{Accesses} the \term{compiler macro function} named \param{name}, if any,
  924. in the \param{environment}.
  925. A value of \nil\ denotes the absence of a \term{compiler macro function} named \param{name}.
  926. \label Examples:\None.
  927. \label Affected By:\None.
  928. \label Exceptional Situations::
  929. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  930. The consequences are undefined if \param{environment} is \term{non-nil}
  931. in a use of \SETFof{compiler-macro-function}.
  932. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  933. \label See Also::
  934. \macref{define-compiler-macro}, {\secref\CompilerMacros}
  935. \label Notes:\None.
  936. \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  937. \endcom
  938. %%% ========== DEFINE-COMPILER-MACRO
  939. \begincom{define-compiler-macro}\ftype{Macro}
  940. \issue{DECLS-AND-DOC}
  941. \label Syntax::
  942. \DefmacWithValuesNewline define-compiler-macro
  943. {name lambda-list {\DeclsAndDoc} \starparam{form}}
  944. {name}
  945. \label Arguments and Values::
  946. \param{name}---a \term{function name}.
  947. % tweaked. --sjl 5 Mar 92
  948. % \param{lambda-list}---a \term{lambda list};
  949. % can contain the lambda list keywords
  950. % \keyref{allow-other-keys},
  951. % \keyref{aux},
  952. % \keyref{body},
  953. % \keyref{environment},
  954. % \keyref{key},
  955. % \keyref{optional},
  956. % \keyref{rest},
  957. % and
  958. % \keyref{whole}.
  959. \param{lambda-list}---a \term{macro lambda list}.
  960. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  961. \param{documentation}---a \term{string}; \noeval.
  962. \param{form}---a \term{form}.
  963. \label Description::
  964. \editornote{KMP: This definition probably needs to be fully expanded to not
  965. refer through the definition of defmacro, but should suffice for now.}
  966. % If this rewriting happens, be sure to copy the compile-time side-effects
  967. % info from DEFMACRO too. -- sjl 5 Mar 92
  968. This is the normal mechanism for defining a \term{compiler macro function}.
  969. Its manner of definition is the same as for \macref{defmacro}; the only
  970. differences are:
  971. \beginlist
  972. \itemitem{\bull} The \param{name} can be a \term{function name} naming
  973. any \term{function} or \term{macro}.
  974. \itemitem{\bull} The expander function is installed as a \term{compiler macro function}
  975. for the \param{name}, rather than as a \term{macro function}.
  976. \itemitem{\bull} The \keyref{whole} argument is bound to the form argument that
  977. is passed to the \term{compiler macro function}. The remaining lambda-list
  978. parameters are specified as if this form contained the function name in the
  979. \term{car} and the actual arguments in the \term{cdr}, but if the \term{car}
  980. of the actual form is the symbol \funref{funcall}, then the destructuring of
  981. the arguments is actually performed using its \term{cddr} instead.
  982. \itemitem{\bull}\issue{DOCUMENTATION-FUNCTION-BUGS:FIX}%
  983. \param{Documentation} is attached as a \term{documentation string}
  984. to \param{name} (as kind \specref{compiler-macro})
  985. and to the \term{compiler macro function}.
  986. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  987. \itemitem{\bull} Unlike an ordinary \term{macro}, a \term{compiler macro}
  988. can decline to provide an expansion merely by returning a form that is
  989. the \term{same} as the original (which can be obtained by using
  990. \keyref{whole}).
  991. \endlist
  992. \label Examples::
  993. \code
  994. (defun square (x) (expt x 2)) \EV SQUARE
  995. (define-compiler-macro square (&whole form arg)
  996. (if (atom arg)
  997. `(expt ,arg 2)
  998. (case (car arg)
  999. (square (if (= (length arg) 2)
  1000. `(expt ,(nth 1 arg) 4)
  1001. form))
  1002. (expt (if (= (length arg) 3)
  1003. (if (numberp (nth 2 arg))
  1004. `(expt ,(nth 1 arg) ,(* 2 (nth 2 arg)))
  1005. `(expt ,(nth 1 arg) (* 2 ,(nth 2 arg))))
  1006. form))
  1007. (otherwise `(expt ,arg 2))))) \EV SQUARE
  1008. (square (square 3)) \EV 81
  1009. (macroexpand '(square x)) \EV (SQUARE X), \term{false}
  1010. (funcall (compiler-macro-function 'square) '(square x) nil)
  1011. \EV (EXPT X 2)
  1012. (funcall (compiler-macro-function 'square) '(square (square x)) nil)
  1013. \EV (EXPT X 4)
  1014. (funcall (compiler-macro-function 'square) '(funcall #'square x) nil)
  1015. \EV (EXPT X 2)
  1016. (defun distance-positional (x1 y1 x2 y2)
  1017. (sqrt (+ (expt (- x2 x1) 2) (expt (- y2 y1) 2))))
  1018. \EV DISTANCE-POSITIONAL
  1019. (defun distance (&key (x1 0) (y1 0) (x2 x1) (y2 y1))
  1020. (distance-positional x1 y1 x2 y2))
  1021. \EV DISTANCE
  1022. (define-compiler-macro distance (&whole form
  1023. &rest key-value-pairs
  1024. &key (x1 0 x1-p)
  1025. (y1 0 y1-p)
  1026. (x2 x1 x2-p)
  1027. (y2 y1 y2-p)
  1028. &allow-other-keys
  1029. &environment env)
  1030. (flet ((key (n) (nth (* n 2) key-value-pairs))
  1031. (arg (n) (nth (1+ (* n 2)) key-value-pairs))
  1032. (simplep (x)
  1033. (let ((expanded-x (macroexpand x env)))
  1034. (or (constantp expanded-x env)
  1035. (symbolp expanded-x)))))
  1036. (let ((n (/ (length key-value-pairs) 2)))
  1037. (multiple-value-bind (x1s y1s x2s y2s others)
  1038. (loop for (key) on key-value-pairs by #'cddr
  1039. count (eq key ':x1) into x1s
  1040. count (eq key ':y1) into y1s
  1041. count (eq key ':x2) into x2s
  1042. count (eq key ':y1) into y2s
  1043. count (not (member key '(:x1 :x2 :y1 :y2)))
  1044. into others
  1045. finally (return (values x1s y1s x2s y2s others)))
  1046. (cond ((and (= n 4)
  1047. (eq (key 0) :x1)
  1048. (eq (key 1) :y1)
  1049. (eq (key 2) :x2)
  1050. (eq (key 3) :y2))
  1051. `(distance-positional ,x1 ,y1 ,x2 ,y2))
  1052. ((and (if x1-p (and (= x1s 1) (simplep x1)) t)
  1053. (if y1-p (and (= y1s 1) (simplep y1)) t)
  1054. (if x2-p (and (= x2s 1) (simplep x2)) t)
  1055. (if y2-p (and (= y2s 1) (simplep y2)) t)
  1056. (zerop others))
  1057. `(distance-positional ,x1 ,y1 ,x2 ,y2))
  1058. ((and (< x1s 2) (< y1s 2) (< x2s 2) (< y2s 2)
  1059. (zerop others))
  1060. (let ((temps (loop repeat n collect (gensym))))
  1061. `(let ,(loop for i below n
  1062. collect (list (nth i temps) (arg i)))
  1063. (distance
  1064. ,@(loop for i below n
  1065. append (list (key i) (nth i temps)))))))
  1066. (t form))))))
  1067. \EV DISTANCE
  1068. (dolist (form
  1069. '((distance :x1 (setq x 7) :x2 (decf x) :y1 (decf x) :y2 (decf x))
  1070. (distance :x1 (setq x 7) :y1 (decf x) :x2 (decf x) :y2 (decf x))
  1071. (distance :x1 (setq x 7) :y1 (incf x))
  1072. (distance :x1 (setq x 7) :y1 (incf x) :x1 (incf x))
  1073. (distance :x1 a1 :y1 b1 :x2 a2 :y2 b2)
  1074. (distance :x1 a1 :x2 a2 :y1 b1 :y2 b2)
  1075. (distance :x1 a1 :y1 b1 :z1 c1 :x2 a2 :y2 b2 :z2 c2)))
  1076. (print (funcall (compiler-macro-function 'distance) form nil)))
  1077. \OUT (LET ((#:G6558 (SETQ X 7))
  1078. \OUT (#:G6559 (DECF X))
  1079. \OUT (#:G6560 (DECF X))
  1080. \OUT (#:G6561 (DECF X)))
  1081. \OUT (DISTANCE :X1 #:G6558 :X2 #:G6559 :Y1 #:G6560 :Y2 #:G6561))
  1082. \OUT (DISTANCE-POSITIONAL (SETQ X 7) (DECF X) (DECF X) (DECF X))
  1083. \OUT (LET ((#:G6567 (SETQ X 7))
  1084. \OUT (#:G6568 (INCF X)))
  1085. \OUT (DISTANCE :X1 #:G6567 :Y1 #:G6568))
  1086. \OUT (DISTANCE :X1 (SETQ X 7) :Y1 (INCF X) :X1 (INCF X))
  1087. \OUT (DISTANCE-POSITIONAL A1 B1 A2 B2)
  1088. \OUT (DISTANCE-POSITIONAL A1 B1 A2 B2)
  1089. \OUT (DISTANCE :X1 A1 :Y1 B1 :Z1 C1 :X2 A2 :Y2 B2 :Z2 C2)
  1090. \EV NIL
  1091. \endcode
  1092. \label Affected By:\None.
  1093. \label Exceptional Situations:\None.
  1094. \label See Also::
  1095. \funref{compiler-macro-function},
  1096. \macref{defmacro},
  1097. \funref{documentation},
  1098. {\secref\DocVsDecls}
  1099. \label Notes::
  1100. The consequences of writing a \term{compiler macro} definition for a function
  1101. in \thepackage{common-lisp} are undefined; it is quite possible that in some
  1102. \term{implementations} such an attempt would override an equivalent or equally
  1103. important definition. In general, it is recommended that a programmer only
  1104. write \term{compiler macro} definitions for \term{functions} he or she personally
  1105. maintains--writing a \term{compiler macro} definition for a function maintained
  1106. elsewhere is normally considered a violation of traditional rules of modularity
  1107. and data abstraction.
  1108. \endissue{DECLS-AND-DOC}
  1109. \endcom
  1110. %%% ========== DEFMACRO
  1111. \begincom{defmacro}\ftype{Macro}
  1112. \issue{DECLS-AND-DOC}
  1113. \label Syntax::
  1114. \DefmacWithValuesNewline defmacro {name lambda-list {\DeclsAndDoc} \starparam{form}} {name}
  1115. \label Arguments and Values::
  1116. \param{name}---a \term{symbol}. %!!! maybe call it a "user symbol" ?? -kmp 2-Aug-91
  1117. %% 8.1.0 9
  1118. %% 8.1.0 10
  1119. %% 8.1.0 11
  1120. %% 8.1.0 12
  1121. \param{lambda-list}---a \term{macro lambda list}.
  1122. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  1123. \param{documentation}---a \term{string}; \noeval.
  1124. \param{form}---a \term{form}.
  1125. \label Description::
  1126. %% 8.1.0 6
  1127. Defines \param{name} as a \term{macro}
  1128. by associating a \term{macro function} with that \param{name}
  1129. in the global environment.
  1130. \issue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  1131. % Reworded garbled text. --sjl 7 Mar 92
  1132. %When the \term{macro function} is called,
  1133. %the \param{forms} are evaluated in
  1134. %the \term{lexical environment} in which the \macref{defmacro} form was evaluated.
  1135. The \term{macro function} is defined in the same \term{lexical environment}
  1136. in which the \macref{defmacro} \term{form} appears.
  1137. \endissue{DEFINING-MACROS-NON-TOP-LEVEL:ALLOW}
  1138. %% 8.1.0 7
  1139. The parameter variables in \param{lambda-list} are bound to
  1140. destructured portions of the macro call.
  1141. The expansion function
  1142. accepts two arguments, a \term{form} and an
  1143. \term{environment}. The expansion function returns a \term{form}.
  1144. The body of the expansion function is specified by \param{forms}.
  1145. \param{Forms} are executed in order. The value of the
  1146. last \param{form} executed is returned as the expansion of the
  1147. \term{macro}.
  1148. \issue{FLET-IMPLICIT-BLOCK:YES}
  1149. \issue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  1150. The body \param{forms} of the expansion function (but not the \param{lambda-list})
  1151. \endissue{DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS}
  1152. are implicitly enclosed in a \term{block} whose name is \param{name}.
  1153. \endissue{FLET-IMPLICIT-BLOCK:YES}
  1154. The \param{lambda-list} conforms to the requirements described in \secref\MacroLambdaLists.
  1155. \issue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  1156. \param{Documentation} is attached as a \term{documentation string}
  1157. to \param{name} (as kind \specref{function})
  1158. and to the \term{macro function}.
  1159. \endissue{DOCUMENTATION-FUNCTION-BUGS:FIX}
  1160. %% 8.1.0 17
  1161. \macref{defmacro} can be used to redefine a \term{macro} or to replace
  1162. a \term{function} definition with a \term{macro} definition.
  1163. %% sandra says this is redundant
  1164. %The consequences are undefined if a \term{special form} is redefined
  1165. %using \macref{defmacro}.
  1166. \issue{RECURSIVE-DEFTYPE:EXPLICITLY-VAGUE}
  1167. Recursive expansion of the \term{form} returned must terminate,
  1168. including the expansion of other \term{macros} which are \term{subforms}
  1169. of other \term{forms} returned.
  1170. %% Per Moon#13 (first public review) -kmp 5-May-93
  1171. The consequences are undefined if the result of fully macroexpanding
  1172. %a form contains any non-constant circular list structure.
  1173. a \term{form}
  1174. contains any \term{circular} \term{list structure} except in \term{literal objects}.
  1175. \endissue{RECURSIVE-DEFTYPE:EXPLICITLY-VAGUE}
  1176. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1177. % added qualification about top-level-ness --sjl 5 Mar 92
  1178. If a \macref{defmacro} \term{form} appears as a \term{top level form},
  1179. the \term{compiler} must store the \term{macro} definition at compile time,
  1180. so that occurrences of the macro later on in the file can be expanded correctly.
  1181. Users must ensure that the body of the \term{macro} can be evaluated at
  1182. compile time if it is referenced within the \term{file} being \term{compiled}.
  1183. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1184. \label Examples::
  1185. \code
  1186. (defmacro mac1 (a b) "Mac1 multiplies and adds"
  1187. `(+ ,a (* ,b 3))) \EV MAC1
  1188. (mac1 4 5) \EV 19
  1189. (documentation 'mac1 'function) \EV "Mac1 multiplies and adds"
  1190. (defmacro mac2 (&optional (a 2 b) (c 3 d) &rest x) `'(,a ,b ,c ,d ,x)) \EV MAC2
  1191. (mac2 6) \EV (6 T 3 NIL NIL)
  1192. (mac2 6 3 8) \EV (6 T 3 T (8))
  1193. (defmacro mac3 (&whole r a &optional (b 3) &rest x &key c (d a))
  1194. `'(,r ,a ,b ,c ,d ,x)) \EV MAC3
  1195. (mac3 1 6 :d 8 :c 9 :d 10) \EV ((MAC3 1 6 :D 8 :C 9 :D 10) 1 6 9 8 (:D 8 :C 9 :D 10))
  1196. \endcode
  1197. % (defmacro mac4
  1198. % (&whole (su &rest (p &rest q)) a
  1199. % &optional (b 3) &rest x &key c (d a))
  1200. % `'(,su ,p ,a ,b ,c ,d ,x)) \EV MAC4
  1201. % (mac4 1 6 :d 8 :c 9 :d 10) \EV (MAC4 1 1 6 9 8 (:D 8 :C 9 :D 10))
  1202. %An example of destructuring follows:
  1203. %
  1204. %\code
  1205. % (defmacro halibut ((mouth eye1 eye2)
  1206. % ((fin1 length1) (fin2 length2))
  1207. % tail)
  1208. % ...)
  1209. %\endcode
  1210. %Now consider this macro call:
  1211. %
  1212. %\code
  1213. % (halibut (m (car eyes) (cdr eyes))
  1214. % ((f1 (count-scales f1)) (f2 (count-scales f2)))
  1215. % my-favorite-tail) \EV NIL
  1216. %\endcode
  1217. %This would cause the expansion function to receive the
  1218. %values in \thenextfigure\ for its parameters:
  1219. %
  1220. %\boxfig
  1221. %{\dimen0=.75pc
  1222. %\tabskip \dimen0 plus .5 fil
  1223. %\halign to \hsize {#\hfil\tabskip \dimen0 plus 1fil&#\hfil\cr
  1224. %\noalign{\vskip -9pt}
  1225. %\hfil{{\sl Parameter\/}} & {{\sl Value\/}} \cr
  1226. %\noalign{\vskip 2pt\hrule\vskip 2pt}
  1227. %mouth & m \cr
  1228. %eye1 & (car eyes) \cr
  1229. %eye2 & (cdr eyes) \cr
  1230. %fin1 & f1 \cr
  1231. %length1 & (count-scales f1) \cr
  1232. %fin2 & f2 \cr
  1233. %length2 & (count-scales f2) \cr
  1234. %tail & my-favorite-tail \cr
  1235. %\noalign{\vskip -9pt}
  1236. %}}
  1237. %\caption{Destructuring example expansion function values}
  1238. %\endfig
  1239. %The following macro call would be in error because there would be no
  1240. %argument form to match the parameter \f{length1}:
  1241. %
  1242. %\code
  1243. % (halibut (m (car eyes) (cdr eyes))
  1244. % ((f1) (f2 (count-scales f2)))
  1245. % my-favorite-tail)
  1246. %\endcode
  1247. %The following macro call would be in error because a \term{symbol} appears
  1248. %in the call where the structure of the \term{lambda list} requires a
  1249. %\term{list}:
  1250. %
  1251. %\code
  1252. % (halibut my-favorite-head
  1253. % ((f1 (count-scales f1)) (f2 (count-scales f2)))
  1254. % my-favorite-tail)
  1255. %\endcode
  1256. %The fact that the value of the variable \f{my-favorite-head}
  1257. %might happen to be a \term{list} is irrelevant here. It is the macro call
  1258. %itself whose structure must match that of the \macref{defmacro}
  1259. %\term{lambda list}.
  1260. %
  1261. %%% 8.1.0 25
  1262. %The use of \term{lambda list keywords} is illustrated as follows.
  1263. %Suppose it is convenient within the expansion
  1264. %function for \f{halibut} to be able to refer to the \term{list}
  1265. %whose components are called \f{mouth}, \f{eye1}, and \f{eye2}
  1266. %as \f{head}.
  1267. %This may be written as follows:
  1268. %
  1269. %\code
  1270. % (defmacro halibut ((&whole head mouth eye1 eye2)
  1271. % ((fin1 length1) (fin2 length2))
  1272. % tail)
  1273. % ...)
  1274. %\endcode
  1275. %Now consider the same valid macro call as before:
  1276. %
  1277. %\code
  1278. % (halibut (m (car eyes) (cdr eyes))
  1279. % ((f1 (count-scales f1)) (f2 (count-scales f2)))
  1280. % my-favorite-tail) \EV NIL
  1281. %\endcode
  1282. %This would cause the expansion function to receive the same
  1283. %values for its parameters and also a value for the parameter \f{head}
  1284. %as in \thenextfigure.
  1285. %
  1286. %\boxfig
  1287. %{\dimen0=.75pc
  1288. %\tabskip \dimen0 plus .5 fil
  1289. %\halign to \hsize {#\hfil\tabskip \dimen0 plus 1fil&#\hfil\cr
  1290. %\noalign{\vskip -9pt}
  1291. %\hfil{{\sl Parameter\/}} & {{\sl Value\/}} \cr
  1292. %\noalign{\vskip 2pt\hrule\vskip 2pt}
  1293. %head & (m (car eyes) (cdr eyes)) \cr
  1294. %\noalign{\vskip -9pt}
  1295. %}}
  1296. %\caption{Lambda list keywords expansion function values example}
  1297. %\endfig
  1298. %
  1299. %%% 8.1.0 19
  1300. %The following implements a conditional \term{form} analogous to the
  1301. %\fortran\ arithmetic IF statement.
  1302. %The \term{form} should accept four argument forms: a \f{test-value},
  1303. %a \f{neg-form}, a \f{zero-form}, and a \f{pos-form}.
  1304. %One of the last three forms is chosen to be executed according
  1305. %to whether the value of the \f{test-form} is positive, negative,
  1306. %or zero.
  1307. %Using \macref{defmacro}, a definition for such a \term{form}
  1308. %might look like this:
  1309. %
  1310. %\code
  1311. % (defmacro arithmetic-if (test neg-form zero-form pos-form)
  1312. % (let ((var (gensym)))
  1313. % `(let ((,var ,test))
  1314. % (cond ((< ,var 0) ,neg-form)
  1315. % ((= ,var 0) ,zero-form)
  1316. % (t ,pos-form))))) \EV ARITHMETIC-IF
  1317. %\endcode
  1318. %Note the use of the backquote facility in this definition,
  1319. %and also the use of \funref{gensym} to generate a new variable name.
  1320. %This is necessary to avoid conflict with any variables that might
  1321. %be referred to in \f{neg-form}, \f{zero-form}, or \f{pos-form}.
  1322. %
  1323. %%% 8.1.0 20
  1324. %If the form is executed by the interpreter, it will cause the
  1325. %function definition of the symbol \f{arithmetic-if}
  1326. %to be a macro associated with which is
  1327. %a two-argument expansion function roughly equivalent to:
  1328. %
  1329. %\code
  1330. % (lambda (calling-form environment)
  1331. % (declare (ignore environment))
  1332. % (let ((var (gensym)))
  1333. % (list 'let
  1334. % (list (list 'var (cadr calling-form)))
  1335. % (list 'cond
  1336. % (list (list '< var '0) (caddr calling-form))
  1337. % (list (list '= var '0) (cadddr calling-form))
  1338. % (list 't (fifth calling-form))))))
  1339. %\endcode
  1340. % Barmar had noted that if we were going to show the above lambda, we should show
  1341. % the defmacro that might have produced it. But since we're not going to show it,
  1342. % I guess the issue is moot. -kmp 28-Dec-90
  1343. %
  1344. %%% 8.1.0 21
  1345. %The \term{lambda expression}
  1346. %could have been produced by the \macref{defmacro} macro.
  1347. %The calls to \funref{list} are the (hypothetical) result
  1348. %of the backquote (\f{\bq})
  1349. %macro character and its associated commas.
  1350. %The precise macro expansion function might depend on the implementation.
  1351. %For example, the implementation
  1352. %might provide some degree of explicit error checking on the number
  1353. %of argument forms in the macro call.
  1354. %
  1355. %%% 8.1.0 22
  1356. %
  1357. %%If \funref{eval} encounters
  1358. %%
  1359. %%\code
  1360. % (arithmetic-if (- x 4.0)
  1361. %% (- x)
  1362. %% (error "Strange zero")
  1363. %% x)
  1364. %%\endcode
  1365. %this will be expanded into something like
  1366. %
  1367. %\code
  1368. % (let ((g407 (- x 4.0)))
  1369. % (cond ((< g407 0) (- x))
  1370. % ((= g407 0) (error "Strange zero"))
  1371. % (t x)))
  1372. %\endcode
  1373. %and \funref{eval} tries again on this new form.
  1374. %
  1375. %%% 8.1.0 23
  1376. %To expand on this example
  1377. %the \f{pos-form}
  1378. %and \f{zero-form} could be omitted, allowing their values to default to \nil,
  1379. %in the same way that the \f{else} form of \specref{if}
  1380. %may be omitted:
  1381. %
  1382. %\code
  1383. % (defmacro arithmetic-if (test neg-form &optional zero-form pos-form)
  1384. % (let ((var (gensym)))
  1385. % \bq(let ((,var ,test))
  1386. % (cond ((< ,var 0) ,neg-form)
  1387. % ((= ,var 0) ,zero-form)
  1388. % (t ,pos-form)))))
  1389. %\endcode
  1390. %Then
  1391. %
  1392. %\code
  1393. % (arithmetic-if (- x 4.0) (print x))
  1394. %\endcode
  1395. %would be expanded into something like
  1396. %
  1397. %\code
  1398. % (let ((g408 (- x 4.0)))
  1399. % (cond ((< g408 0) (print x))
  1400. % ((= g408 0) nil)
  1401. % (t nil)))
  1402. %\endcode
  1403. %% 8.1.0 26
  1404. The stipulation that
  1405. an embedded \term{destructuring lambda list} is permitted only
  1406. where \term{ordinary lambda list} syntax would permit a parameter name
  1407. but not a \term{list} is made to prevent ambiguity. For example,
  1408. the following is not valid:
  1409. \code
  1410. (defmacro loser (x &optional (a b &rest c) &rest z)
  1411. ...)
  1412. \endcode
  1413. because \term{ordinary lambda list} syntax does permit a
  1414. \term{list} following \optional;
  1415. the list \f{(a b \&rest c)} would be interpreted as describing an
  1416. optional parameter named \f{a} whose default value is that of the
  1417. form \f{b}, with a supplied-p parameter named \keyref{rest} (not valid),
  1418. and an extraneous symbol \f{c} in the list (also not valid). An almost
  1419. correct way to express this is
  1420. \code
  1421. (defmacro loser (x &optional ((a b &rest c)) &rest z)
  1422. ...)
  1423. \endcode
  1424. The extra set of parentheses removes the ambiguity. However, the
  1425. definition is now incorrect because a macro call such as \f{(loser (car pool))}
  1426. would not provide any argument form for the lambda list \f{(a b \&rest c)},
  1427. and so the default value against which to match the \term{lambda list} would be
  1428. \nil\ because no explicit default value was specified.
  1429. The consequences of this are unspecified
  1430. since the empty list, \nil, does not have \term{forms} to satisfy the
  1431. parameters \f{a} and \f{b}. The fully correct definition would be either
  1432. \code
  1433. (defmacro loser (x &optional ((a b &rest c) '(nil nil)) &rest z)
  1434. ...)
  1435. \endcode
  1436. or
  1437. \code
  1438. (defmacro loser (x &optional ((&optional a b &rest c)) &rest z)
  1439. ...)
  1440. \endcode
  1441. These differ slightly: the first requires that if the macro call
  1442. specifies \f{a} explicitly then it must also specify \f{b} explicitly,
  1443. whereas the second does not have this requirement. For example,
  1444. \code
  1445. (loser (car pool) ((+ x 1)))
  1446. \endcode
  1447. would be a valid call for the second definition but not for the first.
  1448. \issue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  1449. \code
  1450. (defmacro dm1a (&whole x) `',x)
  1451. (macroexpand '(dm1a)) \EV (QUOTE (DM1A))
  1452. (macroexpand '(dm1a a)) is an error.
  1453. (defmacro dm1b (&whole x a &optional b) `'(,x ,a ,b))
  1454. (macroexpand '(dm1b)) is an error.
  1455. (macroexpand '(dm1b q)) \EV (QUOTE ((DM1B Q) Q NIL))
  1456. (macroexpand '(dm1b q r)) \EV (QUOTE ((DM1B Q R) Q R))
  1457. (macroexpand '(dm1b q r s)) is an error.
  1458. \endcode
  1459. \code
  1460. (defmacro dm2a (&whole form a b) `'(form ,form a ,a b ,b))
  1461. (macroexpand '(dm2a x y)) \EV (QUOTE (FORM (DM2A X Y) A X B Y))
  1462. (dm2a x y) \EV (FORM (DM2A X Y) A X B Y)
  1463. (defmacro dm2b (&whole form a (&whole b (c . d) &optional (e 5))
  1464. &body f &environment env)
  1465. ``(,',form ,,a ,',b ,',(macroexpand c env) ,',d ,',e ,',f))
  1466. ;Note that because backquote is involved, implementations may differ
  1467. ;slightly in the nature (though not the functionality) of the expansion.
  1468. (macroexpand '(dm2b x1 (((incf x2) x3 x4)) x5 x6))
  1469. \EV (LIST* '(DM2B X1 (((INCF X2) X3 X4))
  1470. X5 X6)
  1471. X1
  1472. '((((INCF X2) X3 X4)) (SETQ X2 (+ X2 1)) (X3 X4) 5 (X5 X6))),
  1473. T
  1474. (let ((x1 5))
  1475. (macrolet ((segundo (x) `(cadr ,x)))
  1476. (dm2b x1 (((segundo x2) x3 x4)) x5 x6)))
  1477. \EV ((DM2B X1 (((SEGUNDO X2) X3 X4)) X5 X6)
  1478. 5 (((SEGUNDO X2) X3 X4)) (CADR X2) (X3 X4) 5 (X5 X6))
  1479. \endcode
  1480. \endissue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  1481. \label Affected By:\None.
  1482. \label Exceptional Situations:\none.
  1483. % adequately covered in the packages chapter. --sjl 5 Mar 92
  1484. % \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  1485. % The consequences are undefined if \param{name}
  1486. % is a \term{symbol} in \thepackage{common-lisp}.
  1487. % \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  1488. % Barmar writes:
  1489. % "Macros must not modify any of the structure they are given."
  1490. % We outlawed displacing at some point.
  1491. % but I couldn't find anything to back up this claim. Issue MACRO-CACHING
  1492. % had this in mind, but didn't go far enough. So I've left this alone for now.
  1493. % -kmp 2-Aug-91
  1494. \label See Also::
  1495. \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  1496. \macref{define-compiler-macro},
  1497. \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  1498. \macref{destructuring-bind},
  1499. \funref{documentation},
  1500. \funref{macroexpand},
  1501. \varref{*macroexpand-hook*},
  1502. \specref{macrolet},
  1503. \funref{macro-function},
  1504. {\secref\Evaluation},
  1505. {\secref\Compilation},
  1506. {\secref\DocVsDecls}
  1507. \label Notes:\None.
  1508. \endissue{DECLS-AND-DOC}
  1509. \endcom
  1510. %%% ========== MACRO-FUNCTION
  1511. \begincom{macro-function}\ftype{Accessor}
  1512. \label Syntax::
  1513. \DefunWithValues macro-function {symbol {\opt} environment} {function}
  1514. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1515. % % If it's an error to supply the environment argument here, the syntax
  1516. % % shouldn't show it. Compare w/COMPILER-MACRO-FUNCTION. --sjl 5 Mar 92
  1517. % % \Defsetf macro-function {symbol {\opt} environment} {new-function}
  1518. % \Defsetf macro-function {symbol} {new-function}
  1519. %% Reinstated per X3J13.
  1520. \Defsetf macro-function {symbol {\opt} environment} {new-function}
  1521. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1522. \label Arguments and Values::
  1523. \param{symbol}---a \term{symbol}.
  1524. \issue{MACRO-FUNCTION-ENVIRONMENT}
  1525. \param{environment}---an \term{environment} \term{object}.
  1526. \endissue{MACRO-FUNCTION-ENVIRONMENT}
  1527. \param{function}---a \term{macro function} or \nil.
  1528. \param{new-function}---a \term{macro function}.
  1529. \label Description::
  1530. %% 8.1.0 2
  1531. Determines whether \param{symbol} has a function definition
  1532. as a macro in the specified \param{environment}.
  1533. If so, the macro expansion function, a function of two arguments,
  1534. is returned. If \param{symbol} has no function definition
  1535. in the lexical environment \param{environment}, or its definition
  1536. is not a \term{macro}, \funref{macro-function} returns \nil.
  1537. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1538. \issue{MACRO-FUNCTION-ENVIRONMENT}
  1539. % The consequences are undefined if \param{environment} is supplied
  1540. % in a use of \funref{macro-function} as a \macref{setf} location specifier.
  1541. \endissue{MACRO-FUNCTION-ENVIRONMENT}
  1542. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1543. %This doesn't belong here. -kmp 09-Apr-91
  1544. % \issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  1545. % The \term{environment} \term{object} has
  1546. % \term{dynamic extent}; the consequences are undefined if
  1547. % the \keyref{environment} argument is
  1548. % referred to outside the \term{dynamic extent}
  1549. % of the macro expansion function.
  1550. % \endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  1551. \issue{MACRO-FUNCTION-ENVIRONMENT}
  1552. % The following will be deleted:
  1553. %
  1554. % %% 8.1.0 4
  1555. % \funref{macro-function}
  1556. % cannot be used to determine whether \param{symbol} names
  1557. % a locally defined macro established by \specref{macrolet};
  1558. % %% or \specref{symbol-macrolet}
  1559. % \funref{macro-function} can
  1560. % examine only global definitions.
  1561. \endissue{MACRO-FUNCTION-ENVIRONMENT}
  1562. %% 8.1.0 3
  1563. It is possible for both \funref{macro-function} and
  1564. \issue{SPECIAL-FORM-P-MISNOMER:RENAME}
  1565. \funref{special-operator-p}
  1566. \endissue{SPECIAL-FORM-P-MISNOMER:RENAME}
  1567. to return \term{true} of \param{symbol}. The \term{macro} definition must
  1568. be available for use by programs that understand only the standard
  1569. \clisp\ \term{special forms}.
  1570. \label Examples::
  1571. \code
  1572. (defmacro macfun (x) '(macro-function 'macfun)) \EV MACFUN
  1573. (not (macro-function 'macfun)) \EV \term{false}
  1574. \endcode
  1575. %;;--- The next four lines are not valid Common Lisp, as equal
  1576. %;;--- is not defined for functions --Moon
  1577. % (and (setf (macro-function 'macfun) #'equal)
  1578. % (equal (macro-function 'macfun) #'equal)) \EV \term{true}
  1579. % (macrolet ((macfun (x) "local"))
  1580. % (equal (macro-function 'macfun) #'equal)) \EV \term{true}
  1581. \issue{MACRO-FUNCTION-ENVIRONMENT}
  1582. \code
  1583. (macrolet ((foo (&environment env)
  1584. (if (macro-function 'bar env)
  1585. ''yes
  1586. ''no)))
  1587. (list (foo)
  1588. (macrolet ((bar () :beep))
  1589. (foo))))
  1590. \EV (NO YES)
  1591. \endcode
  1592. \endissue{MACRO-FUNCTION-ENVIRONMENT}
  1593. \label Affected By::
  1594. \f{(setf macro-function)}, \macref{defmacro}, and \specref{macrolet}.
  1595. \label Exceptional Situations::
  1596. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1597. The consequences are undefined if \param{environment} is \term{non-nil}
  1598. in a use of \SETFof{macro-function}.
  1599. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  1600. \label See Also::
  1601. \macref{defmacro}, {\secref\Evaluation}
  1602. \label Notes::
  1603. %% 8.1.0 5
  1604. \macref{setf} can be used with \funref{macro-function} to install
  1605. a \term{macro} as a symbol's global function definition:
  1606. \code
  1607. (setf (macro-function symbol) fn)
  1608. \endcode
  1609. The value installed must be a \term{function} that accepts two arguments,
  1610. the entire macro call and an \term{environment},
  1611. and computes the expansion for that call.
  1612. Performing this operation causes \param{symbol} to have only that
  1613. macro definition as its global function definition; any previous
  1614. definition, whether as a \term{macro} or as a
  1615. \term{function}, is lost.
  1616. \endcom
  1617. %%% ========== MACROEXPAND
  1618. %%% ========== MACROEXPAND-1
  1619. \begincom{macroexpand, macroexpand-1}\ftype{Function}
  1620. \label Syntax::
  1621. \DefunWithValues macroexpand {form {\opt} env} {expansion, expanded-p}
  1622. \DefunWithValues macroexpand-1 {form {\opt} env} {expansion, expanded-p}
  1623. \label Arguments and Values::
  1624. \param{form}---a \term{form}.
  1625. \param{env}---an \term{environment} \term{object}.
  1626. \Default{\nil}
  1627. \param{expansion}---a \term{form}.
  1628. \issue{MACROEXPAND-RETURN-VALUE:TRUE}
  1629. \param{expanded-p}---a \term{generalized boolean}.
  1630. \endissue{MACROEXPAND-RETURN-VALUE:TRUE}
  1631. \label Description::
  1632. \funref{macroexpand} and \funref{macroexpand-1} expand \term{macros}.
  1633. %% 8.2.0 2
  1634. %% 8.2.0 3
  1635. If \param{form} is a \term{macro form},
  1636. then \funref{macroexpand-1} expands the \term{macro form} call once.
  1637. %% 8.2.0 7
  1638. \funref{macroexpand}
  1639. repeatedly expands \param{form} until it is no longer a \term{macro form}.
  1640. In effect, \funref{macroexpand} calls \funref{macroexpand-1} repeatedly
  1641. until the \term{secondary value} it returns is \nil.
  1642. %% 8.2.0 2
  1643. If \param{form} is a \term{macro form},
  1644. then the \param{expansion} is a \term{macro expansion}
  1645. and \param{expanded-p} is \term{true}.
  1646. Otherwise,
  1647. the \param{expansion} is the given \param{form}
  1648. and \param{expanded-p} is \term{false}.
  1649. %% 8.2.0 4
  1650. Macro expansion is carried out as follows.
  1651. Once \funref{macroexpand-1} has
  1652. determined that the \param{form} is a \term{macro form},
  1653. it obtains an appropriate expansion \term{function} for the
  1654. \term{macro} or \term{symbol macro}.
  1655. The value of
  1656. \varref{*macroexpand-hook*} is
  1657. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  1658. coerced to a \term{function} and
  1659. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  1660. then called as a \term{function} of three arguments:
  1661. the expansion \term{function},
  1662. the \param{form},
  1663. and the \param{env}.
  1664. The \term{value} returned from this call is taken to be the expansion
  1665. of the \param{form}.
  1666. %% Augmented this first sentence to mention global environment
  1667. %% and local symbol-macrolet definitions. -kmp 12-May-93
  1668. In addition to \term{macro} definitions in the global environment,
  1669. any local macro definitions established within \param{env} by \specref{macrolet}
  1670. or \specref{symbol-macrolet} are considered.
  1671. If only \param{form} is supplied as an argument,
  1672. then the environment is effectively null, and only global macro definitions
  1673. as established by \macref{defmacro} are considered.
  1674. %% Sandra addition
  1675. \term{Macro} definitions are shadowed by local \term{function} definitions.
  1676. %% end Sandra addition
  1677. \label Examples::
  1678. \code
  1679. (defmacro alpha (x y) `(beta ,x ,y)) \EV ALPHA
  1680. (defmacro beta (x y) `(gamma ,x ,y)) \EV BETA
  1681. (defmacro delta (x y) `(gamma ,x ,y)) \EV EPSILON
  1682. (defmacro expand (form &environment env)
  1683. (multiple-value-bind (expansion expanded-p)
  1684. (macroexpand form env)
  1685. `(values ',expansion ',expanded-p))) \EV EXPAND
  1686. (defmacro expand-1 (form &environment env)
  1687. (multiple-value-bind (expansion expanded-p)
  1688. (macroexpand-1 form env)
  1689. `(values ',expansion ',expanded-p))) \EV EXPAND-1
  1690. \medbreak
  1691. ;; Simple examples involving just the global environment
  1692. (macroexpand-1 '(alpha a b)) \EV (BETA A B), \term{true}
  1693. (expand-1 (alpha a b)) \EV (BETA A B), \term{true}
  1694. (macroexpand '(alpha a b)) \EV (GAMMA A B), \term{true}
  1695. (expand (alpha a b)) \EV (GAMMA A B), \term{true}
  1696. (macroexpand-1 'not-a-macro) \EV NOT-A-MACRO, \term{false}
  1697. (expand-1 not-a-macro) \EV NOT-A-MACRO, \term{false}
  1698. (macroexpand '(not-a-macro a b)) \EV (NOT-A-MACRO A B), \term{false}
  1699. (expand (not-a-macro a b)) \EV (NOT-A-MACRO A B), \term{false}
  1700. \medbreak
  1701. ;; Examples involving lexical environments
  1702. (macrolet ((alpha (x y) `(delta ,x ,y)))
  1703. (macroexpand-1 '(alpha a b))) \EV (BETA A B), \term{true}
  1704. (macrolet ((alpha (x y) `(delta ,x ,y)))
  1705. (expand-1 (alpha a b))) \EV (DELTA A B), \term{true}
  1706. (macrolet ((alpha (x y) `(delta ,x ,y)))
  1707. (macroexpand '(alpha a b))) \EV (GAMMA A B), \term{true}
  1708. (macrolet ((alpha (x y) `(delta ,x ,y)))
  1709. (expand (alpha a b))) \EV (GAMMA A B), \term{true}
  1710. (macrolet ((beta (x y) `(epsilon ,x ,y)))
  1711. (expand (alpha a b))) \EV (EPSILON A B), \term{true}
  1712. (let ((x (list 1 2 3)))
  1713. (symbol-macrolet ((a (first x)))
  1714. (expand a))) \EV (FIRST X), \term{true}
  1715. (let ((x (list 1 2 3)))
  1716. (symbol-macrolet ((a (first x)))
  1717. (macroexpand 'a))) \EV A, \term{false}
  1718. (symbol-macrolet ((b (alpha x y)))
  1719. (expand-1 b)) \EV (ALPHA X Y), \term{true}
  1720. (symbol-macrolet ((b (alpha x y)))
  1721. (expand b)) \EV (GAMMA X Y), \term{true}
  1722. (symbol-macrolet ((b (alpha x y))
  1723. (a b))
  1724. (expand-1 a)) \EV B, \term{true}
  1725. (symbol-macrolet ((b (alpha x y))
  1726. (a b))
  1727. (expand a)) \EV (GAMMA X Y), \term{true}
  1728. \medbreak
  1729. ;; Examples of shadowing behavior
  1730. (flet ((beta (x y) (+ x y)))
  1731. (expand (alpha a b))) \EV (BETA A B), \term{true}
  1732. (macrolet ((alpha (x y) `(delta ,x ,y)))
  1733. (flet ((alpha (x y) (+ x y)))
  1734. (expand (alpha a b)))) \EV (ALPHA A B), \term{false}
  1735. (let ((x (list 1 2 3)))
  1736. (symbol-macrolet ((a (first x)))
  1737. (let ((a x))
  1738. (expand a)))) \EV A, \term{false}
  1739. \endcode
  1740. \label Affected By::
  1741. \macref{defmacro},
  1742. \macref{setf} of \macref{macro-function},
  1743. \specref{macrolet},
  1744. \specref{symbol-macrolet}
  1745. \label Exceptional Situations:\None.
  1746. \label See Also::
  1747. \varref{*macroexpand-hook*},
  1748. \macref{defmacro},
  1749. \macref{setf} of \macref{macro-function},
  1750. \specref{macrolet},
  1751. \specref{symbol-macrolet},
  1752. {\secref\Evaluation}
  1753. \label Notes::
  1754. Neither \funref{macroexpand} nor \funref{macroexpand-1}
  1755. makes any explicit attempt to expand \term{macro forms} that are
  1756. either \term{subforms} of the \param{form}
  1757. or \term{subforms} of the \param{expansion}.
  1758. Such expansion might occur implicitly, however,
  1759. due to the semantics or implementation of the \term{macro function}.
  1760. \endcom
  1761. \issue{ISO-COMPATIBILITY:ADD-SUBSTRATE}
  1762. %%% ========== DEFINE-SYMBOL-MACRO
  1763. \begincom{define-symbol-macro}\ftype{Macro}
  1764. \label Syntax::
  1765. \DefmacWithValuesNewline define-symbol-macro {symbol expansion} {symbol}
  1766. \label Arguments and Values::
  1767. \param{symbol}---a \term{symbol}.
  1768. \param{expansion}---a \term{form}.
  1769. \label Description::
  1770. Provides a mechanism for globally affecting the \term{macro expansion}
  1771. of the indicated \param{symbol}.
  1772. Globally establishes an expansion function for the \term{symbol macro}
  1773. named by \param{symbol}.
  1774. %% Patterned after wording from SYMBOL-MACROLET (per issue SYMBOL-MACROLET-SEMANTICS).
  1775. The only guaranteed property of an expansion \term{function} for a \term{symbol macro}
  1776. is that when it is applied to the \term{form} and the \term{environment} it returns
  1777. the correct expansion. (In particular, it is \term{implementation-dependent}
  1778. whether the expansion is conceptually stored in the expansion function,
  1779. the \term{environment}, or both.)
  1780. Each global reference to \param{symbol} (\ie not \term{shadowed}\meaning{2} by a
  1781. \term{binding} for a \term{variable} or \term{symbol macro} named by
  1782. the same \term{symbol}) is expanded by the normal macro expansion process;
  1783. \seesection\SymbolsAsForms.
  1784. The expansion of a \term{symbol macro} is subject to further \term{macro expansion}
  1785. in the same \term{lexical environment} as the \term{symbol macro} reference,
  1786. exactly analogous to normal \term{macros}.
  1787. %% Patterned after wording from SYMBOL-MACROLET (per issue SYMBOL-MACROLET-DECLARE).
  1788. The consequences are unspecified if a \declref{special} declaration is made for
  1789. \param{symbol} while in the scope of this definition (\ie when it is not
  1790. \term{shadowed}\meaning{2} by a \term{binding} for a \term{variable}
  1791. or \term{symbol macro} named by the same \term{symbol}).
  1792. Any use of \specref{setq} to set the value of
  1793. %% Per X3J13. -kmp 5-Oct-93
  1794. %one of
  1795. the \param{symbol}
  1796. while in the scope of this definition
  1797. is treated as if it were a \macref{setf}.
  1798. \macref{psetq} of \param{symbol}
  1799. is treated as if it were a \macref{psetf}, and
  1800. \macref{multiple-value-setq}
  1801. is treated as if it were a \specref{setf} of \funref{values}.
  1802. A \term{binding} for a \term{symbol macro} can be \term{shadowed}\meaning{2}
  1803. by \specref{let} or \specref{symbol-macrolet}.
  1804. \label Examples::
  1805. \code
  1806. (defvar *things* (list 'alpha 'beta 'gamma)) \EV *THINGS*
  1807. (define-symbol-macro thing1 (first *things*)) \EV THING1
  1808. (define-symbol-macro thing2 (second *things*)) \EV THING2
  1809. (define-symbol-macro thing3 (third *things*)) \EV THING3
  1810. thing1 \EV ALPHA
  1811. (setq thing1 'ONE) \EV ONE
  1812. *things* \EV (ONE BETA GAMMA)
  1813. (multiple-value-setq (thing2 thing3) (values 'two 'three)) \EV TWO
  1814. thing3 \EV THREE
  1815. *things* \EV (ONE TWO THREE)
  1816. (list thing2 (let ((thing2 2)) thing2)) \EV (TWO 2)
  1817. \endcode
  1818. \label Affected By:\None.
  1819. \label Exceptional Situations::
  1820. %% See issues LISP-SYMBOL-REDEFINITION and SYMBOL-MACROS-AND-PROCLAIMED-SPECIALS.
  1821. If \param{symbol} is already defined as a \term{global variable},
  1822. an error \oftype{program-error} is signaled.
  1823. \label See Also::
  1824. \specref{symbol-macrolet},
  1825. \funref{macroexpand}
  1826. \label Notes:\None.
  1827. \endcom%{define-symbol-macro}
  1828. \endissue{ISO-COMPATIBILITY:ADD-SUBSTRATE}
  1829. %%% ========== SYMBOL-MACROLET
  1830. \begincom{symbol-macrolet}\ftype{Special Operator}
  1831. \issue{DECLS-AND-DOC}
  1832. \issue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1833. \label Syntax::
  1834. \DefspecWithValuesNewline symbol-macrolet
  1835. {\paren{\starparen{symbol expansion}}
  1836. \starparam{declaration}
  1837. \starparam{form}}
  1838. {\starparam{result}}
  1839. \label Arguments and Values::
  1840. \param{symbol}---a \term{symbol}.
  1841. \param{expansion}---a \term{form}.
  1842. \issue{SYMBOL-MACROLET-DECLARE:ALLOW}
  1843. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  1844. \endissue{SYMBOL-MACROLET-DECLARE:ALLOW}
  1845. \param{forms}---an \term{implicit progn}.
  1846. \param{results}---the \term{values} returned by the \param{forms}.
  1847. \label Description::
  1848. %A number of changes in here due to Moore #1 (first public review).
  1849. \specref{symbol-macrolet} provides a mechanism for
  1850. affecting the \term{macro expansion} environment for \term{symbols}.
  1851. \specref{symbol-macrolet} lexically establishes expansion functions
  1852. for each of the \term{symbol macros} named by \param{symbols}.
  1853. \issue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1854. The only guaranteed property of an expansion \term{function} for a \term{symbol macro}
  1855. is that when it is applied to the \term{form} and the \term{environment} it returns
  1856. the correct expansion. (In particular, it is \term{implementation-dependent}
  1857. whether the expansion is conceptually stored in the expansion function,
  1858. the \term{environment}, or both.)
  1859. \endissue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1860. Each reference to \param{symbol} as a variable within the lexical \term{scope}
  1861. of \specref{symbol-macrolet} is expanded by the normal macro expansion process;
  1862. \seesection\SymbolsAsForms.
  1863. The expansion of a symbol macro is subject to further macro expansion
  1864. in the same lexical environment as the symbol macro invocation, exactly
  1865. analogous to normal \term{macros}.
  1866. \issue{SYMBOL-MACROLET-DECLARE:ALLOW}
  1867. Exactly the same \param{declarations} are allowed as for \specref{let}
  1868. with one exception: \specref{symbol-macrolet} signals an error
  1869. if a \declref{special} declaration names one of the \term{symbols}
  1870. being defined by \specref{symbol-macrolet}.
  1871. % Discussion of declarations moved to TYPE dictionary entry. --sjl 5 Mar 92
  1872. \endissue{SYMBOL-MACROLET-DECLARE:ALLOW}
  1873. When the \param{forms} of the \specref{symbol-macrolet} form are expanded,
  1874. any use of \specref{setq} to set the value of one of the specified variables
  1875. is treated as if it were a \macref{setf}.
  1876. \macref{psetq} of a \term{symbol} defined as a symbol macro
  1877. is treated as if it were a \macref{psetf}, and
  1878. \macref{multiple-value-setq}
  1879. is treated as if it were a \specref{setf} of \funref{values}.
  1880. The use of \specref{symbol-macrolet} can be shadowed by \specref{let}.
  1881. In other words, \specref{symbol-macrolet} only substitutes for occurrences
  1882. of \param{symbol} that would be in the \term{scope} of a lexical binding of
  1883. \param{symbol} surrounding the \param{forms}.
  1884. \label Examples::
  1885. \code
  1886. ;;; The following is equivalent to
  1887. ;;; (list 'foo (let ((x 'bar)) x)),
  1888. ;;; not
  1889. ;;; (list 'foo (let (('foo 'bar)) 'foo))
  1890. (symbol-macrolet ((x 'foo))
  1891. (list x (let ((x 'bar)) x)))
  1892. \EV (foo bar)
  1893. \NV (foo foo)
  1894. (symbol-macrolet ((x '(foo x)))
  1895. (list x))
  1896. \EV ((FOO X))
  1897. \endcode
  1898. \label Affected By:\None.
  1899. \label Exceptional Situations::
  1900. \issue{SYMBOL-MACROS-AND-PROCLAIMED-SPECIALS:SIGNALS-AN-ERROR}
  1901. \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  1902. If an attempt is made to bind a \term{symbol} that is defined as a \term{global variable},
  1903. an error \oftype{program-error} is signaled.
  1904. \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  1905. \endissue{SYMBOL-MACROS-AND-PROCLAIMED-SPECIALS:SIGNALS-AN-ERROR}
  1906. If \param{declaration} contains a \declref{special} declaration
  1907. that names one of the \term{symbols} being bound by \specref{symbol-macrolet},
  1908. an error \oftype{program-error} is signaled.
  1909. \label See Also::
  1910. \macref{with-slots}, \funref{macroexpand}
  1911. \label Notes::
  1912. The special form \specref{symbol-macrolet} is the basic mechanism that is used to
  1913. implement \macref{with-slots}.
  1914. If a \specref{symbol-macrolet} \term{form} is a \term{top level form},
  1915. the \param{forms} are also processed as \term{top level forms}.
  1916. \Seesection\FileCompilation.
  1917. \endissue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  1918. \endissue{DECLS-AND-DOC}
  1919. \endcom
  1920. %%% ========== *MACROEXPAND-HOOK*
  1921. \begincom{*macroexpand-hook*}\ftype{Variable}
  1922. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  1923. \label Value Type::
  1924. a \term{designator} for a \term{function} of three \term{arguments}:
  1925. a \term{macro function},
  1926. a \term{macro form},
  1927. and an \term{environment} \term{object}.
  1928. \label Initial Value::
  1929. \issue{MACROEXPAND-HOOK-DEFAULT:EXPLICITLY-VAGUE}
  1930. \issue{MACROEXPAND-HOOK-INITIAL-VALUE:IMPLEMENTATION-DEPENDENT}
  1931. a \term{designator} for a function that is equivalent to \thefunction{funcall},
  1932. but that might have additional \term{implementation-dependent} side-effects.
  1933. \endissue{MACROEXPAND-HOOK-INITIAL-VALUE:IMPLEMENTATION-DEPENDENT}
  1934. \endissue{MACROEXPAND-HOOK-DEFAULT:EXPLICITLY-VAGUE}
  1935. \label Description::
  1936. %% 8.2.0 7
  1937. Used as the expansion interface hook by \funref{macroexpand-1} to
  1938. control the \term{macro expansion} process.
  1939. When a \term{macro form} is to be expanded,
  1940. this \term{function} is called with three arguments:
  1941. the \term{macro function},
  1942. the \term{macro form},
  1943. and the \term{environment} in which the \term{macro form} is to be expanded.
  1944. \issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  1945. The \term{environment} \term{object} has \term{dynamic extent};
  1946. the consequences are undefined if the \term{environment} \term{object} is
  1947. referred to outside the \term{dynamic extent} of the macro expansion function.
  1948. \endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  1949. \label Examples::
  1950. \code
  1951. (defun hook (expander form env)
  1952. (format t "Now expanding: ~S~%" form)
  1953. (funcall expander form env)) \EV HOOK
  1954. (defmacro machook (x y) `(/ (+ ,x ,y) 2)) \EV MACHOOK
  1955. (macroexpand '(machook 1 2)) \EV (/ (+ 1 2) 2), \term{true}
  1956. (let ((*macroexpand-hook* #'hook)) (macroexpand '(machook 1 2)))
  1957. \OUT Now expanding (MACHOOK 1 2)
  1958. \EV (/ (+ 1 2) 2), \term{true}
  1959. \endcode
  1960. \label Affected By:\None.
  1961. \label See Also::
  1962. \funref{macroexpand}, \funref{macroexpand-1}, \funref{funcall}, {\secref\Evaluation}
  1963. \label Notes::
  1964. The net effect of the chosen initial value is to just invoke the
  1965. \term{macro function}, giving it the \term{macro form} and
  1966. \term{environment} as its two arguments.
  1967. Users or user programs can \term{assign} this \term{variable} to
  1968. customize or trace the \term{macro expansion} mechanism. Note, however,
  1969. that this \term{variable} is a global resource, potentially shared by
  1970. multiple \term{programs}; as such, if any two \term{programs} depend for
  1971. their correctness on the setting of this \term{variable}, those
  1972. \term{programs} may not be able to run in the same \term{Lisp image}.
  1973. For this reason, it is frequently best to confine its uses to debugging
  1974. situations.
  1975. \issue{MACROEXPAND-HOOK-INITIAL-VALUE:IMPLEMENTATION-DEPENDENT}
  1976. Users who put their own function into \varref{*macroexpand-hook*}
  1977. should consider saving the previous value of the hook, and calling that
  1978. value from their own.
  1979. \endissue{MACROEXPAND-HOOK-INITIAL-VALUE:IMPLEMENTATION-DEPENDENT}
  1980. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  1981. \endcom
  1982. %-------------------- Declarations --------------------
  1983. %%% ========== PROCLAIM
  1984. \begincom{proclaim}\ftype{Function}
  1985. \label Syntax::
  1986. \DefunWithValues proclaim {declaration-specifier} {\term{implementation-dependent}}
  1987. \label Arguments and Values::
  1988. \param{declaration-specifier}---a \term{declaration specifier}.
  1989. \label Description::
  1990. %% 9.1.0 11
  1991. \term{Establishes} the \term{declaration} specified by \param{declaration-specifier}
  1992. in the \term{global environment}.
  1993. %% 9.1.0 13
  1994. Such a \term{declaration}, sometimes called a \term{global declaration}
  1995. or a \term{proclamation}, is always in force unless locally \term{shadowed}.
  1996. %% 9.1.0 12
  1997. \term{Names} of \term{variables} and \term{functions} within
  1998. \param{declaration-specifier} refer to \term{dynamic variables}
  1999. and global \term{function} definitions, respectively.
  2000. \Thenextfigure\ shows a list of \param{declaration identifiers}
  2001. that can be used with \funref{proclaim}.
  2002. % IGNORE, IGNORABLE, and DYNAMIC-EXTENT removed as consequence of vote
  2003. % taken at 5-Oct-93 X3J13 meeting.
  2004. \issue{DYNAMIC-EXTENT:NEW-DECLARATION}
  2005. \issue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2006. \displayfour{Global Declaration Specifiers}{
  2007. declaration&inline&optimize&type\cr
  2008. ftype&notinline&special&\cr
  2009. }
  2010. %function removed.
  2011. \endissue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2012. \endissue{DYNAMIC-EXTENT:NEW-DECLARATION}
  2013. %% 9.2.0 20
  2014. An implementation is free to support other (\term{implementation-defined})
  2015. \term{declaration identifiers} as well.
  2016. \label Examples::
  2017. \code
  2018. (defun declare-variable-types-globally (type vars)
  2019. (proclaim `(type ,type ,@vars))
  2020. type)
  2021. ;; Once this form is executed, the dynamic variable *TOLERANCE*
  2022. ;; must always contain a float.
  2023. (declare-variable-types-globally 'float '(*tolerance*))
  2024. \EV FLOAT
  2025. \endcode
  2026. \label Affected By:\None.
  2027. \label Exceptional Situations:\None.
  2028. \label See Also::
  2029. \specref{declaim},
  2030. \misc{declare},
  2031. {\secref\Compilation}
  2032. \label Notes::
  2033. Although the \term{execution} of a \funref{proclaim} \term{form}
  2034. has effects that might affect compilation, the compiler does not make
  2035. any attempt to recognize and specially process \funref{proclaim} \term{forms}.
  2036. A \term{proclamation} such as the following, even if a \term{top level form},
  2037. does not have any effect until it is executed:
  2038. \code
  2039. (proclaim '(special *x*))
  2040. \endcode
  2041. If compile time side effects are desired, \specref{eval-when} may be useful.
  2042. For example:
  2043. \code
  2044. (eval-when (:execute :compile-toplevel :load-toplevel)
  2045. (proclaim '(special *x*)))
  2046. \endcode
  2047. In most such cases, however, it is preferrable to use \macref{declaim} for
  2048. this purpose.
  2049. \issue{DECLARE-MACROS:FLUSH}
  2050. Since \funref{proclaim} \term{forms} are ordinary \term{function forms},
  2051. \term{macro forms} can expand into them.
  2052. %Barrett: So what?
  2053. %Sandra: DUMB!
  2054. %KMP: Tough. I think this is a commonly asked question, and perfectly
  2055. % appropriate for a Note even though it's not a revelation. Technically,
  2056. % anything in the Notes should be describable as "so what?" or "dumb"
  2057. % or we should ask why it's in the Notes and not the Description.
  2058. \endissue{DECLARE-MACROS:FLUSH}
  2059. \endcom
  2060. %%% ========== DECLAIM
  2061. \begincom{declaim}\ftype{Macro}
  2062. \issue{PROCLAIM-ETC-IN-COMPILE-FILE:NEW-MACRO}
  2063. \label Syntax::
  2064. \DefmacWithValues declaim
  2065. {\starparam{declaration-specifier}}
  2066. {\term{implementation-dependent}}
  2067. \label Arguments and Values::
  2068. \param{declaration-specifier}---a \term{declaration specifier}; \noeval.
  2069. \label Description::
  2070. Establishes the \term{declarations} specified by the \param{declaration-specifiers}.
  2071. If a use of this macro appears as a \term{top level form} in a \term{file}
  2072. being processed by the \term{file compiler}, the proclamations are also made
  2073. at compile-time. As with other defining macros, it is unspecified whether or
  2074. not the compile-time side-effects of a \macref{declaim} persist after the
  2075. \term{file} has been \term{compiled}.
  2076. \label Examples::
  2077. \label Side Effects:\None.
  2078. \label Affected By:\None.
  2079. \label Exceptional Situations:\None.
  2080. \label See Also::
  2081. \misc{declare},
  2082. \funref{proclaim}
  2083. \label Notes:\None.
  2084. %!!! How does proclaim relate to declaim.
  2085. % Not quite as simple as
  2086. % (declaim <x>) == (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '<x>))
  2087. % but close...
  2088. % Clarify that calls to PROCLAIM should be treated the same as any
  2089. % other function call. Users should wrap an explicit EVAL-WHEN around
  2090. % top-level calls to PROCLAIM if they want them to affect compilation,
  2091. % or use the macro DECLAIM.
  2092. \endissue{PROCLAIM-ETC-IN-COMPILE-FILE:NEW-MACRO}
  2093. \endcom
  2094. %%% ========== DECLARE
  2095. \begincom{declare}\ftype{Symbol}
  2096. %!!! Barmar: This entry needs A LOT of work. It is highly redundant and perhaps inconsistent.
  2097. \label Syntax::
  2098. \Defspec declare {\starparam{declaration-specifier}}
  2099. \label Arguments::
  2100. %% 9.1.0 6
  2101. \param{declaration-specifier}---a \term{declaration specifier}; \noeval.
  2102. \label Description::
  2103. %% 9.1.0 2
  2104. A \misc{declare} \term{expression}, sometimes called a \term{declaration},
  2105. can occur only at the beginning of the bodies of certain \term{forms};
  2106. that is, it may be preceded only by other \misc{declare} \term{expressions},
  2107. or by a \term{documentation string} if the context permits.
  2108. A \misc{declare} \term{expression} can occur in a \term{lambda expression}
  2109. or in any of the \term{forms} listed in \thenextfigure.
  2110. \issue{DECLS-AND-DOC}
  2111. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  2112. \issue{SYMBOL-MACROLET-DECLARE:ALLOW}
  2113. \issue{WITH-ADDED-METHODS:DELETE}
  2114. \issue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  2115. \displaythree{Standardized Forms In Which Declarations Can Occur}{
  2116. defgeneric&do-external-symbols&prog\cr
  2117. define-compiler-macro&do-symbols&prog*\cr
  2118. define-method-combination&dolist&restart-case\cr
  2119. define-setf-expander&dotimes&symbol-macrolet\cr
  2120. defmacro&flet&with-accessors\cr
  2121. defmethod&handler-case&with-hash-table-iterator\cr
  2122. defsetf&labels&with-input-from-string\cr
  2123. deftype&let&with-open-file\cr
  2124. defun&let*&with-open-stream\cr
  2125. destructuring-bind&locally&with-output-to-string\cr
  2126. do&macrolet&with-package-iterator\cr
  2127. do*&multiple-value-bind&with-slots\cr
  2128. do-all-symbols&pprint-logical-block&\cr
  2129. }
  2130. %Deleted GENERIC-FLET, GENERIC-LABELS, GENERIC-FUNCTION -kmp 7-Feb-92
  2131. %Deleted WITH-ADDED-METHODS. -kmp 7-Jan-91
  2132. %Added DEFINE-COMPILER-MACRO, DESTRUCTURING-BIND, HANDLER-CASE,
  2133. % PPRINT-LOGICAL-BLOCK, RESTART-CASE, WITH-HASH-TABLE-ITERATOR,
  2134. % and WITH-PACKAGE-ITERATOR. -kmp 15-Feb-92
  2135. \endissue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  2136. \endissue{WITH-ADDED-METHODS:DELETE}
  2137. \endissue{SYMBOL-MACROLET-DECLARE:ALLOW}
  2138. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  2139. \endissue{DECLS-AND-DOC}
  2140. A \misc{declare} \term{expression} can only occur
  2141. where specified by the syntax of these \term{forms}.
  2142. %% 9.1.0 3
  2143. The consequences of attempting to evaluate a \misc{declare} \term{expression}
  2144. are undefined. In situations where such \term{expressions} can appear,
  2145. explicit checks are made for their presence and they are never actually evaluated;
  2146. it is for this reason that they
  2147. are called ``\misc{declare} \term{expressions}''
  2148. rather than ``\misc{declare} \term{forms}.''
  2149. % This doesn't belong here. I think it is adequately covered by the
  2150. % discussion of lambda lists and scoping of lambda variables. --sjl 5 mar 92
  2151. % When evaluating a \term{lambda form},
  2152. % none of the \term{bound declarations} made by \misc{declare} \term{expressions}
  2153. % appearing at the beginning of the body
  2154. % of the \term{lambda expression} apply to the \term{argument} \term{evaluations}.
  2155. % However, such \term{declarations} apply to the \term{initialization form} code (if any)
  2156. % for \keyref{optional}, \keyref{key}, and \keyref{aux} \term{bindings}
  2157. % % Added to please KMP (and hopefully Moon, too).
  2158. % subsequent to the \term{name} to which the \term{bound declaration} refers;
  2159. % \seesection\DeclScope.
  2160. \issue{DECLARE-MACROS:FLUSH}
  2161. %\term{macro}
  2162. %calls may expand into declarations as long as this syntax is observed.
  2163. \term{Macro forms} cannot expand into declarations;
  2164. \misc{declare} \term{expressions} must appear as actual \term{subexpressions} of
  2165. the \term{form} to which they refer.
  2166. % the only valid declarations are \term{lists} whose \term{car} is the symbol \misc{declare}.
  2167. %% Removed because this is already said in PROCLAIM.
  2168. % \term{Macro forms} can expand into \funref{proclaim} forms, however.
  2169. \endissue{DECLARE-MACROS:FLUSH}
  2170. \Thenextfigure\ shows a list of \term{declaration identifiers}
  2171. that can be used with \misc{declare}.
  2172. \issue{DYNAMIC-EXTENT:NEW-DECLARATION}
  2173. \issue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2174. \displaythree{Local Declaration Specifiers}{
  2175. dynamic-extent&ignore&optimize\cr
  2176. ftype&inline&special\cr
  2177. ignorable&notinline&type\cr
  2178. }
  2179. %function removed.
  2180. \endissue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2181. \endissue{DYNAMIC-EXTENT:NEW-DECLARATION}
  2182. %% 9.2.0 20
  2183. An implementation is free to support other (\term{implementation-defined})
  2184. \term{declaration identifiers} as well.
  2185. \label Examples::
  2186. \code
  2187. (defun nonsense (k x z)
  2188. (foo z x) ;First call to foo
  2189. (let ((j (foo k x)) ;Second call to foo
  2190. (x (* k k)))
  2191. (declare (inline foo) (special x z))
  2192. (foo x j z))) ;Third call to foo
  2193. \endcode
  2194. In this example,
  2195. the \declref{inline} declaration applies
  2196. only to the third call to \f{foo}, but not to the first or second ones.
  2197. The \declref{special} declaration of \f{x} causes \specref{let}
  2198. to make a dynamic \term{binding} for \f{x}, and causes the reference to
  2199. \f{x}
  2200. in the body of \specref{let} to be a dynamic reference.
  2201. The reference to \f{x} in the second call to \f{foo} is a local reference
  2202. to the second parameter of {\tt nonsense}.
  2203. The reference to \f{x} in the first call to \f{foo} is a local
  2204. reference, not a \declref{special} one. The \declref{special} declaration of \f{z}
  2205. causes the reference to \f{z} in the
  2206. %Added for Moon:
  2207. third
  2208. call
  2209. to \f{foo} to be a dynamic reference; it does not
  2210. refer to the parameter to \f{nonsense} named \f{z}, because that
  2211. parameter \term{binding} has not been declared to be \declref{special}.
  2212. (The \declref{special} declaration of \f{z} does not appear in the body
  2213. of \macref{defun}, but in an inner \term{form}, and therefore does not
  2214. affect the \term{binding} of the \term{parameter}.)
  2215. \label Affected By:\None.
  2216. \label Exceptional Situations::
  2217. The consequences of trying to use a \misc{declare} \term{expression} as
  2218. a \term{form} to be \term{evaluated} are undefined.
  2219. \editornote{KMP: Probably we need to say something here about ill-formed
  2220. declare expressions.}
  2221. \label See Also::
  2222. \funref{proclaim},
  2223. \secref\TypeSpecifiers,
  2224. \declref{declaration},
  2225. \declref{dynamic-extent},
  2226. \declref{ftype},
  2227. \declref{ignorable},
  2228. \declref{ignore},
  2229. \declref{inline},
  2230. \declref{notinline},
  2231. \declref{optimize},
  2232. \declref{type}
  2233. \label Notes:\None.
  2234. %In all cases such additional code is within the scope of any \term{pervasive}
  2235. %declarations appearing before the body of the \term{form}.
  2236. %Declarations that affect \term{bindings}
  2237. %have no effect on such code, except (of course)
  2238. %in those situations where the code is defined to be within the scope
  2239. %of the variables affected by such non-\term{pervasive} declarations.
  2240. %%% 9.1.0 3
  2241. %Those \term{forms} that permit declarations to appear
  2242. %perform explicit checks for their presence.
  2243. \endcom
  2244. %%% ========== IGNORE
  2245. %%% ========== IGNORABLE
  2246. \begincom{ignore, ignorable}\ftype{Declaration}
  2247. \issue{DOTIMES-IGNORE:X3J13-MAR91}
  2248. \label Syntax::
  2249. \f{\paren{ignore \star{\curly{\param{var} | \paren{\misc{function} \param{fn}}}}}}
  2250. \f{\paren{ignorable \star{\curly{\param{var} | \paren{\misc{function} \param{fn}}}}}}
  2251. \label Arguments::
  2252. \param{var}---a \term{variable} \term{name}.
  2253. \param{fn}---a \term{function} \term{name}.
  2254. \label Valid Context::
  2255. \term{declaration}
  2256. %% Removed per X3J13 -kmp 4-Oct-93
  2257. %or \term{proclamation}
  2258. \label Binding Types Affected::
  2259. \term{variable}, \term{function}
  2260. \label Description::
  2261. \issue{IGNORE-USE-TERMINOLOGY:VALUE-ONLY}
  2262. The \declref{ignore} and \declref{ignorable} declarations
  2263. refer to \term{for-value} \term{references}
  2264. to \term{variable} \term{bindings} for the \param{vars}
  2265. and to \term{function} \term{bindings} for the \param{fns}.
  2266. An \declref{ignore} \term{declaration} specifies that
  2267. \term{for-value} \term{references} to the indicated \term{bindings}
  2268. will not
  2269. occur within the scope of the \term{declaration}.
  2270. Within the \term{scope} of such a \term{declaration},
  2271. it is desirable
  2272. for a compiler to issue a warning about
  2273. the presence of
  2274. either a \term{for-value} \term{reference} to any \param{var} or \param{fn},
  2275. or a \declref{special} \term{declaration} for any \param{var}.
  2276. An \declref{ignorable} \term{declaration} specifies that
  2277. \term{for-value} \term{references} to the indicated \term{bindings}
  2278. might or might not
  2279. occur within the scope of the \term{declaration}.
  2280. Within the \term{scope} of such a \term{declaration},
  2281. it is not desirable
  2282. for a compiler to issue a warning about
  2283. the presence or absence of
  2284. either a \term{for-value} \term{reference} to any \param{var} or \param{fn},
  2285. or a \declref{special} \term{declaration} for any \param{var}.
  2286. When not within the \term{scope}
  2287. of a \declref{ignore} or \declref{ignorable} \term{declaration},
  2288. it is desirable
  2289. for a compiler to issue a warning about
  2290. any \param{var} for which there is
  2291. neither a \term{for-value} \term{reference}
  2292. nor a \declref{special} \term{declaration},
  2293. or about
  2294. any \param{fn} for which there is
  2295. no \term{for-value} \term{reference}.
  2296. Any warning about a ``used'' or ``unused'' \term{binding} must be \oftype{style-warning},
  2297. and may not affect program semantics.
  2298. \endissue{IGNORE-USE-TERMINOLOGY:VALUE-ONLY}
  2299. %!!! Maybe separate out to a concept section?
  2300. %!!! Once these functions are described as using stream vars,
  2301. % we can maybe remove this enumeration.
  2302. % Alternatively, we could make a table and put it in the chapter of "general rules".
  2303. The \term{stream variables} established by
  2304. \macref{with-open-file},
  2305. \macref{with-open-stream},
  2306. \macref{with-input-from-string},
  2307. and \macref{with-output-to-string},
  2308. and all \term{iteration variables} are, by definition, always ``used''.
  2309. Using \f{(declare (ignore \param{v}))},
  2310. for such a \term{variable} \param{v} has unspecified consequences.
  2311. \endissue{DOTIMES-IGNORE:X3J13-MAR91}
  2312. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  2313. % % added. I interpolated the bit about ignorable, since this was
  2314. % % not covered in the original proposal. --sjl 4 Mar 92
  2315. % \issue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2316. % \declref{ignore} and \declref{ignorable} declarations may apply to
  2317. % \term{symbol macros}. Such a declaration specifies that the named
  2318. % \term{symbol macro} must not (in the case of \declref{ignore}) or
  2319. % may not (in the case of \declref{ignorable}) be referenced within
  2320. % the scope of the declaration.
  2321. % \endissue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2322. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  2323. \label See Also::
  2324. \misc{declare}
  2325. %% Removed per X3J13. -kmp 4-Oct-93
  2326. % , \macref{declaim},
  2327. % \funref{proclaim}
  2328. \endcom
  2329. %%% ========== DYNAMIC-EXTENT
  2330. \begincom{dynamic-extent}\ftype{Declaration}
  2331. \label Syntax::
  2332. \f{(dynamic-extent \interleave{\starparam{var} |
  2333. \star{\paren{\misc{function} \param{fn}}}})}
  2334. \label Arguments::
  2335. \param{var}---a \term{variable} \term{name}.
  2336. \param{fn}---a \term{function} \term{name}.
  2337. \label Valid Context::
  2338. \term{declaration}
  2339. %% Removed per X3J13 -kmp 4-Oct-93
  2340. %or \term{proclamation}
  2341. \label Binding Types Affected::
  2342. \term{variable}, \term{function}
  2343. \label Description::
  2344. \issue{DYNAMIC-EXTENT:NEW-DECLARATION}
  2345. %!!! This needs work. -kmp 23-Aug-91
  2346. % Suppose that form <f> contains a DYNAMIC-EXTENT declaration for
  2347. % variable <v> (which need not be bound by <f>). Consider the values
  2348. % <w1>, ..., <wN> taken on by <v> during the course of some execution of
  2349. % <f>. The declaration asserts that if object <x> is an OIP of <wI>
  2350. % when <wI> ever becomes the value of <v>, then just after execution of
  2351. % <f> terminates <x> will be either inaccessible or still an OIP of <v>.
  2352. In some containing \term{form}, \param{F}, this declaration
  2353. asserts for each \param{var$\sub{i}$} (which need not be bound by \param{F}),
  2354. and for each \term{value} \param{v$\sub{ij}$} that \param{var$\sub{i}$} takes on,
  2355. and for each \term{object} \param{x$\sub{ijk}$} that
  2356. %% Removed per Moon
  2357. %\param{v$\sub{ij}$}
  2358. is
  2359. an \term{otherwise inaccessible part} of \param{v$\sub{ij}$} at any time when
  2360. %% "it" => V[ij] per Moon
  2361. %it
  2362. \param{v$\sub{ij}$}
  2363. becomes the value of \param{var$\sub{i}$},
  2364. that just after the execution of \param{F} terminates,
  2365. \param{x$\sub{ijk}$} is either \term{inaccessible}
  2366. (if \param{F} established a \term{binding} for \param{var$\sub{i}$})
  2367. or still an \term{otherwise inaccessible part} of the current value of
  2368. \param{var$\sub{i}$} (if \param{F} did not establish a \term{binding}
  2369. for \param{var$\sub{i}$}).
  2370. \issue{DYNAMIC-EXTENT-FUNCTION:EXTEND}
  2371. % The \param{var} may either be a symbol naming a variable,
  2372. % or a list of the form {\tt (function \i{name})} which names a function.
  2373. The same relation holds for each \param{fn$\sub{i}$},
  2374. except that the \term{bindings} are in the \term{function} \term{namespace}.
  2375. \endissue{DYNAMIC-EXTENT-FUNCTION:EXTEND}
  2376. The compiler is permitted to use
  2377. %make whatever optimizations are appropriate given
  2378. %% For RPG:
  2379. this information in any way that is appropriate to the \term{implementation}
  2380. and that does not conflict with the semantics of \clisp.
  2381. \declref{dynamic-extent} declarations can be \term{free declarations}
  2382. or \term{bound declarations}.
  2383. % added. --sjl 4 Mar 92
  2384. \issue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2385. The \param{vars} and \param{fns} named in a \declref{dynamic-extent}
  2386. declaration must not refer to \term{symbol macro} or \term{macro} bindings.
  2387. \endissue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2388. \label Examples::
  2389. Since stack allocation of the initial value entails knowing at the
  2390. \term{object}'s creation time that the \term{object} can be
  2391. \term{stack-allocated}, it is not generally useful to make a
  2392. \declref{dynamic-extent} \term{declaration} for \term{variables}
  2393. which have no lexically apparent initial value.
  2394. For example, it is probably useful to write:
  2395. \code
  2396. (defun f ()
  2397. (let ((x (list 1 2 3)))
  2398. (declare (dynamic-extent x))
  2399. ...))
  2400. \endcode
  2401. This would permit those compilers that wish to do so to \term{stack allocate}
  2402. the list held by the local variable {\tt x}. It is permissible,
  2403. but in practice probably not as useful, to write:
  2404. \code
  2405. (defun g (x) (declare (dynamic-extent x)) ...)
  2406. (defun f () (g (list 1 2 3)))
  2407. \endcode
  2408. Most compilers would probably not \term{stack allocate} the \term{argument}
  2409. to {\tt g} in {\tt f} because it would be a modularity violation for the compiler
  2410. to assume facts about {\tt g} from within {\tt f}. Only an implementation that
  2411. was willing to be responsible for recompiling {\tt f} if the definition of {\tt g}
  2412. changed incompatibly could legitimately \term{stack allocate} the \term{list}
  2413. argument to {\tt g} in {\tt f}.
  2414. Here is another example:
  2415. \code
  2416. (declaim (inline g))
  2417. (defun g (x) (declare (dynamic-extent x)) ...)
  2418. (defun f () (g (list 1 2 3)))
  2419. (defun f ()
  2420. (flet ((g (x) (declare (dynamic-extent x)) ...))
  2421. (g (list 1 2 3))))
  2422. \endcode
  2423. In the previous example, some compilers might determine that optimization was
  2424. possible and others might not.
  2425. A variant of this is the so-called ``stack allocated rest list''
  2426. that can be achieved (in implementations supporting the optimization) by:
  2427. \code
  2428. (defun f (&rest x)
  2429. (declare (dynamic-extent x))
  2430. ...)
  2431. \endcode
  2432. Note that although the initial value of {\tt x} is not explicit, the {\tt f}
  2433. function is responsible for assembling the list {\tt x} from the passed arguments,
  2434. so the {\tt f} function can be optimized by the compiler to construct a
  2435. \term{stack-allocated} list instead of a heap-allocated list in implementations
  2436. that support such.
  2437. In the following example,
  2438. \code
  2439. (let ((x (list 'a1 'b1 'c1))
  2440. (y (cons 'a2 (cons 'b2 (cons 'c2 nil)))))
  2441. (declare (dynamic-extent x y))
  2442. ...)
  2443. \endcode
  2444. The \term{otherwise inaccessible parts} of {\tt x} are three
  2445. \term{conses}, and the \term{otherwise inaccessible parts}
  2446. of {\tt y} are three other \term{conses}.
  2447. None of the symbols {\tt a1}, {\tt b1}, {\tt c1}, {\tt a2},
  2448. {\tt b2}, {\tt c2}, or \nil\ is an
  2449. \term{otherwise inaccessible part} of {\tt x} or {\tt y} because each
  2450. is \term{interned} and hence \term{accessible} by the \term{package}
  2451. (or \term{packages}) in which it is \term{interned}.
  2452. However, if a freshly allocated \term{uninterned} \term{symbol} had
  2453. been used, it would have been an \term{otherwise inaccessible part} of
  2454. the \term{list} which contained it.
  2455. \code
  2456. ;; In this example, the implementation is permitted to \term{stack allocate}
  2457. ;; the list that is bound to X.
  2458. (let ((x (list 1 2 3)))
  2459. (declare (dynamic-extent x))
  2460. (print x)
  2461. :done)
  2462. \OUT (1 2 3)
  2463. \EV :DONE
  2464. ;; In this example, the list to be bound to L can be \term{stack-allocated}.
  2465. (defun zap (x y z)
  2466. (do ((l (list x y z) (cdr l)))
  2467. ((null l))
  2468. (declare (dynamic-extent l))
  2469. (prin1 (car l)))) \EV ZAP
  2470. (zap 1 2 3)
  2471. \OUT 123
  2472. \EV NIL
  2473. ;; Some implementations might open-code LIST-ALL-PACKAGES in a way
  2474. ;; that permits using \term{stack allocation} of the list to be bound to L.
  2475. (do ((l (list-all-packages) (cdr l)))
  2476. ((null l))
  2477. (declare (dynamic-extent l))
  2478. (let ((name (package-name (car l))))
  2479. (when (string-search "COMMON-LISP" name) (print name))))
  2480. \OUT "COMMON-LISP"
  2481. \OUT "COMMON-LISP-USER"
  2482. \EV NIL
  2483. ;; Some implementations might have the ability to \term{stack allocate}
  2484. ;; rest lists. A declaration such as the following should be a cue
  2485. ;; to such implementations that stack-allocation of the rest list
  2486. ;; would be desirable.
  2487. (defun add (&rest x)
  2488. (declare (dynamic-extent x))
  2489. (apply #'+ x)) \EV ADD
  2490. (add 1 2 3) \EV 6
  2491. (defun zap (n m)
  2492. ;; Computes (RANDOM (+ M 1)) at relative speed of roughly O(N).
  2493. ;; It may be slow, but with a good compiler at least it
  2494. ;; doesn't waste much heap storage. :-\}
  2495. (let ((a (make-array n)))
  2496. (declare (dynamic-extent a))
  2497. (dotimes (i n)
  2498. (declare (dynamic-extent i))
  2499. (setf (aref a i) (random (+ i 1))))
  2500. (aref a m))) \EV ZAP
  2501. (< (zap 5 3) 3) \EV \term{true}
  2502. \endcode
  2503. The following are in error, since the value of {\tt x} is used outside of its
  2504. \term{extent}:
  2505. \code
  2506. (length (list (let ((x (list 1 2 3))) ; Invalid
  2507. (declare (dynamic-extent x))
  2508. x)))
  2509. (progn (let ((x (list 1 2 3))) ; Invalid
  2510. (declare (dynamic-extent x))
  2511. x)
  2512. nil)
  2513. \endcode
  2514. \endissue{DYNAMIC-EXTENT:NEW-DECLARATION}
  2515. \label See Also::
  2516. \misc{declare}
  2517. %% Removed per X3J13. -kmp 4-Oct-93
  2518. % , \macref{declaim},
  2519. % \funref{proclaim}
  2520. \label Notes::
  2521. The most common optimization is to \term{stack allocate} the
  2522. initial value of the \term{objects} named by the \param{vars}.
  2523. It is permissible for an implementation to simply ignore this declaration.
  2524. \endcom
  2525. %%% ========== TYPE
  2526. \begincom{type}\ftype{Declaration}
  2527. \label Syntax::
  2528. \f{(type \param{typespec} \starparam{var})}
  2529. \f{(\param{typespec} \starparam{var})}
  2530. \label Arguments::
  2531. \param{typespec}---a \term{type specifier}.
  2532. \param{var}---a \term{variable} \term{name}.
  2533. \label Valid Context::
  2534. \term{declaration} or \term{proclamation}
  2535. \label Binding Types Affected::
  2536. \term{variable}
  2537. \label Description::
  2538. Affects
  2539. only variable \term{bindings} and specifies that the
  2540. \param{vars} take on
  2541. values only of the specified \param{typespec}.
  2542. In particular, values assigned to the variables by \specref{setq},
  2543. as well as the initial values of the \param{vars} must be of
  2544. the specified \param{typespec}.
  2545. \declref{type} declarations never apply to function \term{bindings} (see \declref{ftype}).
  2546. %% This is already said in the stuff on COMMON-LISP package.
  2547. %% !!! Maybe add a cross-reference? -kmp 9-Feb-92
  2548. % \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2549. % Except where explicitly allowed, the consequences are undefined if a
  2550. % \term{symbol} in \thepackage{common-lisp} is used as a
  2551. % \param{var} argument.
  2552. % If such a \term{symbol} is not globally
  2553. % defined
  2554. % %"by this standard" added per barmar: -kmp 28-Dec-90
  2555. % by this standard
  2556. % as a variable or a constant, it is allowed to lexically bind it
  2557. % and to declare the {\tt type} of that \term{binding}. For example,
  2558. % the lexical variable names {\tt list} and {\tt car} are permitted.
  2559. % \editornote{KMP: This is unintelligible to me and needs to be rewritten to clarify
  2560. % that binding CL special variables is ok, but that their type decls are lexical.}
  2561. % \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2562. \issue{SYMBOL-MACROLET-DECLARE:ALLOW}
  2563. A type declaration of a \term{symbol}
  2564. defined by \specref{symbol-macrolet} is equivalent
  2565. to wrapping a \specref{the}
  2566. expression around the expansion of that \term{symbol},
  2567. \endissue{SYMBOL-MACROLET-DECLARE:ALLOW}
  2568. % moved here from symbol-macrolet dictionary entry --sjl 5 mar 92
  2569. \issue{SYMBOL-MACROLET-TYPE-DECLARATION:NO}
  2570. although the \term{symbol}'s \term{macro expansion} is not actually affected.
  2571. \endissue{SYMBOL-MACROLET-TYPE-DECLARATION:NO}
  2572. \issue{DECLARE-TYPE-FREE:LEXICAL}
  2573. The meaning of a type declaration
  2574. is equivalent to changing each reference to
  2575. a variable (\param{var}) within the scope of the
  2576. declaration to {\tt (the \param{typespec} \param{var})},
  2577. changing each expression assigned to the
  2578. variable (\param{new-value}) within the scope of the declaration to
  2579. {\tt (the \param{typespec} \param{new-value})},
  2580. and executing
  2581. {\tt (the \param{typespec} \param{var})} at the moment the scope of the declaration
  2582. is entered.
  2583. A \term{type} declaration is valid in all declarations. The interpretation
  2584. of a type declaration is as follows:
  2585. \beginlist
  2586. \itemitem{1.} During the execution of any reference to the
  2587. declared variable within the scope of the declaration, the consequences
  2588. are
  2589. %"unspecified" -> "undefined" per barmar. i concur. -kmp
  2590. %unspecified
  2591. undefined
  2592. if
  2593. the value of the declared variable is not of the declared \term{type}.
  2594. \itemitem{2.} During the execution of any
  2595. \specref{setq} of the declared variable within the scope
  2596. of the declaration, the consequences are
  2597. %"unspecified" -> "undefined" per barmar. i concur. -kmp
  2598. %unspecified
  2599. undefined
  2600. if the newly assigned value of the
  2601. declared variable is not of the declared \term{type}.
  2602. \itemitem{3.} At the moment the
  2603. scope of the declaration is entered, the consequences are
  2604. %"unspecified" -> "undefined" per barmar. i concur. -kmp
  2605. %unspecified
  2606. undefined
  2607. if the value of the
  2608. declared variable is not of the declared \term{type}.
  2609. \endlist
  2610. A \term{type} declaration affects only variable references within
  2611. its scope.
  2612. % and the meaning of free and "variable-binding-associated" type
  2613. % declarations can be described identically.
  2614. If nested \term{type} declarations refer to the same variable,
  2615. then the value of the variable must be a member of the intersection of
  2616. the declared \term{types}.
  2617. \endissue{DECLARE-TYPE-FREE:LEXICAL}
  2618. \issue{SPECIAL-TYPE-SHADOWING:CLARIFY}
  2619. If there is a local {\tt type} declaration for a dynamic
  2620. variable, and there is also a global {\tt type} proclamation for that same
  2621. variable, then the value of the variable within the scope of the local
  2622. declaration must be a member of the intersection of the two declared
  2623. \term{types}.
  2624. \endissue{SPECIAL-TYPE-SHADOWING:CLARIFY}
  2625. \declref{type} declarations can be \term{free declarations}
  2626. or \term{bound declarations}.
  2627. \issue{TYPE-DECLARATION-ABBREVIATION:ALLOW-ALL}
  2628. %!!! This paragraph might be better off elsewhere, but can live here for now.
  2629. A \term{symbol} cannot be both the name of a \term{type} and the name of a
  2630. declaration. Defining a \term{symbol} as the \term{name} of a \term{class},
  2631. \term{structure}, \term{condition}, or \term{type}, when the \term{symbol}
  2632. has been \term{declared} as a declaration name, or vice versa, signals an error.
  2633. \endissue{TYPE-DECLARATION-ABBREVIATION:ALLOW-ALL}
  2634. %% The following was inserted after GLS checked this out.
  2635. \issue{DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES:RESTRICTIVE}
  2636. Within the \term{lexical scope} of an \typeref{array} type declaration,
  2637. all references to \term{array} \term{elements} are assumed to satisfy the
  2638. \term{expressed array element type} (as opposed to the \term{upgraded array element type}).
  2639. %The consequences are undefined if this is ever violated.
  2640. A compiler can treat
  2641. the code within the scope of the \typeref{array} type declaration as if each
  2642. \term{access} of an \term{array} \term{element} were surrounded by an appropriate
  2643. \specref{the} form.
  2644. \endissue{DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES:RESTRICTIVE}
  2645. \label Examples::
  2646. \code
  2647. (defun f (x y)
  2648. (declare (type fixnum x y))
  2649. (let ((z (+ x y)))
  2650. (declare (type fixnum z))
  2651. z)) \EV F
  2652. (f 1 2) \EV 3
  2653. ;; The previous definition of F is equivalent to
  2654. (defun f (x y)
  2655. ;; This declaration is a shorthand form of the TYPE declaration
  2656. (declare (fixnum x y))
  2657. ;; To declare the type of a return value, it's not necessary to
  2658. ;; create a named variable. A THE special form can be used instead.
  2659. (the fixnum (+ x y))) \EV F
  2660. (f 1 2) \EV 3
  2661. \endcode
  2662. \issue{DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES:RESTRICTIVE}
  2663. % There were some comments on this code (from the Cleanup issue, probably)
  2664. % that no one liked, so I removed them. This example might do better with
  2665. % some explanation, but better no explanation than a broken one. -kmp 14-Feb-92
  2666. \code
  2667. (defvar *one-array* (make-array 10 :element-type '(signed-byte 5)))
  2668. (defvar *another-array* (make-array 10 :element-type '(signed-byte 8)))
  2669. (defun frob (an-array)
  2670. (declare (type (array (signed-byte 5) 1) an-array))
  2671. (setf (aref an-array 1) 31)
  2672. (setf (aref an-array 2) 127)
  2673. (setf (aref an-array 3) (* 2 (aref an-array 3)))
  2674. (let ((foo 0))
  2675. (declare (type (signed-byte 5) foo))
  2676. (setf foo (aref an-array 0))))
  2677. (frob *one-array*)
  2678. (frob *another-array*)
  2679. \endcode
  2680. \medbreak
  2681. The above definition of \f{frob} is equivalent to:
  2682. \code
  2683. (defun frob (an-array)
  2684. (setf (the (signed-byte 5) (aref an-array 1)) 31)
  2685. (setf (the (signed-byte 5) (aref an-array 2)) 127)
  2686. (setf (the (signed-byte 5) (aref an-array 3))
  2687. (* 2 (the (signed-byte 5) (aref an-array 3))))
  2688. (let ((foo 0))
  2689. (declare (type (signed-byte 5) foo))
  2690. (setf foo (the (signed-byte 5) (aref an-array 0)))))
  2691. \endcode
  2692. %!!! Barmar: What does upgrading matter?
  2693. Given an implementation in which
  2694. \term{fixnums} are 29 bits but \typeref{fixnum} \term{arrays}
  2695. are upgraded to signed 32-bit \term{arrays},
  2696. the following
  2697. %% "should->could" per barmar. i concur. -kmp 27-Dec-90
  2698. %should
  2699. could be compiled with all \term{fixnum} arithmetic:
  2700. \code
  2701. (defun bump-counters (counters)
  2702. (declare (type (array fixnum *) bump-counters))
  2703. (dotimes (i (length counters))
  2704. (incf (aref counters i))))
  2705. \endcode
  2706. \endissue{DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES:RESTRICTIVE}
  2707. \label See Also::
  2708. \misc{declare},
  2709. \macref{declaim},
  2710. \funref{proclaim}
  2711. \label Notes::
  2712. \f{(\param{typespec} \starparam{var})}
  2713. is an abbreviation for \f{(type \param{typespec} \starparam{var})}.
  2714. \issue{TYPE-DECLARATION-ABBREVIATION:ALLOW-ALL}
  2715. %provided that \param{typespec} is one of the standard \term{type specifier}
  2716. %\term{symbols} in \figref\StandardizedAtomicTypeSpecs.
  2717. \endissue{TYPE-DECLARATION-ABBREVIATION:ALLOW-ALL}
  2718. A \declref{type} declaration for the arguments to a function does not
  2719. necessarily imply anything about the type of the result. The following
  2720. function is not permitted to be compiled using \term{implementation-dependent}
  2721. \term{fixnum}-only arithmetic:
  2722. \code
  2723. (defun f (x y) (declare (fixnum x y)) (+ x y))
  2724. \endcode
  2725. To see why, consider \f{(f most-positive-fixnum 1)}.
  2726. Common Lisp defines that \f{F} must return a \term{bignum} here, rather
  2727. than signal an error or produce a mathematically incorrect result.
  2728. If you have special knowledge such ``\term{fixnum} overflow'' cases will
  2729. not come up, you can declare the result value to be in the \term{fixnum}
  2730. range, enabling some compilers to use more efficient arithmetic:
  2731. \code
  2732. (defun f (x y)
  2733. (declare (fixnum x y))
  2734. (the fixnum (+ x y)))
  2735. \endcode
  2736. Note, however, that in the three-argument case, because of the possibility
  2737. of an implicit intermediate value growing too large, the following will not
  2738. cause \term{implementation-dependent} \term{fixnum}-only arithmetic to be used:
  2739. \code
  2740. (defun f (x y)
  2741. (declare (fixnum x y z))
  2742. (the fixnum (+ x y z)))
  2743. \endcode
  2744. To see why, consider \f{(f most-positive-fixnum 1 -1).}
  2745. Although the arguments and the result are all \term{fixnums}, an intermediate
  2746. value is not a \term{fixnum}. If it is important that
  2747. \term{implementation-dependent} \term{fixnum}-only arithmetic be selected
  2748. in \term{implementations} that provide it,
  2749. consider writing something like this instead:
  2750. \code
  2751. (defun f (x y)
  2752. (declare (fixnum x y z))
  2753. (the fixnum (+ (the fixnum (+ x y)) z)))
  2754. \endcode
  2755. \endcom
  2756. %%% ========== INLINE
  2757. %%% ========== NOTINLINE
  2758. \begincom{inline, notinline}\ftype{Declaration}
  2759. \label Syntax::
  2760. {\tt (inline \starparam{function-name})}
  2761. {\tt (notinline \starparam{function-name})}
  2762. \label Arguments::
  2763. \param{function-name}---a \term{function name}.
  2764. \label Valid Context::
  2765. \term{declaration} or \term{proclamation}
  2766. \label Binding Types Affected::
  2767. \term{function}
  2768. \label Description::
  2769. \issue{FUNCTION-NAME:LARGE}
  2770. \declref{inline} specifies that
  2771. it is desirable for the compiler to produce inline calls
  2772. to the \term{functions} named by \param{function-names};
  2773. that is, the code for a specified \param{function-name}
  2774. \endissue{FUNCTION-NAME:LARGE}
  2775. should be integrated into the calling routine, appearing ``in line''
  2776. in place of a procedure call.
  2777. %This declaration is \term{pervasive}.
  2778. A compiler is free to ignore this declaration.
  2779. \declref{inline} declarations never apply to variable \term{bindings}.
  2780. %% 9.2.0 14
  2781. If one of the \term{functions} mentioned has a lexically apparent local definition
  2782. (as made by \specref{flet} or \specref{labels}), then the declaration
  2783. applies to that local definition and not to the global function definition.
  2784. \issue{ALLOW-LOCAL-INLINE:INLINE-NOTINLINE}
  2785. While no \term{conforming implementation} is required to perform inline expansion
  2786. of user-defined functions, those \term{implementations} that do attempt
  2787. to recognize the following paradigm:
  2788. To define a \term{function} \f{f} that is not \declref{inline} by default
  2789. but for which \f{(declare (inline f))} will make \param{f} be locally inlined,
  2790. the proper definition sequence is:
  2791. \code
  2792. (declaim (inline f))
  2793. (defun f ...)
  2794. (declaim (notinline f))
  2795. \endcode
  2796. The \declref{inline} proclamation preceding the \macref{defun} \term{form}
  2797. ensures that the \term{compiler} has the opportunity save the information
  2798. necessary for inline expansion, and the \declref{notinline} proclamation
  2799. following the \macref{defun} \term{form} prevents \f{f} from being expanded
  2800. inline everywhere.
  2801. \endissue{ALLOW-LOCAL-INLINE:INLINE-NOTINLINE}
  2802. \issue{FUNCTION-NAME:LARGE}
  2803. \declref{notinline} specifies that it is
  2804. \endissue{FUNCTION-NAME:LARGE}
  2805. undesirable to compile the \term{functions}
  2806. named by \param{function-names} in-line.
  2807. %This declaration is \term{pervasive}.
  2808. A compiler is not free to ignore this declaration;
  2809. %clarifying clause added per barmar. -kmp 28-Dec-90
  2810. calls to the specified functions must be implemented as out-of-line subroutine calls.
  2811. %% 9.2.0 16
  2812. If one of the \term{functions}
  2813. mentioned has a lexically apparent local definition
  2814. (as made by \specref{flet} or \specref{labels}), then the declaration
  2815. applies to that local definition and not to the global function definition.
  2816. % added. --sjl 4 Mar 92
  2817. \issue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2818. In the presence of a \term{compiler macro} definition for
  2819. \param{function-name}, a \declref{notinline} declaration prevents that
  2820. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  2821. \term{compiler macro} from being used.
  2822. % in preference to the normal definition
  2823. % of \param{function-name} as a \term{function} or \term{macro}.
  2824. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  2825. An \declref{inline} declaration may be used to encourage use of
  2826. \term{compiler macro} definitions. \declref{inline} and \declref{notinline}
  2827. declarations otherwise have no effect when the lexically visible definition
  2828. of \param{function-name} is a \term{macro} definition.
  2829. \endissue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2830. \declref{inline} and \declref{notinline} declarations can be \term{free declarations} or
  2831. \term{bound declarations}.
  2832. \declref{inline} and \declref{notinline} declarations of functions that
  2833. appear before the body of a
  2834. \specref{flet}
  2835. or \specref{labels}
  2836. \issue{WITH-ADDED-METHODS:DELETE}
  2837. % \specref{with-added-methods},
  2838. \endissue{WITH-ADDED-METHODS:DELETE}
  2839. \issue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  2840. % \specref{generic-flet},
  2841. % and
  2842. % \specref{generic-labels}
  2843. \endissue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  2844. \term{form} that defines that function are \term{bound declarations}.
  2845. Such declarations in other contexts are \term{free declarations}.
  2846. \label Examples::
  2847. \code
  2848. ;; The globally defined function DISPATCH should be open-coded,
  2849. ;; if the implementation supports inlining, unless a NOTINLINE
  2850. ;; declaration overrides this effect.
  2851. (declaim (inline dispatch))
  2852. (defun dispatch (x) (funcall (get (car x) 'dispatch) x))
  2853. ;; Here is an example where inlining would be encouraged.
  2854. (defun top-level-1 () (dispatch (read-command)))
  2855. ;; Here is an example where inlining would be prohibited.
  2856. (defun top-level-2 ()
  2857. (declare (notinline dispatch))
  2858. (dispatch (read-command)))
  2859. ;; Here is an example where inlining would be prohibited.
  2860. (declaim (notinline dispatch))
  2861. (defun top-level-3 () (dispatch (read-command)))
  2862. ;; Here is an example where inlining would be encouraged.
  2863. (defun top-level-4 ()
  2864. (declare (inline dispatch))
  2865. (dispatch (read-command)))
  2866. \endcode
  2867. \label See Also::
  2868. \misc{declare},
  2869. \macref{declaim},
  2870. \funref{proclaim}
  2871. \endcom
  2872. %%% ========== FTYPE
  2873. \begincom{ftype}\ftype{Declaration}
  2874. \label Syntax::
  2875. \issue{FUNCTION-NAME:LARGE}
  2876. \f{(ftype \param{type} \starparam{function-name})}
  2877. \endissue{FUNCTION-NAME:LARGE}
  2878. \label Arguments::
  2879. \param{function-name}---a \term{function name}.
  2880. % added --sjl 7 Mar 92
  2881. \param{type}---a \term{type specifier}.
  2882. \label Valid Context::
  2883. \term{declaration} or \term{proclamation}
  2884. \label Binding Types Affected::
  2885. \term{function}
  2886. \label Description::
  2887. Specifies that the \term{functions} named by \param{function-names} are of
  2888. the functional type \param{type}.
  2889. For example:
  2890. \code
  2891. (declare (ftype (function (integer list) t) ith)
  2892. (ftype (function (number) float) sine cosine))
  2893. \endcode
  2894. If one of the \term{functions} mentioned has a lexically apparent local definition
  2895. (as made by \specref{flet} or \specref{labels}), then the declaration
  2896. applies to that local definition and not to the global function definition.
  2897. \declref{ftype} declarations never apply to variable \term{bindings} (see {\tt type}).
  2898. % added. --sjl 4 Mar 92
  2899. \issue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2900. The lexically apparent bindings of \param{function-names} must not be
  2901. \term{macro} definitions. (This is because \declref{ftype} declares the
  2902. functional definition of each \term{function name} to be of a particular
  2903. subtype of \typeref{function}, and \term{macros} do not denote
  2904. \term{functions}.)
  2905. \endissue{MACRO-DECLARATIONS:MAKE-EXPLICIT}
  2906. % This is adequately covered in the packages chapter. --sjl 5 Mar 92
  2907. % \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2908. % Except where explicitly allowed, the consequences are undefined if
  2909. % a \term{symbol} in \thepackage{common-lisp}
  2910. % is used as a \param{function-name} argument.
  2911. % If such a \term{symbol} is not defined
  2912. % %"by this standard" added per barmar: -kmp 28-Dec-90
  2913. % by this standard
  2914. % as a \term{function}, \term{macro}, or \term{special form},
  2915. % it is allowed to declare the
  2916. % \declref{ftype} of that \term{binding}.
  2917. % \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2918. \declref{ftype}
  2919. \issue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2920. %and \declref{function}
  2921. \endissue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2922. declarations
  2923. can be \term{free declarations} or \term{bound declarations}.
  2924. \declref{ftype} declarations of functions that appear before the body of a
  2925. \specref{flet}
  2926. or \specref{labels}
  2927. \issue{WITH-ADDED-METHODS:DELETE}
  2928. % \specref{with-added-methods},
  2929. \endissue{WITH-ADDED-METHODS:DELETE}
  2930. \issue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  2931. % \specref{generic-flet},
  2932. % and
  2933. % \specref{generic-labels}
  2934. \endissue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  2935. \term{form} that defines that function are \term{bound declarations}.
  2936. Such declarations in other contexts are \term{free declarations}.
  2937. \issue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2938. %
  2939. % {\tt (function \param{var1} \param{var2}...)}
  2940. % is equivalent to
  2941. % {\tt (type function \param{var1} \param{var2}...)}
  2942. %
  2943. %
  2944. %%% 9.2.0 12
  2945. %If one of the \term{functions}
  2946. %mentioned has a lexically apparent local definition
  2947. %(as made by \specref{flet} or \specref{labels}), then the declaration
  2948. %applies to that local definition and not to the global function definition.
  2949. %
  2950. %
  2951. % See \declref{type} and \declref{ftype}.
  2952. %
  2953. \endissue{DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION}
  2954. \label See Also::
  2955. \misc{declare},
  2956. \macref{declaim},
  2957. \funref{proclaim}
  2958. \endcom
  2959. %%% ========== DECLARATION
  2960. \begincom{declaration}\ftype{Declaration}
  2961. \label Syntax::
  2962. \f{(declaration \starparam{name})}
  2963. \label Arguments::
  2964. \param{name}---a \term{symbol}.
  2965. \label Binding Types Affected:\None.
  2966. \label Valid Context::
  2967. \term{proclamation} only
  2968. \label Description::
  2969. %% 9.2.0 19
  2970. Advises the compiler that each \param{name} is a valid but potentially
  2971. non-standard declaration name. The purpose of this is to tell one
  2972. compiler not to issue warnings for declarations meant for another
  2973. compiler or other program processor.
  2974. % Already said in the packages chapter. --sjl 5 Mar 92
  2975. % \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2976. % The consequences are undefined if a \term{symbol} in \thepackage{common-lisp}
  2977. % is used as a \i{name} argument.
  2978. % \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  2979. %!!! Couldn't figure this out. It's obviously better to omit it than include it but...
  2980. % \reviewer{Barmar: What does this mean??}%!!!
  2981. % \f{(\i{declaration} x)} never applies to a \term{binding} of {\tt y}.
  2982. \label Examples::
  2983. \code
  2984. (declaim (declaration author target-language target-machine))
  2985. (declaim (target-language ada))
  2986. (declaim (target-machine IBM-650))
  2987. (defun strangep (x)
  2988. (declare (author "Harry Tweeker"))
  2989. (member x '(strange weird odd peculiar)))
  2990. \endcode
  2991. \label See Also::
  2992. \macref{declaim},
  2993. \funref{proclaim}
  2994. \endcom
  2995. %%% ========== OPTIMIZE
  2996. %%% ========== COMPILATION-SPEED
  2997. %%% ========== DEBUG
  2998. %%% ========== SAFETY
  2999. %%% ========== SPACE
  3000. %%% ========== SPEED
  3001. \begincom{optimize}\ftype{Declaration}
  3002. \label Syntax::
  3003. \f{(optimize \star{\curly{\param{quality} | (\param{quality} \param{value})}})}
  3004. \idxref{compilation-speed}%
  3005. \idxref{debug}%
  3006. \idxref{safety}%
  3007. \idxref{space}%
  3008. \idxref{speed}
  3009. \label Arguments::
  3010. \param{quality}---an \term{optimize quality}.
  3011. \param{value}---one of the \term{integers} \f{0}, \f{1}, \f{2}, or \f{3}.
  3012. \label Valid Context::
  3013. \term{declaration} or \term{proclamation}
  3014. \label Binding Types Affected:\None.
  3015. \label Description::
  3016. Advises the compiler that each \param{quality} should be given attention
  3017. according to the specified corresponding \param{value}.
  3018. Each \param{quality} must be a \term{symbol} naming an \term{optimize quality};
  3019. the names and meanings of the standard \param{optimize qualities} are shown in
  3020. \thenextfigure.
  3021. \issue{OPTIMIZE-DEBUG-INFO:NEW-QUALITY}
  3022. \tablefigtwo{Optimize qualities}{Name}{Meaning}{
  3023. \declref{compilation-speed} & speed of the compilation process \cr
  3024. \declref{debug} & ease of debugging \cr
  3025. \declref{safety} & run-time error checking \cr
  3026. \declref{space} & both code size and run-time space \cr
  3027. \declref{speed} & speed of the object code \cr
  3028. }
  3029. \endissue{OPTIMIZE-DEBUG-INFO:NEW-QUALITY}
  3030. There may be other, \term{implementation-defined} \term{optimize qualities}.
  3031. A \param{value} \f{0} means that the corresponding \param{quality} is totally
  3032. unimportant, and \f{3} that the \param{quality} is extremely important;
  3033. \f{1} and \f{2} are intermediate values, with \f{1} the
  3034. %% "average" -> "neutral" since KAB balked and I think this will be less weird. -kmp 3-Oct-91
  3035. %average
  3036. neutral value.
  3037. \f{(\param{quality} 3)} can be abbreviated to \param{quality}.
  3038. %This declaration is \term{pervasive}.
  3039. Note that \term{code} which has the optimization \f{(safety 3)},
  3040. or just \typeref{safety},
  3041. is called \term{safe} \term{code}.
  3042. % Added per Sandra in response to Barrett query ...
  3043. The consequences are unspecified if a \param{quality} appears more than once
  3044. with \term{different} \param{values}.
  3045. \label Examples::
  3046. \code
  3047. (defun often-used-subroutine (x y)
  3048. (declare (optimize (safety 2)))
  3049. (error-check x y)
  3050. (hairy-setup x)
  3051. (do ((i 0 (+ i 1))
  3052. (z x (cdr z)))
  3053. ((null z))
  3054. ;; This inner loop really needs to burn.
  3055. (declare (optimize speed))
  3056. (declare (fixnum i))
  3057. ))
  3058. \endcode
  3059. \label See Also::
  3060. \misc{declare},
  3061. \macref{declaim},
  3062. \funref{proclaim},
  3063. {\secref\DeclScope}
  3064. \label Notes::
  3065. An \declref{optimize} declaration never applies to either a \term{variable} or
  3066. a \term{function} \term{binding}. An \declref{optimize} declaration can only
  3067. be a \term{free declaration}. For more information, \seesection\DeclScope.
  3068. \endcom
  3069. % I moved the dictionary entry for the special declaration here.
  3070. % It used to be in chapter 5, but it seemed more logical to put it with
  3071. % all the other declaration specifiers. -- sjl 5 Mar 92
  3072. %%% ========== SPECIAL
  3073. \begincom{special}\ftype{Declaration}
  3074. \label Syntax::
  3075. \f{(special \starparam{var})}
  3076. \label Arguments::
  3077. \param{var}---a \term{symbol}.
  3078. \label Valid Context::
  3079. \term{declaration} or \term{proclamation}
  3080. \label Binding Types Affected::
  3081. \term{variable}
  3082. \label Description::
  3083. Specifies that all of
  3084. the \param{vars} named are dynamic.
  3085. This specifier affects variable \term{bindings} and
  3086. affects references.
  3087. All variable \term{bindings} affected are made to be dynamic \term{bindings},
  3088. and affected variable references refer to the current dynamic
  3089. \term{binding}.
  3090. %rather than the current lexical \term{binding}.
  3091. For example:
  3092. \code
  3093. (defun hack (thing *mod*) ;The binding of the parameter
  3094. (declare (special *mod*)) ; *mod* is visible to hack1,
  3095. (hack1 (car thing))) ; but not that of thing.
  3096. (defun hack1 (arg)
  3097. (declare (special *mod*)) ;Declare references to *mod*
  3098. ;within hack1 to be special.
  3099. (if (atom arg) *mod*
  3100. (cons (hack1 (car arg)) (hack1 (cdr arg)))))
  3101. \endcode
  3102. %% 9.2.0 4
  3103. A \declref{special} declaration does not affect inner \term{bindings}
  3104. of a \param{var}; the inner \term{bindings} implicitly shadow
  3105. a \declref{special} declaration and must be explicitly re-declared to
  3106. be \declref{special}.
  3107. \declref{special} declarations never apply to function \term{bindings}.
  3108. % adequately covered in the packages chapter. --sjl 5 Mar 92
  3109. % \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  3110. % Except where explicitly allowed, the consequences are undefined if
  3111. % a \term{symbol} in \thepackage{common-lisp}
  3112. % is used as a \param{var} argument.
  3113. % \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  3114. \declref{special} declarations can be either \term{bound declarations},
  3115. affecting both a binding and references, or \term{free declarations},
  3116. affecting only references, depending on whether the declaration is
  3117. attached to a variable binding.
  3118. %% 9.1.0 14
  3119. When used in a \term{proclamation}, a \declref{special}
  3120. \term{declaration specifier}
  3121. applies to all \term{bindings} as well as to all references of the
  3122. mentioned variables. For example, after
  3123. \code
  3124. (declaim (special x))
  3125. \endcode
  3126. then in a function definition such as
  3127. \code
  3128. (defun example (x) ...)
  3129. \endcode
  3130. the parameter \f{x} is bound as a dynamic variable
  3131. rather than as a lexical variable.
  3132. \label Examples::
  3133. \code
  3134. (defun declare-eg (y) ;this y is special
  3135. (declare (special y))
  3136. (let ((y t)) ;this y is lexical
  3137. (list y
  3138. (locally (declare (special y)) y)))) ;this y refers to the
  3139. ;special binding of y
  3140. \EV DECLARE-EG
  3141. (declare-eg nil) \EV (T NIL)
  3142. \endcode
  3143. \code
  3144. (setf (symbol-value 'x) 6)
  3145. (defun foo (x) ;a lexical binding of x
  3146. (print x)
  3147. (let ((x (1+ x))) ;a special binding of x
  3148. (declare (special x)) ;and a lexical reference
  3149. (bar))
  3150. (1+ x))
  3151. (defun bar ()
  3152. (print (locally (declare (special x))
  3153. x)))
  3154. (foo 10)
  3155. \OUT 10
  3156. \OUT 11
  3157. \EV 11
  3158. \endcode
  3159. \code
  3160. (setf (symbol-value 'x) 6)
  3161. (defun bar (x y) ;[1] 1st occurrence of x
  3162. (let ((old-x x) ;[2] 2nd occurrence of x -- same as 1st occurrence
  3163. (x y)) ;[3] 3rd occurrence of x
  3164. (declare (special x))
  3165. (list old-x x)))
  3166. (bar 'first 'second) \EV (FIRST SECOND)
  3167. \endcode
  3168. \code
  3169. (defun few (x &optional (y *foo*))
  3170. (declare (special *foo*))
  3171. ...)
  3172. \endcode
  3173. The reference to \f{*foo*}
  3174. in the first line of this example is not \declref{special}
  3175. even though there is a \declref{special} declaration in the second line.
  3176. \code
  3177. (declaim (special prosp)) \EV \term{implementation-dependent}
  3178. (setq prosp 1 reg 1) \EV 1
  3179. (let ((prosp 2) (reg 2)) ;the binding of prosp is special
  3180. (set 'prosp 3) (set 'reg 3) ;due to the preceding proclamation,
  3181. (list prosp reg)) ;whereas the variable reg is lexical
  3182. \EV (3 2)
  3183. (list prosp reg) \EV (1 3)
  3184. (declaim (special x)) ;x is always special.
  3185. (defun example (x y)
  3186. (declare (special y))
  3187. (let ((y 3) (x (* x 2)))
  3188. (print (+ y (locally (declare (special y)) y)))
  3189. (let ((y 4)) (declare (special y)) (foo x)))) \EV EXAMPLE
  3190. \endcode
  3191. In the contorted code above, the outermost and innermost \term{bindings} of
  3192. \f{y} are dynamic,
  3193. but the middle
  3194. binding is lexical. The two arguments to \f{+} are different,
  3195. one being the value, which is \f{3}, of the lexical variable
  3196. \f{y}, and the other being the value of the dynamic variable named \f{y}
  3197. (a \term{binding}
  3198. of which happens, coincidentally, to lexically surround it at
  3199. an outer level). All the \term{bindings}
  3200. of \f{x} and references to \f{x}
  3201. are dynamic, however, because of the proclamation that \f{x} is
  3202. always \declref{special}.
  3203. \label See Also::
  3204. \macref{defparameter},
  3205. \macref{defvar}
  3206. \endcom
  3207. %%% ========== LOCALLY
  3208. \begincom{locally}\ftype{Special Operator}
  3209. \issue{DECLS-AND-DOC}
  3210. \label Syntax::
  3211. \issue{LOCALLY-TOP-LEVEL:SPECIAL-FORM}
  3212. \DefspecWithValues locally
  3213. {\starparam{declaration} \starparam{form}}
  3214. {\starparam{result}}
  3215. \endissue{LOCALLY-TOP-LEVEL:SPECIAL-FORM}
  3216. \label Arguments and Values::
  3217. \param{Declaration}---a \misc{declare} \term{expression}; \noeval.
  3218. \param{forms}---an \term{implicit progn}.
  3219. \issue{RETURN-VALUES-UNSPECIFIED:SPECIFY}
  3220. \param{results}---the \term{values} of the \param{forms}.
  3221. \endissue{RETURN-VALUES-UNSPECIFIED:SPECIFY}
  3222. \label Description::
  3223. %% 9.1.0 10
  3224. Sequentially evaluates a body of \param{forms}
  3225. in a \term{lexical environment} where the given \param{declarations} have effect.
  3226. \label Examples::
  3227. \code
  3228. (defun sample-function (y) ;this y is regarded as special
  3229. (declare (special y))
  3230. (let ((y t)) ;this y is regarded as lexical
  3231. (list y
  3232. (locally (declare (special y))
  3233. ;; this next y is regarded as special
  3234. y))))
  3235. \EV SAMPLE-FUNCTION
  3236. (sample-function nil) \EV (T NIL)
  3237. (setq x '(1 2 3) y '(4 . 5)) \EV (4 . 5)
  3238. ;;; The following declarations are not notably useful in specific.
  3239. ;;; They just offer a sample of valid declaration syntax using LOCALLY.
  3240. (locally (declare (inline floor) (notinline car cdr))
  3241. (declare (optimize space))
  3242. (floor (car x) (cdr y))) \EV 0, 1
  3243. \endcode
  3244. \issue{LOCALLY-TOP-LEVEL:SPECIAL-FORM}
  3245. %Barmar: Say what the example does.
  3246. %KMP: I added some comments. OK?
  3247. \code
  3248. ;;; This example shows a definition of a function that has a particular set
  3249. ;;; of OPTIMIZE settings made locally to that definition.
  3250. (locally (declare (optimize (safety 3) (space 3) (speed 0)))
  3251. (defun frob (w x y &optional (z (foo x y)))
  3252. (mumble x y z w)))
  3253. \EV FROB
  3254. ;;; This is like the previous example, except that the optimize settings
  3255. ;;; remain in effect for subsequent definitions in the same compilation unit.
  3256. (declaim (optimize (safety 3) (space 3) (speed 0)))
  3257. (defun frob (w x y &optional (z (foo x y)))
  3258. (mumble x y z w))
  3259. \EV FROB
  3260. \endcode
  3261. \endissue{LOCALLY-TOP-LEVEL:SPECIAL-FORM}
  3262. \label Side Effects:\None.
  3263. \label Affected By:\None.
  3264. \label Exceptional Situations:\None.
  3265. \label See Also::
  3266. \misc{declare}
  3267. \label Notes::
  3268. The \declref{special} declaration may be used with \specref{locally}
  3269. to affect references to, rather than \term{bindings} of, \term{variables}.
  3270. %Barrett: So what?
  3271. \issue{LOCALLY-TOP-LEVEL:SPECIAL-FORM}
  3272. If a \specref{locally} \term{form} is a \term{top level form}, the body \param{forms}
  3273. are also processed as \term{top level forms}. \Seesection\FileCompilation.
  3274. \endissue{LOCALLY-TOP-LEVEL:SPECIAL-FORM}
  3275. \endissue{DECLS-AND-DOC}
  3276. \endcom
  3277. %%% ========== THE
  3278. \begincom{the}\ftype{Special Operator}
  3279. \label Syntax::
  3280. \DefspecWithValues the {value-type form} {\starparam{result}}
  3281. \label Arguments and Values::
  3282. \param{value-type}---a \term{type specifier}; \noeval.
  3283. \param{form}---a \term{form}; \eval.
  3284. \issue{THE-VALUES:RETURN-NUMBER-RECEIVED}
  3285. %% 7.9.2 19
  3286. \param{results}---the \term{values} resulting from the \term{evaluation} of \param{form}.
  3287. These \term{values} must conform to the \term{type} supplied by \param{value-type};
  3288. see below.
  3289. \endissue{THE-VALUES:RETURN-NUMBER-RECEIVED}
  3290. \label Description::
  3291. %% 9.3.0 2
  3292. \specref{the} specifies that the \term{values}\meaning{1a} returned by \param{form}
  3293. are of the \term{types} specified by \param{value-type}.
  3294. The consequences are undefined if any \param{result}
  3295. is not of the declared type.
  3296. \issue{THE-AMBIGUITY:FOR-DECLARATION}
  3297. %% This text has been removed per Moon #19 (first public review). -kmp 8-May-93
  3298. % %!!! Barmar: If this is true, the THE form is equivalent to the form argument.
  3299. % \param{Value-type} can be any valid \term{type specifier}.
  3300. % In the case that \param{form} returns one
  3301. % value and \param{value-type} is not a
  3302. % \declref{values} \term{type specifier},
  3303. %
  3304. % \code
  3305. % (the type exp)
  3306. % \EQ
  3307. % (let ((#:g0001 exp))
  3308. % (declare (type type #:g0001))
  3309. % #:g0001)
  3310. % \endcode
  3311. \endissue{THE-AMBIGUITY:FOR-DECLARATION}
  3312. \issue{JUN90-TRIVIAL-ISSUES:27}
  3313. \issue{THE-VALUES:RETURN-NUMBER-RECEIVED}
  3314. It is permissible for \param{form} to \term{yield} a different number of \term{values}
  3315. than are specified by \param{value-type}, provided that the values
  3316. for which \param{types} are declared are indeed of those \term{types}.
  3317. Missing values are treated as \nil\ for the purposes of checking their \term{types}.
  3318. Regardless of number of \term{values} declared by \param{value-type},
  3319. the number of \term{values} returned by \thespecform{the} is the same as
  3320. the number of \term{values} returned by \param{form}.
  3321. \endissue{THE-VALUES:RETURN-NUMBER-RECEIVED}
  3322. \endissue{JUN90-TRIVIAL-ISSUES:27}
  3323. \label Examples::
  3324. \issue{THE-VALUES:RETURN-NUMBER-RECEIVED}
  3325. \code
  3326. (the symbol (car (list (gensym)))) \EV #:G9876
  3327. (the fixnum (+ 5 7)) \EV 12
  3328. (the (values) (truncate 3.2 2)) \EV 1, 1.2
  3329. (the integer (truncate 3.2 2)) \EV 1, 1.2
  3330. (the (values integer) (truncate 3.2 2)) \EV 1, 1.2
  3331. (the (values integer float) (truncate 3.2 2)) \EV 1, 1.2
  3332. (the (values integer float symbol) (truncate 3.2 2)) \EV 1, 1.2
  3333. (the (values integer float symbol t null list)
  3334. (truncate 3.2 2)) \EV 1, 1.2
  3335. (let ((i 100))
  3336. (declare (fixnum i))
  3337. (the fixnum (1+ i))) \EV 101
  3338. (let* ((x (list 'a 'b 'c))
  3339. (y 5))
  3340. (setf (the fixnum (car x)) y)
  3341. x) \EV (5 B C)
  3342. \endcode
  3343. \endissue{THE-VALUES:RETURN-NUMBER-RECEIVED}
  3344. \label Affected By:\None.
  3345. \label Exceptional Situations::
  3346. The consequences are undefined if
  3347. the \term{values} \term{yielded} by the \param{form}
  3348. are not of the \term{type} specified by \param{value-type}.
  3349. \label See Also::
  3350. \declref{values}
  3351. \label Notes::
  3352. The \declref{values} \term{type specifier} can be used to indicate the types
  3353. of \term{multiple values}:
  3354. \code
  3355. (the (values integer integer) (floor x y))
  3356. (the (values string t)
  3357. (gethash the-key the-string-table))
  3358. \endcode
  3359. \macref{setf} can be used with \specref{the} type declarations.
  3360. In this case the declaration is transferred to the form that
  3361. specifies the new value. The resulting \macref{setf} \term{form}
  3362. is then analyzed.
  3363. \endcom
  3364. %-------------------- Introspection --------------------
  3365. %%% ========== SPECIAL-OPERATOR-P
  3366. \begincom{special-operator-p}\ftype{Function}
  3367. \issue{SPECIAL-FORM-P-MISNOMER:RENAME}
  3368. \label Syntax::
  3369. \DefunWithValues special-operator-p {symbol} {generalized-boolean}
  3370. \label Arguments and Values::
  3371. \param{symbol}---a \term{symbol}.
  3372. \param{generalized-boolean}---a \term{generalized boolean}.
  3373. \label Description::
  3374. %% 7.1.1 22
  3375. \Predicate{symbol}{a \term{special operator}}
  3376. \label Examples::
  3377. \code
  3378. (special-operator-p 'if) \EV \term{true}
  3379. (special-operator-p 'car) \EV \term{false}
  3380. (special-operator-p 'one) \EV \term{false}
  3381. \endcode
  3382. \label Side Effects:\None.
  3383. \label Affected By:\None.
  3384. \label Exceptional Situations::
  3385. Should signal \typeref{type-error} if its argument is not a \term{symbol}.
  3386. \label See Also:\None.
  3387. \label Notes::
  3388. Historically, this function was called \f{special-form-p}. The name was
  3389. finally declared a misnomer and changed, since it returned true for
  3390. \term{special operators}, not \term{special forms}.
  3391. %This is beyond the scope of the language. -kmp 26-Dec-90
  3392. % A returned \term{non-nil} value is typically a \term{function}
  3393. % of \term{implementation-dependent} nature that can be used to
  3394. % interpret (evaluate) the \term{special form}.
  3395. \endissue{SPECIAL-FORM-P-MISNOMER:RENAME}
  3396. \endcom
  3397. %%% ========== CONSTANTP
  3398. \begincom{constantp}\ftype{Function}
  3399. \issue{CONSTANTP-DEFINITION:INTENTIONAL}
  3400. \issue{CONSTANTP-ENVIRONMENT:ADD-ARG}
  3401. \label Syntax::
  3402. \DefunWithValues constantp {form {\opt} environment} {generalized-boolean}
  3403. \label Arguments and Values::
  3404. \param{form}---a \term{form}.
  3405. \param{environment}---an \term{environment} \term{object}.
  3406. \Default{\nil}
  3407. \param{generalized-boolean}---a \term{generalized boolean}.
  3408. \label Description::
  3409. %% 20.1.0 14
  3410. %% 20.1.0 15
  3411. Returns \term{true} if \param{form} can be determined
  3412. by the \term{implementation} to be a \term{constant form}
  3413. in the indicated \param{environment};
  3414. otherwise, it returns \term{false} indicating either
  3415. that the \term{form} is not a \term{constant form}
  3416. or that it cannot be determined whether or not \term{form} is a \term{constant form}.
  3417. The following kinds of \term{forms} are considered \term{constant forms}:
  3418. \beginlist
  3419. \itemitem{\bull}
  3420. % This is the wrong term. --sjl 5 Mar 92
  3421. % \term{Constant objects}
  3422. \term{Self-evaluating objects}
  3423. (such as \term{numbers},
  3424. \term{characters},
  3425. and the various kinds of \term{arrays})
  3426. are always considered \term{constant forms}
  3427. and must be recognized as such by \funref{constantp}.
  3428. \itemitem{\bull}
  3429. \term{Constant variables}, such as \term{keywords},
  3430. symbols defined by \clisp\ as constant (such as \nil, \t, and \conref{pi}),
  3431. and symbols declared as constant by the user in the indicated \param{environment}
  3432. using \macref{defconstant}
  3433. are always considered \term{constant forms}
  3434. and must be recognized as such by \funref{constantp}.
  3435. \itemitem{\bull}
  3436. \specref{quote} \term{forms} are always considered \term{constant forms}
  3437. and must be recognized as such by \funref{constantp}.
  3438. \itemitem{\bull}
  3439. An \term{implementation} is permitted, but not required, to detect
  3440. additional \term{constant forms}. If it does, it is also permitted,
  3441. but not required, to make use of information in the \param{environment}.
  3442. Examples of \term{constant forms} for which \funref{constantp} might
  3443. or might not return \term{true} are:
  3444. \f{(sqrt pi)},
  3445. \f{(+ 3 2)},
  3446. \f{(length '(a b c))},
  3447. and
  3448. \f{(let ((x 7)) (zerop x))}.
  3449. \endlist
  3450. If an \term{implementation} chooses to make use of the \param{environment}
  3451. information, such actions as expanding \term{macros} or performing function
  3452. inlining are permitted to be used, but not required;
  3453. however, expanding \term{compiler macros} is not permitted.
  3454. \label Examples::
  3455. \code
  3456. (constantp 1) \EV \term{true}
  3457. (constantp 'temp) \EV \term{false}
  3458. (constantp ''temp)) \EV \term{true}
  3459. (defconstant this-is-a-constant 'never-changing) \EV THIS-IS-A-CONSTANT
  3460. (constantp 'this-is-a-constant) \EV \term{true}
  3461. (constantp "temp") \EV \term{true}
  3462. (setq a 6) \EV 6
  3463. (constantp a) \EV \term{true}
  3464. (constantp '(sin pi)) \EV \term{implementation-dependent}
  3465. (constantp '(car '(x))) \EV \term{implementation-dependent}
  3466. (constantp '(eql x x)) \EV \term{implementation-dependent}
  3467. (constantp '(typep x 'nil)) \EV \term{implementation-dependent}
  3468. (constantp '(typep x 't)) \EV \term{implementation-dependent}
  3469. (constantp '(values this-is-a-constant)) \EV \term{implementation-dependent}
  3470. (constantp '(values 'x 'y)) \EV \term{implementation-dependent}
  3471. (constantp '(let ((a '(a b c))) (+ (length a) 6))) \EV \term{implementation-dependent}
  3472. \endcode
  3473. \label Side Effects:\None!
  3474. \label Affected By::
  3475. The state of the global environment (\eg which \term{symbols} have been
  3476. declared to be the \term{names} of \term{constant variables}).
  3477. \label Exceptional Situations:\None!
  3478. \label See Also::
  3479. \macref{defconstant}
  3480. \label Notes:\None.
  3481. \endissue{CONSTANTP-ENVIRONMENT:ADD-ARG}
  3482. \endissue{CONSTANTP-DEFINITION:INTENTIONAL}
  3483. \endcom
  3484. \issue{SYNTACTIC-ENVIRONMENT-ACCESS:RETRACTED-MAR91}
  3485. % The following functions were removed due to the retraction of
  3486. % issue SYNTACTIC-ENVIRONMENT-ACCESS by X3J13 at the Mar 91 meeting.
  3487. % AUGMENT-ENVIRONMENT
  3488. % DECLARATION-INFORMATION
  3489. % DEFINE-DECLARATION
  3490. % ENCLOSE
  3491. % FUNCTION-INFORMATION
  3492. % PARSE-MACRO
  3493. % VARIABLE-INFORMATION
  3494. \endissue{SYNTACTIC-ENVIRONMENT-ACCESS:RETRACTED-MAR91}