My various dotfiles

chap-11.texi 89KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708
  1. @node Packages, Numbers (Numbers), Symbols, Top
  2. @chapter Packages
  3. @menu
  4. * Package Concepts::
  5. * Packages Dictionary::
  6. @end menu
  7. @node Package Concepts, Packages Dictionary, Packages, Packages
  8. @section Package Concepts
  9. @c including concept-packages
  10. @menu
  11. * Introduction to Packages::
  12. * Standardized Packages::
  13. @end menu
  14. @node Introduction to Packages, Standardized Packages, Package Concepts, Package Concepts
  15. @subsection Introduction to Packages
  16. A @i{package}
  17. @IGindex{package}
  18. establishes a mapping from names to @i{symbols}.
  19. At any given time, one @i{package} is current.
  20. The @i{current package}
  21. @IGindex{current package}
  22. is the one that is the @i{value} of @b{*package*}.
  23. When using the @i{Lisp reader},
  24. it is possible to refer to @i{symbols} in @i{packages}
  25. other than the current one through the use of @i{package prefixes} in the
  26. printed representation of the @i{symbol}.
  27. Figure 11--1 lists some @i{defined names} that are applicable
  28. to @i{packages}.
  29. Where an @i{operator}
  30. takes an argument that is either a @i{symbol} or a @i{list}
  31. of @i{symbols},
  32. an argument of @b{nil} is treated as an empty @i{list} of @i{symbols}.
  33. Any @i{package} argument may be either a @i{string}, a @i{symbol}, or
  34. a @i{package}. If a @i{symbol} is supplied, its name will be used
  35. as the @i{package} name.
  36. @group
  37. @noindent
  38. @w{ *modules* import provide }
  39. @w{ *package* in-package rename-package }
  40. @w{ defpackage intern require }
  41. @w{ do-all-symbols list-all-packages shadow }
  42. @w{ do-external-symbols make-package shadowing-import }
  43. @w{ do-symbols package-name unexport }
  44. @w{ export package-nicknames unintern }
  45. @w{ find-all-symbols package-shadowing-symbols unuse-package }
  46. @w{ find-package package-use-list use-package }
  47. @w{ find-symbol package-used-by-list }
  48. @noindent
  49. @w{ Figure 11--1: Some Defined Names related to Packages }
  50. @end group
  51. @menu
  52. * Package Names and Nicknames::
  53. * Symbols in a Package::
  54. * Internal and External Symbols::
  55. * Package Inheritance::
  56. * Accessibility of Symbols in a Package::
  57. * Locating a Symbol in a Package::
  58. * Prevention of Name Conflicts in Packages::
  59. @end menu
  60. @node Package Names and Nicknames, Symbols in a Package, Introduction to Packages, Introduction to Packages
  61. @subsubsection Package Names and Nicknames
  62. Each @i{package} has a @i{name} (a @i{string}) and perhaps some @i{nicknames}
  63. (also @i{strings}).
  64. These are assigned when the @i{package} is created and can be changed later.
  65. There is a single namespace for @i{packages}.
  66. The @i{function} @b{find-package} translates a package
  67. @i{name} or @i{nickname} into the associated @i{package}.
  68. The @i{function} @b{package-name} returns the @i{name} of a @i{package}.
  69. The @i{function} @b{package-nicknames} returns
  70. a @i{list} of all @i{nicknames} for a @i{package}.
  71. @b{rename-package} removes a @i{package}'s
  72. current @i{name} and @i{nicknames} and replaces them with new ones
  73. specified by the caller.
  74. @node Symbols in a Package, Internal and External Symbols, Package Names and Nicknames, Introduction to Packages
  75. @subsubsection Symbols in a Package
  76. @node Internal and External Symbols, Package Inheritance, Symbols in a Package, Introduction to Packages
  77. @subsubsection Internal and External Symbols
  78. The mappings in a @i{package} are divided into two classes, external and internal.
  79. The @i{symbols} targeted by these different mappings
  80. are called @i{external symbols} and @i{internal symbols}
  81. @IGindex{internal symbol}
  82. of the
  83. @i{package}. Within a @i{package}, a name refers to one
  84. @i{symbol} or to none; if it does refer
  85. to a @i{symbol}, then it is either external or internal in that
  86. @i{package}, but not both.
  87. @i{External symbols}
  88. @IGindex{external symbol}
  89. are part of the package's public interface to other @i{packages}.
  90. @i{Symbols} become @i{external symbols} of a given
  91. @i{package} if they have been @i{exported} from that @i{package}.
  92. A @i{symbol} has the same @i{name} no matter what @i{package}
  93. it is @i{present} in, but it might be an @i{external symbol} of some @i{packages}
  94. and an @i{internal symbol} of others.
  95. @node Package Inheritance, Accessibility of Symbols in a Package, Internal and External Symbols, Introduction to Packages
  96. @subsubsection Package Inheritance
  97. @i{Packages} can be built up in layers. From one point of view,
  98. a @i{package} is a single collection
  99. of mappings from @i{strings} into @i{internal symbols} and
  100. @i{external symbols}.
  101. However, some of these mappings might be established within the @i{package}
  102. itself, while other mappings are inherited from other @i{packages}
  103. via @b{use-package}.
  104. A @i{symbol} is said to be @i{present}
  105. @IGindex{present}
  106. in a @i{package}
  107. if the mapping is in the @i{package} itself and is
  108. not inherited from somewhere else.
  109. There is no way to inherit the @i{internal symbols} of another @i{package};
  110. to refer to an @i{internal symbol} using the @i{Lisp reader},
  111. a @i{package} containing the @i{symbol}
  112. must be made to be the @i{current package},
  113. a @i{package prefix} must be used,
  114. or the @i{symbol} must be @i{imported} into the @i{current package}.
  115. @node Accessibility of Symbols in a Package, Locating a Symbol in a Package, Package Inheritance, Introduction to Packages
  116. @subsubsection Accessibility of Symbols in a Package
  117. A @i{symbol} becomes @i{accessible}
  118. @IGindex{accessible}
  119. in a @i{package}
  120. if that is its @i{home package} when it is created,
  121. or if it is @i{imported} into that @i{package},
  122. or by inheritance via @b{use-package}.
  123. If a @i{symbol} is @i{accessible} in a @i{package},
  124. it can be referred to when using the @i{Lisp reader}
  125. without a @i{package prefix} when that @i{package} is the @i{current package},
  126. regardless of whether it is @i{present} or inherited.
  127. @i{Symbols} from one @i{package} can be made @i{accessible}
  128. in another @i{package} in two ways.
  129. @table @asis
  130. @item --
  131. Any individual @i{symbol} can be added to a @i{package} by use
  132. of @b{import}. After the call to @b{import} the
  133. @i{symbol} is @i{present} in the importing @i{package}.
  134. The status of the @i{symbol} in the @i{package}
  135. it came from (if any) is unchanged, and the @i{home package} for
  136. this @i{symbol} is unchanged.
  137. Once @i{imported}, a @i{symbol} is @i{present} in the
  138. importing @i{package}
  139. and can be removed only by calling @b{unintern}.
  140. A @i{symbol} is @i{shadowed}_3 by another @i{symbol}
  141. in some @i{package} if the first @i{symbol} would be @i{accessible}
  142. by inheritance if not for the presence of the second @i{symbol}.
  143. See @b{shadowing-import}.
  144. @item --
  145. The second mechanism for making @i{symbols} from one @i{package}
  146. @i{accessible} in another is provided by @b{use-package}.
  147. All of the @i{external symbols} of the used @i{package} are inherited
  148. by the using @i{package}.
  149. The @i{function} @b{unuse-package} undoes the effects of a previous @b{use-package}.
  150. @end table
  151. @node Locating a Symbol in a Package, Prevention of Name Conflicts in Packages, Accessibility of Symbols in a Package, Introduction to Packages
  152. @subsubsection Locating a Symbol in a Package
  153. When a @i{symbol} is to be located in a given @i{package}
  154. the following occurs:
  155. @table @asis
  156. @item --
  157. The @i{external symbols} and @i{internal symbols} of the
  158. @i{package} are searched for the @i{symbol}.
  159. @item --
  160. The @i{external symbols} of the used @i{packages} are
  161. searched
  162. in some unspecified order. The
  163. order does not matter; see the rules for handling name
  164. conflicts listed below.
  165. @end table
  166. @node Prevention of Name Conflicts in Packages, , Locating a Symbol in a Package, Introduction to Packages
  167. @subsubsection Prevention of Name Conflicts in Packages
  168. Within one @i{package}, any particular name can refer to at most one
  169. @i{symbol}. A name conflict is said to occur when there would be more than
  170. one candidate @i{symbol}. Any time a name conflict is about to occur,
  171. a @i{correctable} @i{error} is signaled.
  172. The following rules apply to name conflicts:
  173. @table @asis
  174. @item --
  175. Name conflicts are detected when they become possible, that is, when the
  176. package structure is altered. Name
  177. conflicts are not checked during every name lookup.
  178. @item --
  179. If the @i{same} @i{symbol} is @i{accessible} to a @i{package}
  180. through more than one path, there is no name conflict.
  181. A @i{symbol} cannot conflict with itself.
  182. Name conflicts occur only between @i{distinct} @i{symbols} with
  183. the same name (under @b{string=}).
  184. @item --
  185. Every @i{package} has a list of shadowing @i{symbols}.
  186. A shadowing @i{symbol} takes precedence over any other @i{symbol} of
  187. the same name that would otherwise be @i{accessible} in the @i{package}.
  188. A name conflict involving a shadowing symbol is always resolved in favor of
  189. the shadowing @i{symbol}, without signaling an error (except for one
  190. exception involving @b{import}).
  191. See @b{shadow} and @b{shadowing-import}.
  192. @item --
  193. The functions @b{use-package}, @b{import}, and
  194. @b{export} check for name conflicts.
  195. @item --
  196. @b{shadow} and @b{shadowing-import}
  197. never signal a name-conflict error.
  198. @item --
  199. @b{unuse-package} and @b{unexport}
  200. do not need to do any name-conflict checking.
  201. @b{unintern} does name-conflict checking only when a @i{symbol}
  202. being @i{uninterned} is a @i{shadowing symbol}
  203. @IGindex{shadowing symbol}
  204. .
  205. @item --
  206. Giving a shadowing symbol to @b{unintern}
  207. can uncover a name conflict that had
  208. previously been resolved by the shadowing.
  209. @item --
  210. Package functions signal name-conflict errors of @i{type} @b{package-error} before making any
  211. change to the package structure. When multiple changes are to be made,
  212. it is
  213. permissible for the implementation to process each change separately.
  214. For example, when @b{export} is given a
  215. @i{list} of
  216. @i{symbols},
  217. aborting from a name
  218. conflict caused by the second @i{symbol}
  219. in the @i{list} might still export the
  220. first @i{symbol} in the @i{list}.
  221. However, a name-conflict error caused by @b{export}
  222. of a single @i{symbol} will be signaled before
  223. that @i{symbol}'s @i{accessibility} in any @i{package} is changed.
  224. @item --
  225. Continuing from a name-conflict error must offer the user a chance to
  226. resolve the name conflict in favor of either of the candidates. The
  227. @i{package}
  228. structure should be altered to reflect the resolution of the
  229. name conflict, via @b{shadowing-import},
  230. @b{unintern},
  231. or @b{unexport}.
  232. @item --
  233. A name conflict in @b{use-package} between a @i{symbol}
  234. @i{present} in the using @i{package} and an @i{external symbol} of the used
  235. @i{package} is resolved in favor of the first @i{symbol} by making it a
  236. shadowing @i{symbol}, or in favor of the second @i{symbol} by uninterning
  237. the first @i{symbol} from the using @i{package}.
  238. @item --
  239. A name conflict in @b{export} or @b{unintern}
  240. due to a @i{package}'s inheriting two @i{distinct} @i{symbols}
  241. with the @i{same} @i{name} (under @b{string=})
  242. from two other @i{packages} can be resolved in
  243. favor of either @i{symbol} by importing it into the using
  244. @i{package} and making it a @i{shadowing symbol}
  245. @IGindex{shadowing symbol}
  246. ,
  247. just as with @b{use-package}.
  248. @end table
  249. @node Standardized Packages, , Introduction to Packages, Package Concepts
  250. @subsection Standardized Packages
  251. This section describes the @i{packages} that are available
  252. in every @i{conforming implementation}. A summary of the
  253. @i{names} and @i{nicknames} of those @i{standardized} @i{packages}
  254. is given in Figure 11--2.
  255. @group
  256. @noindent
  257. @w{ Name Nicknames }
  258. @w{ @t{COMMON-LISP} @t{CL} }
  259. @w{ @t{COMMON-LISP-USER} @t{CL-USER} }
  260. @w{ @t{KEYWORD} @i{none} }
  261. @noindent
  262. @w{ Figure 11--2: Standardized Package Names}
  263. @end group
  264. @menu
  265. * The COMMON-LISP Package::
  266. * Constraints on the COMMON-LISP Package for Conforming Implementations::
  267. * Constraints on the COMMON-LISP Package for Conforming Programs::
  268. * Some Exceptions to Constraints on the COMMON-LISP Package for Conforming Programs::
  269. * The COMMON-LISP-USER Package::
  270. * The KEYWORD Package::
  271. * Interning a Symbol in the KEYWORD Package::
  272. * Notes about The KEYWORD Package::
  273. * Implementation-Defined Packages::
  274. @end menu
  275. @node The COMMON-LISP Package, Constraints on the COMMON-LISP Package for Conforming Implementations, Standardized Packages, Standardized Packages
  276. @subsubsection The COMMON-LISP Package
  277. @IPindex{common-lisp}
  278. @IPindex{cl}
  279. The @t{COMMON-LISP} @i{package} contains the primitives of the @r{Common Lisp} system as
  280. defined by this specification. Its @i{external} @i{symbols} include
  281. all of the @i{defined names} (except for @i{defined names} in
  282. the @t{KEYWORD} @i{package}) that are present in the @r{Common Lisp} system,
  283. such as @b{car}, @b{cdr}, @b{*package*}, etc.
  284. The @t{COMMON-LISP} @i{package} has the @i{nickname} @t{CL}.
  285. The @t{COMMON-LISP} @i{package} has as @i{external} @i{symbols} those
  286. symbols enumerated in the figures in @ref{Symbols in the COMMON-LISP Package}, and no others.
  287. These @i{external} @i{symbols} are @i{present} in the @t{COMMON-LISP} @i{package}
  288. but their @i{home package} need not be the @t{COMMON-LISP} @i{package}.
  289. For example, the symbol @t{HELP} cannot be an @i{external symbol} of
  290. the @t{COMMON-LISP} @i{package} because it is not mentioned in @ref{Symbols in the COMMON-LISP Package}.
  291. In contrast, the @i{symbol} @b{variable}
  292. must be an @i{external symbol} of the @t{COMMON-LISP} @i{package}
  293. even though it has no definition
  294. because it is listed in that section
  295. (to support its use as a valid second @i{argument} to the @i{function} @b{documentation}).
  296. The @t{COMMON-LISP} @i{package} can have additional @i{internal symbols}.
  297. @node Constraints on the COMMON-LISP Package for Conforming Implementations, Constraints on the COMMON-LISP Package for Conforming Programs, The COMMON-LISP Package, Standardized Packages
  298. @subsubsection Constraints on the COMMON-LISP Package for Conforming Implementations
  299. In a @i{conforming implementation},
  300. an @i{external} @i{symbol} of the @t{COMMON-LISP} @i{package} can have
  301. a @i{function}, @i{macro}, or @i{special operator} definition,
  302. a @i{global variable} definition
  303. (or other status as a @i{dynamic variable}
  304. due to a @b{special} @i{proclamation}),
  305. or a @i{type} definition
  306. only if explicitly permitted in this standard.
  307. For example,
  308. @b{fboundp} @i{yields} @i{false}
  309. for any @i{external symbol} of the @t{COMMON-LISP} @i{package}
  310. that is not the @i{name} of a @i{standardized}
  311. @i{function}, @i{macro} or @i{special operator},
  312. and
  313. @b{boundp} returns @i{false}
  314. for any @i{external symbol} of the @t{COMMON-LISP} @i{package}
  315. that is not the @i{name} of a @i{standardized} @i{global variable}.
  316. It also follows that
  317. @i{conforming programs} can use @i{external symbols} of the @t{COMMON-LISP} @i{package}
  318. as the @i{names} of local @i{lexical variables}
  319. with confidence that those @i{names} have not been @i{proclaimed} @b{special}
  320. by the @i{implementation}
  321. unless those @i{symbols} are
  322. @i{names} of @i{standardized} @i{global variables}.
  323. A @i{conforming implementation} must not place any @i{property} on
  324. an @i{external symbol} of the @t{COMMON-LISP} @i{package} using a @i{property indicator}
  325. that is either an @i{external symbol} of any @i{standardized} @i{package}
  326. or a @i{symbol} that is otherwise @i{accessible} in the @t{COMMON-LISP-USER} @i{package}.
  327. @node Constraints on the COMMON-LISP Package for Conforming Programs, Some Exceptions to Constraints on the COMMON-LISP Package for Conforming Programs, Constraints on the COMMON-LISP Package for Conforming Implementations, Standardized Packages
  328. @subsubsection Constraints on the COMMON-LISP Package for Conforming Programs
  329. @ITindex{redefinition}
  330. Except where explicitly allowed, the consequences are undefined if any
  331. of the following actions are performed on an @i{external symbol}
  332. of the @t{COMMON-LISP} @i{package}:
  333. @table @asis
  334. @item 1.
  335. @i{Binding} or altering its value (lexically or dynamically).
  336. (Some exceptions are noted below.)
  337. @item 2.
  338. Defining,
  339. undefining,
  340. or @i{binding} it as a @i{function}.
  341. (Some exceptions are noted below.)
  342. @item 3.
  343. Defining,
  344. undefining,
  345. or @i{binding} it as a @i{macro}
  346. or @i{compiler macro}.
  347. (Some exceptions are noted below.)
  348. @item 4.
  349. Defining it as a @i{type specifier}
  350. (via @b{defstruct},
  351. @b{defclass},
  352. @b{deftype},
  353. @b{define-condition}).
  354. @item 5.
  355. Defining it as a structure (via @b{defstruct}).
  356. @item 6.
  357. Defining it as a @i{declaration}
  358. with a @b{declaration} @i{proclamation}.
  359. @item 7.
  360. Defining it as a @i{symbol macro}.
  361. @item 8.
  362. Altering its @i{home package}.
  363. @item 9.
  364. Tracing it (via @b{trace}).
  365. @item 10.
  366. Declaring or proclaiming it
  367. @b{special}
  368. (via @b{declare},
  369. @b{declaim},
  370. or @b{proclaim}).
  371. @item 11.
  372. Declaring or proclaiming its @b{type} or @b{ftype}
  373. (via @b{declare},
  374. @b{declaim},
  375. or @b{proclaim}).
  376. (Some exceptions are noted below.)
  377. @item 12.
  378. Removing it from the @t{COMMON-LISP} @i{package}.
  379. @item 13.
  380. Defining a @i{setf expander} for it
  381. (via @b{defsetf} or @b{define-setf-method}).
  382. @item 14.
  383. Defining, undefining, or binding its @i{setf function name}.
  384. @item 15.
  385. Defining it as a @i{method combination} type
  386. (via @b{define-method-combination}).
  387. @item 16.
  388. Using it as the class-name argument
  389. to @b{setf} of @b{find-class}.
  390. @item 17.
  391. Binding it as a @i{catch tag}.
  392. @item 18.
  393. Binding it as a @i{restart} @i{name}.
  394. @item 19.
  395. Defining a @i{method}
  396. for a @i{standardized} @i{generic function}
  397. which is @i{applicable} when all of the @i{arguments}
  398. are @i{direct instances} of @i{standardized} @i{classes}.
  399. @end table
  400. @node Some Exceptions to Constraints on the COMMON-LISP Package for Conforming Programs, The COMMON-LISP-USER Package, Constraints on the COMMON-LISP Package for Conforming Programs, Standardized Packages
  401. @subsubsection Some Exceptions to Constraints on the COMMON-LISP Package for Conforming Programs
  402. If an @i{external symbol} of the @t{COMMON-LISP} @i{package}
  403. is not globally defined as a @i{standardized} @i{dynamic variable}
  404. or @i{constant variable},
  405. it is allowed to lexically @i{bind} it
  406. and to declare the @b{type} of that @i{binding},
  407. and
  408. it is allowed to locally @i{establish} it as a @i{symbol macro}
  409. (@i{e.g.}, with @b{symbol-macrolet}).
  410. Unless explicitly specified otherwise,
  411. if an @i{external symbol} of the @t{COMMON-LISP} @i{package}
  412. is globally defined as a @i{standardized} @i{dynamic variable},
  413. it is permitted to @i{bind} or @i{assign} that @i{dynamic variable}
  414. provided that the ``Value Type'' constraints on the @i{dynamic variable}
  415. are maintained, and that the new @i{value} of the @i{variable}
  416. is consistent with the stated purpose of the @i{variable}.
  417. If an @i{external symbol} of the @t{COMMON-LISP} @i{package} is not defined
  418. as a @i{standardized} @i{function}, @i{macro}, or @i{special operator},
  419. it is allowed to lexically @i{bind} it as a @i{function} (@i{e.g.}, with @b{flet}),
  420. to declare the @b{ftype} of that @i{binding},
  421. and
  422. (in @i{implementations} which provide the ability to do so)
  423. to @b{trace} that @i{binding}.
  424. If an @i{external symbol} of the @t{COMMON-LISP} @i{package} is not defined
  425. as a @i{standardized} @i{function}, @i{macro}, or @i{special operator},
  426. it is allowed to lexically @i{bind} it as a @i{macro} (@i{e.g.}, with @b{macrolet}).
  427. If an @i{external symbol} of the @t{COMMON-LISP} @i{package} is not defined
  428. as a @i{standardized} @i{function}, @i{macro}, or @i{special operator},
  429. it is allowed to lexically @i{bind} its @i{setf function name}
  430. as a @i{function},
  431. and to declare the @b{ftype} of that @i{binding}.
  432. @node The COMMON-LISP-USER Package, The KEYWORD Package, Some Exceptions to Constraints on the COMMON-LISP Package for Conforming Programs, Standardized Packages
  433. @subsubsection The COMMON-LISP-USER Package
  434. @IPindex{common-lisp-user}
  435. @IPindex{cl-user}
  436. The @t{COMMON-LISP-USER} @i{package} is the @i{current package} when
  437. a @r{Common Lisp} system starts up. This @i{package} @i{uses} the @t{COMMON-LISP} @i{package}.
  438. The @t{COMMON-LISP-USER} @i{package} has the @i{nickname} @t{CL-USER}.
  439. The @t{COMMON-LISP-USER} @i{package} can have additional @i{symbols} @i{interned} within it;
  440. it can @i{use} other @i{implementation-defined} @i{packages}.
  441. @node The KEYWORD Package, Interning a Symbol in the KEYWORD Package, The COMMON-LISP-USER Package, Standardized Packages
  442. @subsubsection The KEYWORD Package
  443. @IPindex{keyword}
  444. The @t{KEYWORD} @i{package} contains @i{symbols}, called @i{keywords}_1,
  445. that are typically used as special markers in @i{programs}
  446. and their associated data @i{expressions}_1.
  447. @i{Symbol} @i{tokens} that start with a @i{package marker}
  448. are parsed by the @i{Lisp reader} as @i{symbols}
  449. in the @t{KEYWORD} @i{package}; see @ref{Symbols as Tokens}.
  450. This makes it notationally convenient to use @i{keywords}
  451. when communicating between programs in different @i{packages}.
  452. For example, the mechanism for passing @i{keyword parameters} in a @i{call} uses
  453. @i{keywords}_1 to name the corresponding @i{arguments};
  454. see @ref{Ordinary Lambda Lists}.
  455. @i{Symbols} in the @t{KEYWORD} @i{package} are, by definition, of @i{type} @b{keyword}.
  456. @node Interning a Symbol in the KEYWORD Package, Notes about The KEYWORD Package, The KEYWORD Package, Standardized Packages
  457. @subsubsection Interning a Symbol in the KEYWORD Package
  458. The @t{KEYWORD} @i{package} is treated differently than other @i{packages}
  459. in that special actions are taken when a @i{symbol} is @i{interned} in it.
  460. In particular, when a @i{symbol} is @i{interned} in the @t{KEYWORD} @i{package},
  461. it is automatically made to be an @i{external symbol}
  462. and is automatically made to be a @i{constant variable} with itself as a @i{value}.
  463. @node Notes about The KEYWORD Package, Implementation-Defined Packages, Interning a Symbol in the KEYWORD Package, Standardized Packages
  464. @subsubsection Notes about The KEYWORD Package
  465. It is generally best to confine the use of @i{keywords} to situations in which
  466. there are a finitely enumerable set of names to be selected between. For example,
  467. if there were two states of a light switch, they might be called @t{:on} and @t{:off}.
  468. In situations where the set of names is not finitely enumerable
  469. (@i{i.e.}, where name conflicts might arise)
  470. it is frequently best to use @i{symbols} in some @i{package}
  471. other than @t{KEYWORD} so that conflicts will be naturally avoided.
  472. For example, it is generally not wise for a @i{program} to use a @i{keyword}_1
  473. as a @i{property indicator}, since if there were ever another @i{program}
  474. that did the same thing, each would clobber the other's data.
  475. @node Implementation-Defined Packages, , Notes about The KEYWORD Package, Standardized Packages
  476. @subsubsection Implementation-Defined Packages
  477. Other, @i{implementation-defined} @i{packages} might be present
  478. in the initial @r{Common Lisp} environment.
  479. It is recommended, but not required, that the documentation for a
  480. @i{conforming implementation} contain a full list of all @i{package} names
  481. initially present in that @i{implementation} but not specified in this specification.
  482. (See also the @i{function} @b{list-all-packages}.)
  483. @c end of including concept-packages
  484. @node Packages Dictionary, , Package Concepts, Packages
  485. @section Packages Dictionary
  486. @c including dict-packages
  487. @menu
  488. * package::
  489. * export::
  490. * find-symbol::
  491. * find-package::
  492. * find-all-symbols::
  493. * import::
  494. * list-all-packages::
  495. * rename-package::
  496. * shadow::
  497. * shadowing-import::
  498. * delete-package::
  499. * make-package::
  500. * with-package-iterator::
  501. * unexport::
  502. * unintern::
  503. * in-package::
  504. * unuse-package::
  505. * use-package::
  506. * defpackage::
  507. * do-symbols::
  508. * intern::
  509. * package-name::
  510. * package-nicknames::
  511. * package-shadowing-symbols::
  512. * package-use-list::
  513. * package-used-by-list::
  514. * packagep::
  515. * *package*::
  516. * package-error::
  517. * package-error-package::
  518. @end menu
  519. @node package, export, Packages Dictionary, Packages Dictionary
  520. @subsection package [System Class]
  521. @subsubheading Class Precedence List::
  522. @b{package},
  523. @b{t}
  524. @subsubheading Description::
  525. A @i{package} is a @i{namespace} that maps @i{symbol} @i{names}
  526. to @i{symbols}; see @ref{Package Concepts}.
  527. @subsubheading See Also::
  528. @ref{Package Concepts},
  529. @ref{Printing Other Objects},
  530. @ref{Symbols as Tokens}
  531. @node export, find-symbol, package, Packages Dictionary
  532. @subsection export [Function]
  533. @code{export} @i{symbols {&optional} package} @result{} @i{@b{t}}
  534. @subsubheading Arguments and Values::
  535. @i{symbols}---a @i{designator} for a @i{list} of @i{symbols}.
  536. @i{package}---a @i{package designator}.
  537. The default is the @i{current package}.
  538. @subsubheading Description::
  539. @b{export} makes one or more @i{symbols} that are @i{accessible}
  540. in @i{package} (whether directly or by inheritance) be @i{external symbols}
  541. of that @i{package}.
  542. If any of the @i{symbols} is already @i{accessible} as
  543. an @i{external symbol} of @i{package},
  544. @b{export} has no effect on that @i{symbol}.
  545. If the @i{symbol} is
  546. @i{present} in @i{package}
  547. as an internal symbol, it is simply changed to external status.
  548. If it is @i{accessible} as an @i{internal symbol} via @b{use-package},
  549. it
  550. is first @i{imported} into @i{package},
  551. then @i{exported}.
  552. (The @i{symbol} is then @i{present} in the @i{package}
  553. whether or not @i{package} continues to use the @i{package} through
  554. which the @i{symbol} was originally inherited.)
  555. @b{export} makes
  556. each @i{symbol}
  557. @i{accessible} to all the @i{packages} that use @i{package}.
  558. All of these @i{packages} are checked for name conflicts:
  559. @t{(export @i{s} @i{p})} does
  560. @t{(find-symbol (symbol-name @i{s}) @i{q})} for each package @i{q}
  561. in @t{(package-used-by-list @i{p})}. Note that in the usual case of
  562. an @b{export} during the initial definition of a @i{package},
  563. the
  564. result of @b{package-used-by-list}
  565. is @b{nil} and the name-conflict checking
  566. takes negligible time.
  567. When multiple changes are to be made,
  568. for example when @b{export}
  569. is given a @i{list} of @i{symbols}, it is
  570. permissible for the implementation to process each change separately,
  571. so that aborting from a name
  572. conflict caused by any but the first @i{symbol} in the
  573. @i{list} does not unexport the
  574. first @i{symbol} in the @i{list}.
  575. However, aborting from a name-conflict error
  576. caused by @b{export}
  577. of one of @i{symbols} does not leave that @i{symbol}
  578. @i{accessible}
  579. to some @i{packages}
  580. and @i{inaccessible} to others; with respect to
  581. each of @i{symbols} processed, @b{export}
  582. behaves as if it were as an atomic operation.
  583. A name conflict in @b{export} between one of
  584. @i{symbols} being exported and a
  585. @i{symbol} already @i{present} in a @i{package}
  586. that would inherit the
  587. newly-exported @i{symbol}
  588. may be resolved in favor of the exported @i{symbol}
  589. by uninterning the other one, or in favor of the already-present
  590. @i{symbol} by making it a shadowing symbol.
  591. @subsubheading Examples::
  592. @example
  593. (make-package 'temp :use nil) @result{} #<PACKAGE "TEMP">
  594. (use-package 'temp) @result{} T
  595. (intern "TEMP-SYM" 'temp) @result{} TEMP::TEMP-SYM, NIL
  596. (find-symbol "TEMP-SYM") @result{} NIL, NIL
  597. (export (find-symbol "TEMP-SYM" 'temp) 'temp) @result{} T
  598. (find-symbol "TEMP-SYM") @result{} TEMP-SYM, :INHERITED
  599. @end example
  600. @subsubheading Side Effects::
  601. The package system is modified.
  602. @subsubheading Affected By::
  603. @i{Accessible} @i{symbols}.
  604. @subsubheading Exceptional Situations::
  605. If any of the @i{symbols} is not @i{accessible} at all in @i{package},
  606. an error of @i{type} @b{package-error} is signaled that is @i{correctable}
  607. by permitting the @i{user}
  608. to interactively specify whether that @i{symbol} should be @i{imported}.
  609. @subsubheading See Also::
  610. @ref{import}
  611. ,
  612. @ref{unexport}
  613. ,
  614. @ref{Package Concepts}
  615. @node find-symbol, find-package, export, Packages Dictionary
  616. @subsection find-symbol [Function]
  617. @code{find-symbol} @i{string {&optional} package} @result{} @i{symbol, status}
  618. @subsubheading Arguments and Values::
  619. @i{string}---a @i{string}.
  620. @i{package}---a @i{package designator}.
  621. The default is the @i{current package}.
  622. @i{symbol}---a @i{symbol} accessible in the @i{package},
  623. or @b{nil}.
  624. @i{status}---one of @t{:inherited}, @t{:external}, @t{:internal}, or @b{nil}.
  625. @subsubheading Description::
  626. @b{find-symbol} locates a @i{symbol} whose @i{name} is
  627. @i{string} in a @i{package}.
  628. If a @i{symbol} named @i{string} is found in @i{package},
  629. directly or by inheritance, the @i{symbol}
  630. found is returned as the first
  631. value; the second value is as follows:
  632. @table @asis
  633. @item @t{:internal}
  634. If the @i{symbol} is @i{present} in @i{package}
  635. as an @i{internal symbol}.
  636. @item @t{:external}
  637. If the @i{symbol} is @i{present} in @i{package}
  638. as an @i{external symbol}.
  639. @item @t{:inherited}
  640. If the @i{symbol} is inherited by @i{package}
  641. through @b{use-package},
  642. but is not @i{present} in @i{package}.
  643. @end table
  644. If no such @i{symbol} is @i{accessible} in @i{package},
  645. both values are @b{nil}.
  646. @subsubheading Examples::
  647. @example
  648. (find-symbol "NEVER-BEFORE-USED") @result{} NIL, NIL
  649. (find-symbol "NEVER-BEFORE-USED") @result{} NIL, NIL
  650. (intern "NEVER-BEFORE-USED") @result{} NEVER-BEFORE-USED, NIL
  651. (intern "NEVER-BEFORE-USED") @result{} NEVER-BEFORE-USED, :INTERNAL
  652. (find-symbol "NEVER-BEFORE-USED") @result{} NEVER-BEFORE-USED, :INTERNAL
  653. (find-symbol "never-before-used") @result{} NIL, NIL
  654. (find-symbol "CAR" 'common-lisp-user) @result{} CAR, :INHERITED
  655. (find-symbol "CAR" 'common-lisp) @result{} CAR, :EXTERNAL
  656. (find-symbol "NIL" 'common-lisp-user) @result{} NIL, :INHERITED
  657. (find-symbol "NIL" 'common-lisp) @result{} NIL, :EXTERNAL
  658. (find-symbol "NIL" (prog1 (make-package "JUST-TESTING" :use '())
  659. (intern "NIL" "JUST-TESTING")))
  660. @result{} JUST-TESTING::NIL, :INTERNAL
  661. (export 'just-testing::nil 'just-testing)
  662. (find-symbol "NIL" 'just-testing) @result{} JUST-TESTING:NIL, :EXTERNAL
  663. (find-symbol "NIL" "KEYWORD")
  664. @result{} NIL, NIL
  665. @i{OR}@result{} :NIL, :EXTERNAL
  666. (find-symbol (symbol-name :nil) "KEYWORD") @result{} :NIL, :EXTERNAL
  667. @end example
  668. @subsubheading Affected By::
  669. @b{intern},
  670. @b{import},
  671. @b{export},
  672. @b{use-package},
  673. @b{unintern},
  674. @b{unexport},
  675. @b{unuse-package}
  676. @subsubheading See Also::
  677. @ref{intern}
  678. ,
  679. @ref{find-all-symbols}
  680. @subsubheading Notes::
  681. @b{find-symbol} is operationally equivalent to @b{intern},
  682. except that it never creates a new @i{symbol}.
  683. @node find-package, find-all-symbols, find-symbol, Packages Dictionary
  684. @subsection find-package [Function]
  685. @code{find-package} @i{name} @result{} @i{package}
  686. @subsubheading Arguments and Values::
  687. @i{name}---a @i{string designator} or a @i{package} @i{object}.
  688. @i{package}---a @i{package} @i{object} or @b{nil}.
  689. @subsubheading Description::
  690. If @i{name} is a @i{string designator},
  691. @b{find-package} locates and returns the
  692. @i{package} whose name or nickname is @i{name}.
  693. This
  694. search is case sensitive.
  695. If there is no such @i{package},
  696. @b{find-package} returns @b{nil}.
  697. If @i{name} is a @i{package} @i{object},
  698. that @i{package} @i{object} is returned.
  699. @subsubheading Examples::
  700. @example
  701. (find-package 'common-lisp) @result{} #<PACKAGE "COMMON-LISP">
  702. (find-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  703. (find-package 'not-there) @result{} NIL
  704. @end example
  705. @subsubheading Affected By::
  706. The set of @i{packages} created by the @i{implementation}.
  707. @b{defpackage},
  708. @b{delete-package},
  709. @b{make-package},
  710. @b{rename-package}
  711. @subsubheading See Also::
  712. @ref{make-package}
  713. @node find-all-symbols, import, find-package, Packages Dictionary
  714. @subsection find-all-symbols [Function]
  715. @code{find-all-symbols} @i{string} @result{} @i{symbols}
  716. @subsubheading Arguments and Values::
  717. @i{string}---a @i{string designator}.
  718. @i{symbols}---a @i{list} of @i{symbols}.
  719. @subsubheading Description::
  720. @b{find-all-symbols} searches
  721. every @i{registered package}
  722. for @i{symbols} that have a
  723. @i{name} that is the @i{same} (under @b{string=}) as
  724. @i{string}. A @i{list} of all such @i{symbols} is returned.
  725. Whether or how the @i{list} is ordered is
  726. @i{implementation-dependent}.
  727. @subsubheading Examples::
  728. @example
  729. (find-all-symbols 'car)
  730. @result{} (CAR)
  731. @i{OR}@result{} (CAR VEHICLES:CAR)
  732. @i{OR}@result{} (VEHICLES:CAR CAR)
  733. (intern "CAR" (make-package 'temp :use nil)) @result{} TEMP::CAR, NIL
  734. (find-all-symbols 'car)
  735. @result{} (TEMP::CAR CAR)
  736. @i{OR}@result{} (CAR TEMP::CAR)
  737. @i{OR}@result{} (TEMP::CAR CAR VEHICLES:CAR)
  738. @i{OR}@result{} (CAR TEMP::CAR VEHICLES:CAR)
  739. @end example
  740. @subsubheading See Also::
  741. @ref{find-symbol}
  742. @node import, list-all-packages, find-all-symbols, Packages Dictionary
  743. @subsection import [Function]
  744. @code{import} @i{symbols {&optional} package} @result{} @i{@b{t}}
  745. @subsubheading Arguments and Values::
  746. @i{symbols}---a @i{designator} for a @i{list} of @i{symbols}.
  747. @i{package}---a @i{package designator}.
  748. The default is the @i{current package}.
  749. @subsubheading Description::
  750. @b{import} adds @i{symbol} or
  751. @i{symbols} to the internals of @i{package}, checking for name
  752. conflicts with existing @i{symbols} either @i{present} in @i{package}
  753. or @i{accessible} to it. Once the @i{symbols} have been
  754. @i{imported}, they may be referenced in the @i{importing}
  755. @i{package} without the use of a @i{package prefix} when using the @i{Lisp reader}.
  756. A name conflict in @b{import} between the
  757. @i{symbol} being imported and a symbol inherited from some other @i{package} can
  758. be resolved in favor of the
  759. @i{symbol} being @i{imported}
  760. by making it a shadowing symbol, or in favor
  761. of the @i{symbol} already @i{accessible} by
  762. not doing the @b{import}. A
  763. name conflict in @b{import} with a @i{symbol}
  764. already @i{present} in the
  765. @i{package}
  766. may be resolved by uninterning that @i{symbol}, or by not
  767. doing the @b{import}.
  768. The imported @i{symbol} is
  769. not automatically exported from the @i{current package}, but if it is
  770. already @i{present} and external, then the fact that it
  771. is external is not changed.
  772. If any @i{symbol} to be @i{imported} has no home
  773. package (@i{i.e.}, @t{(symbol-package @i{symbol}) @result{} nil}),
  774. @b{import} sets the @i{home package}
  775. of the @i{symbol} to @i{package}.
  776. If the @i{symbol} is already @i{present} in the importing @i{package},
  777. @b{import} has no effect.
  778. @subsubheading Examples::
  779. @example
  780. (import 'common-lisp::car (make-package 'temp :use nil)) @result{} T
  781. (find-symbol "CAR" 'temp) @result{} CAR, :INTERNAL
  782. (find-symbol "CDR" 'temp) @result{} NIL, NIL
  783. @end example
  784. The form @t{(import 'editor:buffer)} takes the external symbol named
  785. @t{buffer} in the @t{EDITOR} @i{package} (this symbol was located when the form
  786. was read by the @i{Lisp reader}) and adds it to the @i{current package}
  787. as an @i{internal symbol}. The symbol @t{buffer} is then @i{present} in
  788. the @i{current package}.
  789. @subsubheading Side Effects::
  790. The package system is modified.
  791. @subsubheading Affected By::
  792. Current state of the package system.
  793. @subsubheading Exceptional Situations::
  794. @b{import} signals a @i{correctable} error of @i{type} @b{package-error}
  795. if any of the @i{symbols} to be @i{imported} has the @i{same} @i{name}
  796. (under @b{string=}) as some distinct @i{symbol} (under @b{eql})
  797. already @i{accessible} in the @i{package}, even if the conflict is
  798. with a @i{shadowing symbol} of the @i{package}.
  799. @subsubheading See Also::
  800. @ref{shadow}
  801. ,
  802. @ref{export}
  803. @node list-all-packages, rename-package, import, Packages Dictionary
  804. @subsection list-all-packages [Function]
  805. @code{list-all-packages} @i{<@i{no @i{arguments}}>} @result{} @i{packages}
  806. @subsubheading Arguments and Values::
  807. @i{packages}---a @i{list} of @i{package} @i{objects}.
  808. @subsubheading Description::
  809. @b{list-all-packages} returns a
  810. @i{fresh}
  811. @i{list} of
  812. all @i{registered packages}.
  813. @subsubheading Examples::
  814. @example
  815. (let ((before (list-all-packages)))
  816. (make-package 'temp)
  817. (set-difference (list-all-packages) before)) @result{} (#<PACKAGE "TEMP">)
  818. @end example
  819. @subsubheading Affected By::
  820. @b{defpackage},
  821. @b{delete-package},
  822. @b{make-package}
  823. @node rename-package, shadow, list-all-packages, Packages Dictionary
  824. @subsection rename-package [Function]
  825. @code{rename-package} @i{package new-name {&optional} new-nicknames} @result{} @i{package-object}
  826. @subsubheading Arguments and Values::
  827. @i{package}---a @i{package designator}.
  828. @i{new-name}---a @i{package designator}.
  829. @i{new-nicknames}---a @i{list} of @i{string designators}.
  830. The default is the @i{empty list}.
  831. @i{package-object}---the renamed @i{package} @i{object}.
  832. @subsubheading Description::
  833. Replaces the name and nicknames of @i{package}.
  834. The old name and all of the old nicknames of @i{package} are eliminated
  835. and are replaced by @i{new-name} and @i{new-nicknames}.
  836. The consequences are undefined if @i{new-name} or any @i{new-nickname}
  837. conflicts with any existing package names.
  838. @subsubheading Examples::
  839. @example
  840. (make-package 'temporary :nicknames '("TEMP")) @result{} #<PACKAGE "TEMPORARY">
  841. (rename-package 'temp 'ephemeral) @result{} #<PACKAGE "EPHEMERAL">
  842. (package-nicknames (find-package 'ephemeral)) @result{} ()
  843. (find-package 'temporary) @result{} NIL
  844. (rename-package 'ephemeral 'temporary '(temp fleeting))
  845. @result{} #<PACKAGE "TEMPORARY">
  846. (package-nicknames (find-package 'temp)) @result{} ("TEMP" "FLEETING")
  847. @end example
  848. @subsubheading See Also::
  849. @ref{make-package}
  850. @node shadow, shadowing-import, rename-package, Packages Dictionary
  851. @subsection shadow [Function]
  852. @code{shadow} @i{symbol-names {&optional} package} @result{} @i{@b{t}}
  853. @subsubheading Arguments and Values::
  854. @i{symbol-names}---a @i{designator} for
  855. a @i{list} of @i{string designators}.
  856. @i{package}---a @i{package designator}.
  857. The default is the @i{current package}.
  858. @subsubheading Description::
  859. @b{shadow} assures that @i{symbols} with names given
  860. by @i{symbol-names} are @i{present}
  861. in
  862. the @i{package}.
  863. Specifically, @i{package} is searched for @i{symbols}
  864. with the @i{names} supplied by @i{symbol-names}.
  865. For each such @i{name}, if a corresponding @i{symbol}
  866. is not @i{present} in @i{package} (directly, not by inheritance),
  867. then a corresponding @i{symbol} is created with that @i{name},
  868. and inserted into @i{package} as an @i{internal symbol}.
  869. The corresponding @i{symbol}, whether pre-existing or newly created,
  870. is then added, if not already present, to the @i{shadowing symbols list}
  871. of @i{package}.
  872. @subsubheading Examples::
  873. @example
  874. (package-shadowing-symbols (make-package 'temp)) @result{} NIL
  875. (find-symbol 'car 'temp) @result{} CAR, :INHERITED
  876. (shadow 'car 'temp) @result{} T
  877. (find-symbol 'car 'temp) @result{} TEMP::CAR, :INTERNAL
  878. (package-shadowing-symbols 'temp) @result{} (TEMP::CAR)
  879. @end example
  880. @example
  881. (make-package 'test-1) @result{} #<PACKAGE "TEST-1">
  882. (intern "TEST" (find-package 'test-1)) @result{} TEST-1::TEST, NIL
  883. (shadow 'test-1::test (find-package 'test-1)) @result{} T
  884. (shadow 'TEST (find-package 'test-1)) @result{} T
  885. (assert (not (null (member 'test-1::test (package-shadowing-symbols
  886. (find-package 'test-1))))))
  887. (make-package 'test-2) @result{} #<PACKAGE "TEST-2">
  888. (intern "TEST" (find-package 'test-2)) @result{} TEST-2::TEST, NIL
  889. (export 'test-2::test (find-package 'test-2)) @result{} T
  890. (use-package 'test-2 (find-package 'test-1)) ;should not error
  891. @end example
  892. @subsubheading Side Effects::
  893. @b{shadow} changes the state of the package system in such a
  894. way that the package consistency rules do not hold across the change.
  895. @subsubheading Affected By::
  896. Current state of the package system.
  897. @subsubheading See Also::
  898. @ref{package-shadowing-symbols}
  899. ,
  900. @ref{Package Concepts}
  901. @subsubheading Notes::
  902. If a @i{symbol} with a name in @i{symbol-names} already exists
  903. in @i{package}, but by inheritance, the inherited symbol becomes
  904. @i{shadowed}_3 by a newly created @i{internal symbol}.
  905. @node shadowing-import, delete-package, shadow, Packages Dictionary
  906. @subsection shadowing-import [Function]
  907. @code{shadowing-import} @i{symbols {&optional} package} @result{} @i{@b{t}}
  908. @subsubheading Arguments and Values::
  909. @i{symbols}---a @i{designator} for a @i{list} of @i{symbols}.
  910. @i{package} ---a @i{package designator}.
  911. The default is the @i{current package}.
  912. @subsubheading Description::
  913. @b{shadowing-import} is like @b{import},
  914. but it does not signal an error even if the importation of a @i{symbol}
  915. would shadow some @i{symbol} already @i{accessible} in @i{package}.
  916. @b{shadowing-import} inserts each of @i{symbols}
  917. into @i{package} as an internal symbol, regardless
  918. of whether another @i{symbol} of the same name is shadowed by this
  919. action.
  920. If a different @i{symbol} of the same name is already @i{present}
  921. in @i{package},
  922. that @i{symbol} is first @i{uninterned} from @i{package}.
  923. The new @i{symbol} is added to @i{package}'s shadowing-symbols list.
  924. @b{shadowing-import} does name-conflict
  925. checking to the extent that it checks whether a distinct existing
  926. @i{symbol} with the same name is @i{accessible}; if so, it is shadowed by
  927. the new @i{symbol}, which implies that it must be uninterned
  928. if it was
  929. @i{present} in @i{package}.
  930. @subsubheading Examples::
  931. @example
  932. (in-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  933. (setq sym (intern "CONFLICT")) @result{} CONFLICT
  934. (intern "CONFLICT" (make-package 'temp)) @result{} TEMP::CONFLICT, NIL
  935. (package-shadowing-symbols 'temp) @result{} NIL
  936. (shadowing-import sym 'temp) @result{} T
  937. (package-shadowing-symbols 'temp) @result{} (CONFLICT)
  938. @end example
  939. @subsubheading Side Effects::
  940. @b{shadowing-import}
  941. changes the state of the package system in such a way that
  942. the consistency rules do not hold across the change.
  943. @i{package}'s shadowing-symbols list is modified.
  944. @subsubheading Affected By::
  945. Current state of the package system.
  946. @subsubheading See Also::
  947. @ref{import}
  948. ,
  949. @ref{unintern}
  950. ,
  951. @ref{package-shadowing-symbols}
  952. @node delete-package, make-package, shadowing-import, Packages Dictionary
  953. @subsection delete-package [Function]
  954. @code{delete-package} @i{package} @result{} @i{generalized-boolean}
  955. @subsubheading Arguments and Values::
  956. @i{package}---a @i{package designator}.
  957. @i{generalized-boolean}---a @i{generalized boolean}.
  958. @subsubheading Description::
  959. @b{delete-package} deletes @i{package} from all package system
  960. data structures.
  961. If the operation is successful, @b{delete-package} returns
  962. true, otherwise @b{nil}.
  963. The effect of @b{delete-package} is that the name and nicknames
  964. of @i{package} cease to be recognized package names.
  965. The package @i{object} is still a @i{package}
  966. (@i{i.e.}, @b{packagep} is @i{true} of it)
  967. but @b{package-name} returns @b{nil}.
  968. The consequences of deleting the @t{COMMON-LISP} @i{package} or the @t{KEYWORD} @i{package} are undefined.
  969. The consequences of invoking any other package operation on @i{package}
  970. once it has been deleted are unspecified.
  971. In particular, the consequences of invoking @b{find-symbol},
  972. @b{intern} and other functions that look for a symbol name in
  973. a @i{package} are unspecified if they are called with @b{*package*}
  974. bound to the deleted @i{package} or with the deleted @i{package}
  975. as an argument.
  976. If @i{package} is a @i{package} @i{object} that has already
  977. been deleted, @b{delete-package} immediately returns @b{nil}.
  978. After this operation completes, the
  979. @i{home package}
  980. of any @i{symbol} whose @i{home package}
  981. had previously been
  982. @i{package}
  983. is
  984. @i{implementation-dependent}.
  985. Except for this, @i{symbols} @i{accessible}
  986. in @i{package} are not modified in any other way;
  987. @i{symbols} whose @i{home package} is not @i{package} remain unchanged.
  988. @subsubheading Examples::
  989. @example
  990. (setq *foo-package* (make-package "FOO" :use nil))
  991. (setq *foo-symbol* (intern "FOO" *foo-package*))
  992. (export *foo-symbol* *foo-package*)
  993. (setq *bar-package* (make-package "BAR" :use '("FOO")))
  994. (setq *bar-symbol* (intern "BAR" *bar-package*))
  995. (export *foo-symbol* *bar-package*)
  996. (export *bar-symbol* *bar-package*)
  997. (setq *baz-package* (make-package "BAZ" :use '("BAR")))
  998. (symbol-package *foo-symbol*) @result{} #<PACKAGE "FOO">
  999. (symbol-package *bar-symbol*) @result{} #<PACKAGE "BAR">
  1000. (prin1-to-string *foo-symbol*) @result{} "FOO:FOO"
  1001. (prin1-to-string *bar-symbol*) @result{} "BAR:BAR"
  1002. (find-symbol "FOO" *bar-package*) @result{} FOO:FOO, :EXTERNAL
  1003. (find-symbol "FOO" *baz-package*) @result{} FOO:FOO, :INHERITED
  1004. (find-symbol "BAR" *baz-package*) @result{} BAR:BAR, :INHERITED
  1005. (packagep *foo-package*) @result{} @i{true}
  1006. (packagep *bar-package*) @result{} @i{true}
  1007. (packagep *baz-package*) @result{} @i{true}
  1008. (package-name *foo-package*) @result{} "FOO"
  1009. (package-name *bar-package*) @result{} "BAR"
  1010. (package-name *baz-package*) @result{} "BAZ"
  1011. (package-use-list *foo-package*) @result{} ()
  1012. (package-use-list *bar-package*) @result{} (#<PACKAGE "FOO">)
  1013. (package-use-list *baz-package*) @result{} (#<PACKAGE "BAR">)
  1014. (package-used-by-list *foo-package*) @result{} (#<PACKAGE "BAR">)
  1015. (package-used-by-list *bar-package*) @result{} (#<PACKAGE "BAZ">)
  1016. (package-used-by-list *baz-package*) @result{} ()
  1017. (delete-package *bar-package*)
  1018. @t{ |> } Error: Package BAZ uses package BAR.
  1019. @t{ |> } If continued, BAZ will be made to unuse-package BAR,
  1020. @t{ |> } and then BAR will be deleted.
  1021. @t{ |> } Type :CONTINUE to continue.
  1022. @t{ |> } Debug> @b{|>>}@t{:CONTINUE}@b{<<|}
  1023. @result{} T
  1024. (symbol-package *foo-symbol*) @result{} #<PACKAGE "FOO">
  1025. (symbol-package *bar-symbol*) is unspecified
  1026. (prin1-to-string *foo-symbol*) @result{} "FOO:FOO"
  1027. (prin1-to-string *bar-symbol*) is unspecified
  1028. (find-symbol "FOO" *bar-package*) is unspecified
  1029. (find-symbol "FOO" *baz-package*) @result{} NIL, NIL
  1030. (find-symbol "BAR" *baz-package*) @result{} NIL, NIL
  1031. (packagep *foo-package*) @result{} T
  1032. (packagep *bar-package*) @result{} T
  1033. (packagep *baz-package*) @result{} T
  1034. (package-name *foo-package*) @result{} "FOO"
  1035. (package-name *bar-package*) @result{} NIL
  1036. (package-name *baz-package*) @result{} "BAZ"
  1037. (package-use-list *foo-package*) @result{} ()
  1038. (package-use-list *bar-package*) is unspecified
  1039. (package-use-list *baz-package*) @result{} ()
  1040. (package-used-by-list *foo-package*) @result{} ()
  1041. (package-used-by-list *bar-package*) is unspecified
  1042. (package-used-by-list *baz-package*) @result{} ()
  1043. @end example
  1044. @subsubheading Exceptional Situations::
  1045. If the @i{package} @i{designator} is a @i{name} that does not
  1046. currently name a @i{package},
  1047. a @i{correctable} error of @i{type} @b{package-error} is signaled.
  1048. If correction is attempted, no deletion action is attempted;
  1049. instead, @b{delete-package} immediately returns @b{nil}.
  1050. If @i{package} is used by other @i{packages},
  1051. a @i{correctable} error of @i{type} @b{package-error} is signaled.
  1052. If correction is attempted,
  1053. @b{unuse-package} is effectively called to remove any dependencies,
  1054. causing @i{package}'s @i{external symbols} to cease being @i{accessible} to those
  1055. @i{packages} that use @i{package}.
  1056. @b{delete-package} then deletes @i{package} just as it would have had
  1057. there been no @i{packages} that used it.
  1058. @subsubheading See Also::
  1059. @ref{unuse-package}
  1060. @node make-package, with-package-iterator, delete-package, Packages Dictionary
  1061. @subsection make-package [Function]
  1062. @code{make-package} @i{package-name {&key} nicknames use} @result{} @i{package}
  1063. @subsubheading Arguments and Values::
  1064. @i{package-name}---a @i{string designator}.
  1065. @i{nicknames}---a @i{list} of @i{string designators}.
  1066. The default is the @i{empty list}.
  1067. @i{use}---
  1068. a @i{list} of @i{package designators}.
  1069. The default is @i{implementation-defined}.
  1070. @i{package}---a @i{package}.
  1071. @subsubheading Description::
  1072. Creates a new @i{package} with the name @i{package-name}.
  1073. @i{Nicknames} are additional @i{names} which may be used
  1074. to refer to the new @i{package}.
  1075. @i{use} specifies zero or more @i{packages}
  1076. the @i{external symbols} of which are to be inherited by
  1077. the new @i{package}. See the @i{function} @b{use-package}.
  1078. @subsubheading Examples::
  1079. @example
  1080. (make-package 'temporary :nicknames '("TEMP" "temp")) @result{} #<PACKAGE "TEMPORARY">
  1081. (make-package "OWNER" :use '("temp")) @result{} #<PACKAGE "OWNER">
  1082. (package-used-by-list 'temp) @result{} (#<PACKAGE "OWNER">)
  1083. (package-use-list 'owner) @result{} (#<PACKAGE "TEMPORARY">)
  1084. @end example
  1085. @subsubheading Affected By::
  1086. The existence of other @i{packages} in the system.
  1087. @subsubheading Exceptional Situations::
  1088. The consequences are unspecified if @i{packages} denoted by @i{use}
  1089. do not exist.
  1090. A @i{correctable} error is signaled if the @i{package-name}
  1091. or any of the @i{nicknames} is already
  1092. the @i{name} or @i{nickname} of an existing @i{package}.
  1093. @subsubheading See Also::
  1094. @ref{defpackage}
  1095. ,
  1096. @ref{use-package}
  1097. @subsubheading Notes::
  1098. In situations where the @i{packages} to be used contain symbols which would conflict,
  1099. it is necessary to first create the package with @t{:use '()},
  1100. then to use @b{shadow} or @b{shadowing-import} to address the conflicts,
  1101. and then after that to use @b{use-package} once the conflicts have been addressed.
  1102. When packages are being created as part of the static definition of a program
  1103. rather than dynamically by the program, it is generally considered more stylistically
  1104. appropriate to use @b{defpackage} rather than @b{make-package}.
  1105. @node with-package-iterator, unexport, make-package, Packages Dictionary
  1106. @subsection with-package-iterator [Macro]
  1107. @code{with-package-iterator} @i{@r{(}name package-list-form {&rest} {symbol-types}@r{)}
  1108. @{@i{declaration}@}{*} @{@i{form}@}{*}}@*
  1109. @result{} @i{@{@i{result}@}{*}}
  1110. @subsubheading Arguments and Values::
  1111. @i{name}---a @i{symbol}.
  1112. @i{package-list-form}---a @i{form}; evaluated once to produce a @i{package-list}.
  1113. @i{package-list}---a @i{designator} for a list of @i{package designators}.
  1114. @i{symbol-type}---one of the @i{symbols}
  1115. @t{:internal}, @t{:external}, or @t{:inherited}.
  1116. @i{declaration}---a @b{declare} @i{expression}; not evaluated.
  1117. @i{forms}---an @i{implicit progn}.
  1118. @i{results}---the @i{values} of the @i{forms}.
  1119. @subsubheading Description::
  1120. Within the lexical scope of the body @i{forms},
  1121. the @i{name} is defined via @b{macrolet}
  1122. such that successive invocations of @t{(@i{name})}
  1123. will return the @i{symbols}, one by one,
  1124. from the @i{packages} in @i{package-list}.
  1125. It is unspecified whether @i{symbols} inherited from
  1126. multiple @i{packages} are returned more than once.
  1127. The order of @i{symbols} returned does not necessarily reflect the order
  1128. of @i{packages} in @i{package-list}. When @i{package-list} has
  1129. more than one element, it is unspecified whether duplicate @i{symbols} are
  1130. returned once or more than once.
  1131. @i{Symbol-types} controls which @i{symbols} that are @i{accessible}
  1132. in a @i{package} are returned as follows:
  1133. @table @asis
  1134. @item @t{:internal}
  1135. The @i{symbols} that are @i{present} in the @i{package},
  1136. but that are not @i{exported}.
  1137. @item @t{:external}
  1138. The @i{symbols} that are @i{present} in the @i{package}
  1139. and are @i{exported}.
  1140. @item @t{:inherited}
  1141. The @i{symbols} that are @i{exported} by used @i{packages}
  1142. and that are not @i{shadowed}.
  1143. @end table
  1144. When more than one argument is supplied for @i{symbol-types},
  1145. a @i{symbol} is returned if its @i{accessibility} matches
  1146. any one of the @i{symbol-types} supplied.
  1147. Implementations may extend this syntax by recognizing additional
  1148. symbol accessibility types.
  1149. An invocation of @t{(@i{name})} returns four values as follows:
  1150. @table @asis
  1151. @item 1.
  1152. A flag that indicates whether a @i{symbol} is returned
  1153. (true means that a @i{symbol} is returned).
  1154. @item 2.
  1155. A @i{symbol} that is @i{accessible} in one the
  1156. indicated @i{packages}.
  1157. @item 3.
  1158. The accessibility type for that @i{symbol};
  1159. @i{i.e.}, one of the symbols @t{:internal}, @t{:external}, or @t{:inherited}.
  1160. @item 4.
  1161. The @i{package} from which the @i{symbol} was obtained.
  1162. The @i{package} is one of the @i{packages} present
  1163. or named in @i{package-list}.
  1164. @end table
  1165. After all @i{symbols} have been returned by successive invocations of
  1166. @t{(@i{name})}, then only one value is returned, namely @b{nil}.
  1167. The meaning of the second, third, and fourth @i{values} is that the returned
  1168. @i{symbol} is @i{accessible} in the returned @i{package}
  1169. in the way indicated by the second return value as follows:
  1170. @table @asis
  1171. @item @t{:internal}
  1172. Means @i{present} and not @i{exported}.
  1173. @item @t{:external}
  1174. Means @i{present} and @i{exported}.
  1175. @item @t{:inherited}
  1176. Means not @i{present} (thus not @i{shadowed}) but inherited
  1177. from some used @i{package}.
  1178. @end table
  1179. It is unspecified what happens if any of the implicit interior state
  1180. of an iteration is returned outside the dynamic extent of the
  1181. @b{with-package-iterator}
  1182. form such as by returning some @i{closure} over the invocation @i{form}.
  1183. Any number of invocations of @b{with-package-iterator}
  1184. can be nested, and the body of the innermost one can invoke all of the
  1185. locally @i{established} @i{macros}, provided all those @i{macros}
  1186. have distinct names.
  1187. @subsubheading Examples::
  1188. The following function should return @b{t} on any @i{package}, and signal
  1189. an error if the usage of @b{with-package-iterator} does not agree
  1190. with the corresponding usage of @b{do-symbols}.
  1191. @example
  1192. (defun test-package-iterator (package)
  1193. (unless (packagep package)
  1194. (setq package (find-package package)))
  1195. (let ((all-entries '())
  1196. (generated-entries '()))
  1197. (do-symbols (x package)
  1198. (multiple-value-bind (symbol accessibility)
  1199. (find-symbol (symbol-name x) package)
  1200. (push (list symbol accessibility) all-entries)))
  1201. (with-package-iterator (generator-fn package
  1202. :internal :external :inherited)
  1203. (loop
  1204. (multiple-value-bind (more? symbol accessibility pkg)
  1205. (generator-fn)
  1206. (unless more? (return))
  1207. (let ((l (multiple-value-list (find-symbol (symbol-name symbol)
  1208. package))))
  1209. (unless (equal l (list symbol accessibility))
  1210. (error "Symbol ~S not found as ~S in package ~A [~S]"
  1211. symbol accessibility (package-name package) l))
  1212. (push l generated-entries)))))
  1213. (unless (and (subsetp all-entries generated-entries :test #'equal)
  1214. (subsetp generated-entries all-entries :test #'equal))
  1215. (error "Generated entries and Do-Symbols entries don't correspond"))
  1216. t))
  1217. @end example
  1218. The following function prints out every @i{present} @i{symbol}
  1219. (possibly more than once):
  1220. @example
  1221. (defun print-all-symbols ()
  1222. (with-package-iterator (next-symbol (list-all-packages)
  1223. :internal :external)
  1224. (loop
  1225. (multiple-value-bind (more? symbol) (next-symbol)
  1226. (if more?
  1227. (print symbol)
  1228. (return))))))
  1229. @end example
  1230. @subsubheading Exceptional Situations::
  1231. @b{with-package-iterator} signals an error of @i{type} @b{program-error} if
  1232. no @i{symbol-types} are supplied or if a @i{symbol-type} is not
  1233. recognized by the implementation is supplied.
  1234. The consequences are undefined if the local function named @i{name}
  1235. @i{established} by @b{with-package-iterator} is called after it
  1236. has returned @i{false} as its @i{primary value}.
  1237. @subsubheading See Also::
  1238. @ref{Traversal Rules and Side Effects}
  1239. @node unexport, unintern, with-package-iterator, Packages Dictionary
  1240. @subsection unexport [Function]
  1241. @code{unexport} @i{symbols {&optional} package} @result{} @i{@b{t}}
  1242. @subsubheading Arguments and Values::
  1243. @i{symbols}---a @i{designator} for a @i{list} of @i{symbols}.
  1244. @i{package}---a @i{package designator}.
  1245. The default is the @i{current package}.
  1246. @subsubheading Description::
  1247. @b{unexport} reverts external @i{symbols} in @i{package} to
  1248. internal status; it undoes the effect of @b{export}.
  1249. @b{unexport} works only on @i{symbols}
  1250. @i{present}
  1251. in @i{package}, switching them back to internal status.
  1252. If @b{unexport} is given a @i{symbol} that is
  1253. already @i{accessible} as an @i{internal symbol} in @i{package},
  1254. it does nothing.
  1255. @subsubheading Examples::
  1256. @example
  1257. (in-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  1258. (export (intern "CONTRABAND" (make-package 'temp)) 'temp) @result{} T
  1259. (find-symbol "CONTRABAND") @result{} NIL, NIL
  1260. (use-package 'temp) @result{} T
  1261. (find-symbol "CONTRABAND") @result{} CONTRABAND, :INHERITED
  1262. (unexport 'contraband 'temp) @result{} T
  1263. (find-symbol "CONTRABAND") @result{} NIL, NIL
  1264. @end example
  1265. @subsubheading Side Effects::
  1266. Package system is modified.
  1267. @subsubheading Affected By::
  1268. Current state of the package system.
  1269. @subsubheading Exceptional Situations::
  1270. If @b{unexport} is given a @i{symbol}
  1271. not @i{accessible} in @i{package} at all,
  1272. an error of @i{type} @b{package-error} is signaled.
  1273. The consequences are undefined if @i{package} is the @t{KEYWORD} @i{package}
  1274. or the @t{COMMON-LISP} @i{package}.
  1275. @subsubheading See Also::
  1276. @ref{export}
  1277. , @ref{Package Concepts}
  1278. @node unintern, in-package, unexport, Packages Dictionary
  1279. @subsection unintern [Function]
  1280. @code{unintern} @i{symbol {&optional} package} @result{} @i{generalized-boolean}
  1281. @subsubheading Arguments and Values::
  1282. @i{symbol}---a @i{symbol}.
  1283. @i{package}---a @i{package designator}.
  1284. The default is the @i{current package}.
  1285. @i{generalized-boolean}---a @i{generalized boolean}.
  1286. @subsubheading Description::
  1287. @b{unintern} removes @i{symbol} from @i{package}.
  1288. If @i{symbol} is @i{present} in @i{package}, it is
  1289. removed from @i{package} and also from @i{package}'s
  1290. @i{shadowing symbols list} if it is present there. If @i{package} is the
  1291. @i{home package} for @i{symbol}, @i{symbol} is made to have no
  1292. @i{home package}.
  1293. @i{Symbol} may continue to be @i{accessible}
  1294. in @i{package} by inheritance.
  1295. Use of @b{unintern} can result in a @i{symbol}
  1296. that has no
  1297. recorded @i{home package},
  1298. but that in fact is @i{accessible} in some @i{package}.
  1299. @r{Common Lisp} does not check for this pathological case,
  1300. and such @i{symbols}
  1301. are always printed preceded by @t{#:}.
  1302. @b{unintern} returns @i{true} if it removes @i{symbol}, and @b{nil} otherwise.
  1303. @subsubheading Examples::
  1304. @example
  1305. (in-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  1306. (setq temps-unpack (intern "UNPACK" (make-package 'temp))) @result{} TEMP::UNPACK
  1307. (unintern temps-unpack 'temp) @result{} T
  1308. (find-symbol "UNPACK" 'temp) @result{} NIL, NIL
  1309. temps-unpack @result{} #:UNPACK
  1310. @end example
  1311. @subsubheading Side Effects::
  1312. @b{unintern} changes the state of the
  1313. package system in such a way that the consistency rules do not hold
  1314. across the change.
  1315. @subsubheading Affected By::
  1316. Current state of the package system.
  1317. @subsubheading Exceptional Situations::
  1318. Giving a shadowing symbol to @b{unintern}
  1319. can uncover a name conflict that had
  1320. previously been resolved by the shadowing. If package A uses packages
  1321. B and C, A contains a shadowing symbol @t{x}, and B and C each contain external
  1322. symbols named @t{x}, then removing the shadowing symbol @t{x}
  1323. from A will reveal a name
  1324. conflict between @t{b:x} and @t{c:x} if those two @i{symbols} are distinct.
  1325. In this case @b{unintern} will signal an error.
  1326. @subsubheading See Also::
  1327. @ref{Package Concepts}
  1328. @node in-package, unuse-package, unintern, Packages Dictionary
  1329. @subsection in-package [Macro]
  1330. @code{in-package} @i{name} @result{} @i{package}
  1331. @subsubheading Arguments and Values::
  1332. @i{name}---a @i{string designator}; not evaluated.
  1333. @i{package}---the @i{package} named by @i{name}.
  1334. @subsubheading Description::
  1335. Causes the the @i{package} named by @i{name}
  1336. to become the @i{current package}---that is, the @i{value} of @b{*package*}.
  1337. If no such @i{package} already exists, an error of @i{type} @b{package-error} is signaled.
  1338. Everything @b{in-package} does is also performed at compile time
  1339. if the call appears as a @i{top level form}.
  1340. @subsubheading Side Effects::
  1341. The @i{variable} @b{*package*} is assigned.
  1342. If the @b{in-package} @i{form} is a @i{top level form},
  1343. this assignment also occurs at compile time.
  1344. @subsubheading Exceptional Situations::
  1345. An error of @i{type} @b{package-error} is signaled if the specified @i{package} does not exist.
  1346. @subsubheading See Also::
  1347. @ref{package}
  1348. @node unuse-package, use-package, in-package, Packages Dictionary
  1349. @subsection unuse-package [Function]
  1350. @code{unuse-package} @i{packages-to-unuse {&optional} package} @result{} @i{@b{t}}
  1351. @subsubheading Arguments and Values::
  1352. @i{packages-to-unuse}---a @i{designator} for
  1353. a @i{list} of @i{package designators}.
  1354. @i{package}---a @i{package designator}.
  1355. The default is the @i{current package}.
  1356. @subsubheading Description::
  1357. @b{unuse-package} causes @i{package} to cease inheriting
  1358. all the @i{external symbols} of
  1359. @i{packages-to-unuse}; @b{unuse-package} undoes
  1360. the effects of @b{use-package}. The
  1361. @i{packages-to-unuse}
  1362. are removed from the @i{use list} of @i{package}.
  1363. Any @i{symbols} that have been
  1364. @i{imported} into @i{package} continue to be @i{present} in @i{package}.
  1365. @subsubheading Examples::
  1366. @example
  1367. (in-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  1368. (export (intern "SHOES" (make-package 'temp)) 'temp) @result{} T
  1369. (find-symbol "SHOES") @result{} NIL, NIL
  1370. (use-package 'temp) @result{} T
  1371. (find-symbol "SHOES") @result{} SHOES, :INHERITED
  1372. (find (find-package 'temp) (package-use-list 'common-lisp-user)) @result{} #<PACKAGE "TEMP">
  1373. (unuse-package 'temp) @result{} T
  1374. (find-symbol "SHOES") @result{} NIL, NIL
  1375. @end example
  1376. @subsubheading Side Effects::
  1377. The @i{use list} of @i{package} is modified.
  1378. @subsubheading Affected By::
  1379. Current state of the package system.
  1380. @subsubheading See Also::
  1381. @ref{use-package}
  1382. ,
  1383. @ref{package-use-list}
  1384. @node use-package, defpackage, unuse-package, Packages Dictionary
  1385. @subsection use-package [Function]
  1386. @code{use-package} @i{packages-to-use {&optional} package} @result{} @i{@b{t}}
  1387. @subsubheading Arguments and Values::
  1388. @i{packages-to-use}---a @i{designator} for
  1389. a @i{list} of @i{package designators}.
  1390. The @t{KEYWORD} @i{package} may not be supplied.
  1391. @i{package}---a @i{package designator}.
  1392. The @t{KEYWORD} @i{package} cannot be supplied.
  1393. The default is the @i{current package}.
  1394. @subsubheading Description::
  1395. @b{use-package} causes @i{package} to inherit all the
  1396. @i{external symbols} of @i{packages-to-use}.
  1397. The inherited @i{symbols} become @i{accessible} as
  1398. @i{internal symbols} of @i{package}.
  1399. @i{Packages-to-use} are added to the @i{use list} of @i{package}
  1400. if they are not there already. All @i{external symbols} in
  1401. @i{packages-to-use} become @i{accessible} in @i{package}
  1402. as @i{internal symbols}.
  1403. @b{use-package} does not cause any new @i{symbols} to be @i{present}
  1404. in @i{package} but only makes them @i{accessible} by inheritance.
  1405. @b{use-package} checks for
  1406. name conflicts between the newly imported symbols and those already
  1407. @i{accessible} in @i{package}.
  1408. A name conflict in @b{use-package}
  1409. between two external symbols inherited
  1410. by @i{package} from @i{packages-to-use} may be resolved in favor of
  1411. either @i{symbol}
  1412. by @i{importing} one of them into @i{package} and making it a
  1413. shadowing symbol.
  1414. @subsubheading Examples::
  1415. @example
  1416. (export (intern "LAND-FILL" (make-package 'trash)) 'trash) @result{} T
  1417. (find-symbol "LAND-FILL" (make-package 'temp)) @result{} NIL, NIL
  1418. (package-use-list 'temp) @result{} (#<PACKAGE "TEMP">)
  1419. (use-package 'trash 'temp) @result{} T
  1420. (package-use-list 'temp) @result{} (#<PACKAGE "TEMP"> #<PACKAGE "TRASH">)
  1421. (find-symbol "LAND-FILL" 'temp) @result{} TRASH:LAND-FILL, :INHERITED
  1422. @end example
  1423. @subsubheading Side Effects::
  1424. The @i{use list} of @i{package} may be modified.
  1425. @subsubheading See Also::
  1426. @ref{unuse-package}
  1427. ,
  1428. @ref{package-use-list}
  1429. ,
  1430. @ref{Package Concepts}
  1431. @subsubheading Notes::
  1432. It is permissible for a @i{package} P_1
  1433. to @i{use} a @i{package} P_2
  1434. even if P_2 already uses P_1.
  1435. The using of @i{packages} is not transitive,
  1436. so no problem results from the apparent circularity.
  1437. @node defpackage, do-symbols, use-package, Packages Dictionary
  1438. @subsection defpackage [Macro]
  1439. @code{defpackage} @i{defined-package-name [[!@i{option}]]} @result{} @i{package}
  1440. @w{@i{option} ::=@{{(}@t{:nicknames} @{@i{nickname}@}{*}@r{)}@}{*} | }
  1441. @w{ @r{(}@t{:documentation} @i{string}@r{)} | }
  1442. @w{ @{{(}@t{:use} @{@i{package-name}@}{*}@r{)}@}{*} | }
  1443. @w{ @{{(}@t{:shadow} @{!@i{symbol-name}@}{*}@r{)}@}{*} | }
  1444. @w{ @{{(}@t{:shadowing-import-from} @i{package-name} @{!@i{symbol-name}@}{*}@r{)}@}{*} | }
  1445. @w{ @{{(}@t{:import-from} @i{package-name} @{!@i{symbol-name}@}{*}@r{)}@}{*} | }
  1446. @w{ @{{(}@t{:export} @{!@i{symbol-name}@}{*}@r{)}@}{*} | }
  1447. @w{ @{{(}@t{:intern} @{!@i{symbol-name}@}{*}@r{)}@}{*} | }
  1448. @w{ @r{(}@t{:size} @i{integer}@r{)}}
  1449. @w{@i{symbol-name} ::=(@i{symbol} | @i{string})}
  1450. @subsubheading Arguments and Values::
  1451. @i{defined-package-name}---a @i{string designator}.
  1452. @i{package-name}---a @i{package designator}.
  1453. @i{nickname}---a @i{string designator}.
  1454. @i{symbol-name}---a @i{string designator}.
  1455. @i{package}---the @i{package} named @i{package-name}.
  1456. @subsubheading Description::
  1457. @b{defpackage} creates a @i{package} as specified and returns
  1458. the @i{package}.
  1459. If @i{defined-package-name} already refers to an existing
  1460. @i{package}, the name-to-package mapping for that name is not changed.
  1461. If the new definition is at variance with the current state of that
  1462. @i{package}, the consequences are undefined; an implementation
  1463. might choose to modify the existing @i{package} to reflect the
  1464. new definition. If @i{defined-package-name} is a @i{symbol},
  1465. its @i{name} is used.
  1466. The standard @i{options} are described below.
  1467. @table @asis
  1468. @item @t{:nicknames}
  1469. The arguments to @t{:nicknames} set the @i{package}'s nicknames to the
  1470. supplied names.
  1471. @item @t{:documentation}
  1472. The argument to @t{:documentation} specifies a @i{documentation string};
  1473. it is attached as a @i{documentation string} to the @i{package}.
  1474. At most one @t{:documentation} option
  1475. can appear in a single @b{defpackage} @i{form}.
  1476. @item @t{:use}
  1477. The arguments to @t{:use} set the @i{packages} that the @i{package}
  1478. named by @i{package-name}
  1479. will inherit from. If @t{:use} is not supplied,
  1480. it defaults to the same @i{implementation-dependent} value as the @t{:use} @i{argument} to
  1481. @b{make-package}.
  1482. @item @t{:shadow}
  1483. The arguments to @t{:shadow}, @i{symbol-names}, name @i{symbols}
  1484. that are to be created in the @i{package} being defined.
  1485. These @i{symbols} are added to the list of shadowing
  1486. @i{symbols} effectively as if by @b{shadow}.
  1487. @item @t{:shadowing-import-from}
  1488. The @i{symbols} named by the argument @i{symbol-names}
  1489. are found (involving a lookup as if by @b{find-symbol})
  1490. in the specified @i{package-name}. The resulting @i{symbols}
  1491. are @i{imported} into the @i{package} being defined, and
  1492. placed on the shadowing symbols list as if by @b{shadowing-import}.
  1493. In no case are @i{symbols} created in any @i{package}
  1494. other than the one being defined.
  1495. @item @t{:import-from}
  1496. The @i{symbols} named by the argument @i{symbol-names}
  1497. are found in the @i{package} named by @i{package-name} and
  1498. they are @i{imported} into the @i{package} being defined.
  1499. In no case are @i{symbols} created in any @i{package}
  1500. other than the one being defined.
  1501. @item @t{:export}
  1502. The @i{symbols} named by
  1503. the argument @i{symbol-names} are found
  1504. or created in the @i{package} being defined
  1505. and @i{exported}.
  1506. The @t{:export} option interacts
  1507. with the @t{:use} option, since inherited @i{symbols}
  1508. can be used rather than new ones created.
  1509. The @t{:export} option interacts
  1510. with the
  1511. @t{:import-from} and @t{:shadowing-import-from} options, since
  1512. @i{imported}
  1513. symbols can be used rather than new ones created.
  1514. If an argument to the @t{:export} option is @i{accessible} as
  1515. an (inherited) @i{internal symbol} via @b{use-package}, that the
  1516. @i{symbol} named by @i{symbol-name}
  1517. is first @i{imported} into the @i{package} being
  1518. defined, and is then @i{exported} from that @i{package}.
  1519. @item @t{:intern}
  1520. The @i{symbols} named by the argument @i{symbol-names}
  1521. are found or created in the @i{package} being defined.
  1522. The @t{:intern} option interacts with the
  1523. @t{:use} option, since inherited @i{symbols}
  1524. can be used rather than new ones created.
  1525. @item @t{:size}
  1526. The argument to the @t{:size} option
  1527. declares the approximate number of @i{symbols} expected in the
  1528. @i{package}.
  1529. This is an efficiency hint only and might be ignored by an
  1530. implementation.
  1531. @end table
  1532. The order in which the options appear in a
  1533. @b{defpackage} form is irrelevant.
  1534. The order in which they are executed is as follows:
  1535. @table @asis
  1536. @item 1.
  1537. @t{:shadow} and @t{:shadowing-import-from}.
  1538. @item 2.
  1539. @t{:use}.
  1540. @item 3.
  1541. @t{:import-from} and @t{:intern}.
  1542. @item 4.
  1543. @t{:export}.
  1544. @end table
  1545. Shadows are established first, since they might be necessary to block
  1546. spurious name conflicts when the @t{:use}
  1547. option is processed. The @t{:use} option is executed
  1548. next so that @t{:intern} and @t{:export} options can refer to normally
  1549. inherited @i{symbols}.
  1550. The @t{:export} option is executed last so that it can refer to
  1551. @i{symbols} created by any of the other options; in
  1552. particular, @i{shadowing symbols} and
  1553. @i{imported} @i{symbols} can be made external.
  1554. If a {defpackage} @i{form} appears as a @i{top level form},
  1555. all of the actions normally performed by this @i{macro}
  1556. at load time must also be performed at compile time.
  1557. @subsubheading Examples::
  1558. @example
  1559. (defpackage "MY-PACKAGE"
  1560. (:nicknames "MYPKG" "MY-PKG")
  1561. (:use "COMMON-LISP")
  1562. (:shadow "CAR" "CDR")
  1563. (:shadowing-import-from "VENDOR-COMMON-LISP" "CONS")
  1564. (:import-from "VENDOR-COMMON-LISP" "GC")
  1565. (:export "EQ" "CONS" "FROBOLA")
  1566. )
  1567. (defpackage my-package
  1568. (:nicknames mypkg :MY-PKG) ; remember Common Lisp conventions for case
  1569. (:use common-lisp) ; conversion on symbols
  1570. (:shadow CAR :cdr #:cons)
  1571. (:export "CONS") ; this is the shadowed one.
  1572. )
  1573. @end example
  1574. @subsubheading Affected By::
  1575. Existing @i{packages}.
  1576. @subsubheading Exceptional Situations::
  1577. If one of the supplied @t{:nicknames} already
  1578. refers to an existing @i{package},
  1579. an error of @i{type} @b{package-error} is signaled.
  1580. An error of @i{type} @b{program-error} should be signaled if @t{:size} or @t{:documentation}
  1581. appears more than once.
  1582. Since @i{implementations} might allow extended @i{options}
  1583. an error of @i{type} @b{program-error} should be signaled
  1584. if an @i{option} is present that is not
  1585. actually supported in the host @i{implementation}.
  1586. The collection of @i{symbol-name} arguments given to the options
  1587. @t{:shadow}, @t{:intern},
  1588. @t{:import-from}, and @t{:shadowing-import-from} must
  1589. all be disjoint; additionally, the @i{symbol-name} arguments given to
  1590. @t{:export} and @t{:intern}
  1591. must be disjoint.
  1592. Disjoint in this context is defined as no two of the @i{symbol-names}
  1593. being @b{string=} with each other. If either condition is
  1594. violated, an error of @i{type} @b{program-error} should be signaled.
  1595. For the @t{:shadowing-import-from} and @t{:import-from} options,
  1596. a @i{correctable} @i{error} of @i{type} @b{package-error}
  1597. is signaled if no @i{symbol} is
  1598. @i{accessible} in the @i{package} named by
  1599. @i{package-name} for one of the argument @i{symbol-names}.
  1600. Name conflict errors are handled by the underlying calls to
  1601. @b{make-package}, @b{use-package}, @b{import}, and
  1602. @b{export}. See @ref{Package Concepts}.
  1603. @subsubheading See Also::
  1604. @ref{documentation; (setf documentation)}
  1605. ,
  1606. @ref{Package Concepts},
  1607. @ref{Compilation}
  1608. @subsubheading Notes::
  1609. The @t{:intern} option is useful if an @t{:import-from} or a
  1610. @t{:shadowing-import-from} option in a subsequent call to @b{defpackage}
  1611. (for some other @i{package}) expects to find
  1612. these @i{symbols} @i{accessible} but not necessarily external.
  1613. It is recommended that the entire @i{package} definition is put
  1614. in a single place, and that all the @i{package} definitions of a
  1615. program are in a single file. This file can be @i{loaded} before
  1616. @i{loading} or compiling anything else that depends on those
  1617. @i{packages}. Such a file can be read in the @t{COMMON-LISP-USER} @i{package},
  1618. avoiding any initial state issues.
  1619. @b{defpackage} cannot be used to create two ``mutually
  1620. recursive'' packages, such as:
  1621. @example
  1622. (defpackage my-package
  1623. (:use common-lisp your-package) ;requires your-package to exist first
  1624. (:export "MY-FUN"))
  1625. (defpackage your-package
  1626. (:use common-lisp)
  1627. (:import-from my-package "MY-FUN") ;requires my-package to exist first
  1628. (:export "MY-FUN"))
  1629. @end example
  1630. However, nothing prevents the user from using the
  1631. @i{package}-affecting functions
  1632. such as @b{use-package},
  1633. @b{import}, and @b{export} to establish such links
  1634. after a more standard use of @b{defpackage}.
  1635. The macroexpansion of @b{defpackage}
  1636. could usefully canonicalize the names
  1637. into @i{strings},
  1638. so that even if a source file has random @i{symbols} in the
  1639. @b{defpackage} form, the compiled file would only contain
  1640. @i{strings}.
  1641. Frequently additional @i{implementation-dependent} options take the
  1642. form of a @i{keyword} standing by itself as an abbreviation for a list
  1643. @t{(keyword T)}; this syntax should be properly reported as an unrecognized
  1644. option in implementations that do not support it.
  1645. @node do-symbols, intern, defpackage, Packages Dictionary
  1646. @subsection do-symbols, do-external-symbols, do-all-symbols [Macro]
  1647. @code{do-symbols} @i{@r{(}var @r{[}package @r{[}result-form@r{]}@r{]}@r{)}
  1648. @{@i{declaration}@}{*}
  1649. @{tag | statement@}{*}}@*
  1650. @result{} @i{@{@i{result}@}{*}}
  1651. @code{do-external-symbols} @i{@r{(}var @r{[}package @r{[}result-form@r{]}@r{]}@r{)}
  1652. @{@i{declaration}@}{*}
  1653. @{tag | statement@}{*}}@*
  1654. @result{} @i{@{@i{result}@}{*}}
  1655. @code{do-all-symbols} @i{@r{(}var @r{[}result-form@r{]}@r{)}
  1656. @{@i{declaration}@}{*}
  1657. @{tag | statement@}{*}}@*
  1658. @result{} @i{@{@i{result}@}{*}}
  1659. @subsubheading Arguments and Values::
  1660. @i{var}---a @i{variable} @i{name}; not evaluated.
  1661. @i{package}---a @i{package designator}; evaluated.
  1662. The default in @b{do-symbols} and @b{do-external-symbols} is the @i{current package}.
  1663. @i{result-form}---a @i{form}; evaluated as described below.
  1664. The default is @b{nil}.
  1665. @i{declaration}---a @b{declare} @i{expression}; not evaluated.
  1666. @i{tag}---a @i{go tag}; not evaluated.
  1667. @i{statement}---a @i{compound form}; evaluated as described below.
  1668. @i{results}---the @i{values} returned by the @i{result-form}
  1669. if a @i{normal return} occurs,
  1670. or else, if an @i{explicit return} occurs, the @i{values} that were transferred.
  1671. @subsubheading Description::
  1672. @b{do-symbols},
  1673. @b{do-external-symbols}, and
  1674. @b{do-all-symbols} iterate over the @i{symbols}
  1675. of @i{packages}.
  1676. For each @i{symbol} in the set of @i{packages} chosen,
  1677. the @i{var} is bound to the @i{symbol},
  1678. and the @i{statements} in the body are executed.
  1679. When all the @i{symbols} have been processed,
  1680. @i{result-form} is evaluated and returned as the value of the macro.
  1681. @b{do-symbols} iterates
  1682. over the @i{symbols} @i{accessible} in
  1683. @i{package}.
  1684. @i{Statements} may execute more than once for @i{symbols}
  1685. that are inherited from multiple @i{packages}.
  1686. @b{do-all-symbols} iterates on every @i{registered package}.
  1687. @b{do-all-symbols} will not process every @i{symbol}
  1688. whatsoever, because a @i{symbol} not @i{accessible} in any
  1689. @i{registered package} will not be processed.
  1690. @b{do-all-symbols} may cause a @i{symbol} that is @i{present} in
  1691. several @i{packages} to be processed more than once.
  1692. @b{do-external-symbols} iterates on the external symbols of @i{package}.
  1693. When @i{result-form} is evaluated, @i{var} is bound and has the value @b{nil}.
  1694. An @i{implicit block} named @b{nil} surrounds the entire @b{do-symbols},
  1695. @b{do-external-symbols}, or @b{do-all-symbols} @i{form}.
  1696. @b{return} or @b{return-from} may be used to terminate the
  1697. iteration prematurely.
  1698. If execution of the body affects which @i{symbols}
  1699. are contained in the set of @i{packages} over which iteration
  1700. is occurring, other than to
  1701. remove the @i{symbol}
  1702. currently the value of @i{var} by using @b{unintern},
  1703. the consequences are undefined.
  1704. For each of these macros, the
  1705. @i{scope} of the name binding does not include any
  1706. initial value form, but the optional result forms are included.
  1707. Any @i{tag} in the body is treated as with @b{tagbody}.
  1708. @subsubheading Examples::
  1709. @example
  1710. (make-package 'temp :use nil) @result{} #<PACKAGE "TEMP">
  1711. (intern "SHY" 'temp) @result{} TEMP::SHY, NIL ;SHY will be an internal symbol
  1712. ;in the package TEMP
  1713. (export (intern "BOLD" 'temp) 'temp) @result{} T ;BOLD will be external
  1714. (let ((lst ()))
  1715. (do-symbols (s (find-package 'temp)) (push s lst))
  1716. lst)
  1717. @result{} (TEMP::SHY TEMP:BOLD)
  1718. @i{OR}@result{} (TEMP:BOLD TEMP::SHY)
  1719. (let ((lst ()))
  1720. (do-external-symbols (s (find-package 'temp) lst) (push s lst))
  1721. lst)
  1722. @result{} (TEMP:BOLD)
  1723. (let ((lst ()))
  1724. (do-all-symbols (s lst)
  1725. (when (eq (find-package 'temp) (symbol-package s)) (push s lst)))
  1726. lst)
  1727. @result{} (TEMP::SHY TEMP:BOLD)
  1728. @i{OR}@result{} (TEMP:BOLD TEMP::SHY)
  1729. @end example
  1730. @subsubheading See Also::
  1731. @ref{intern}
  1732. ,
  1733. @ref{export}
  1734. ,
  1735. @ref{Traversal Rules and Side Effects}
  1736. @node intern, package-name, do-symbols, Packages Dictionary
  1737. @subsection intern [Function]
  1738. @code{intern} @i{string {&optional} package} @result{} @i{symbol, status}
  1739. @subsubheading Arguments and Values::
  1740. @i{string}---a @i{string}.
  1741. @i{package}---a @i{package designator}.
  1742. The default is the @i{current package}.
  1743. @i{symbol}---a @i{symbol}.
  1744. @i{status}---one of @t{:inherited}, @t{:external}, @t{:internal}, or @b{nil}.
  1745. @subsubheading Description::
  1746. @b{intern} enters a @i{symbol} named @i{string} into @i{package}.
  1747. If a @i{symbol} whose name is the same as @i{string}
  1748. is already @i{accessible} in @i{package}, it is returned.
  1749. If no such @i{symbol} is @i{accessible} in @i{package},
  1750. a new @i{symbol} with the given name is created
  1751. and entered into @i{package} as an @i{internal symbol},
  1752. or as an @i{external symbol} if the @i{package} is the @t{KEYWORD} @i{package};
  1753. @i{package} becomes the @i{home package} of the created @i{symbol}.
  1754. The first value returned by @b{intern}, @i{symbol},
  1755. is the @i{symbol} that was found or
  1756. created.
  1757. The meaning of the @i{secondary value}, @i{status}, is as follows:
  1758. @table @asis
  1759. @item @t{:internal}
  1760. The @i{symbol} was found
  1761. and is
  1762. @i{present} in @i{package} as an @i{internal symbol}.
  1763. @item @t{:external}
  1764. The @i{symbol} was found
  1765. and is
  1766. @i{present} as an @i{external symbol}.
  1767. @item @t{:inherited}
  1768. The @i{symbol} was found
  1769. and is inherited via @b{use-package}
  1770. (which implies that the @i{symbol} is internal).
  1771. @item @b{nil}
  1772. No pre-existing @i{symbol} was found,
  1773. so one was created.
  1774. It is @i{implementation-dependent} whether the @i{string}
  1775. that becomes the new @i{symbol}'s @i{name} is the given
  1776. @i{string} or a copy of it. Once a @i{string}
  1777. has been given as the @i{string} @i{argument} to
  1778. @i{intern} in this situation where a new @i{symbol} is created,
  1779. the consequences are undefined if a
  1780. subsequent attempt is made to alter that @i{string}.
  1781. @end table
  1782. @subsubheading Examples::
  1783. @example
  1784. (in-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  1785. (intern "Never-Before") @result{} |Never-Before|, NIL
  1786. (intern "Never-Before") @result{} |Never-Before|, :INTERNAL
  1787. (intern "NEVER-BEFORE" "KEYWORD") @result{} :NEVER-BEFORE, NIL
  1788. (intern "NEVER-BEFORE" "KEYWORD") @result{} :NEVER-BEFORE, :EXTERNAL
  1789. @end example
  1790. @subsubheading See Also::
  1791. @ref{find-symbol}
  1792. ,
  1793. @ref{read; read-preserving-whitespace}
  1794. ,
  1795. @b{symbol},
  1796. @ref{unintern}
  1797. ,
  1798. @ref{Symbols as Tokens}
  1799. @subsubheading Notes::
  1800. @b{intern} does not need to do any name conflict checking
  1801. because it never creates a new @i{symbol}
  1802. if there is already an @i{accessible} @i{symbol} with the name given.
  1803. @node package-name, package-nicknames, intern, Packages Dictionary
  1804. @subsection package-name [Function]
  1805. @code{package-name} @i{package} @result{} @i{name}
  1806. @subsubheading Arguments and Values::
  1807. @i{package}---a @i{package designator}.
  1808. @i{name}---a @i{string}
  1809. or @b{nil}.
  1810. @subsubheading Description::
  1811. @b{package-name} returns the @i{string} that names @i{package},
  1812. or @b{nil} if the @i{package} @i{designator}
  1813. is a @i{package} @i{object} that has no name (see the @i{function} @b{delete-package}).
  1814. @subsubheading Examples::
  1815. @example
  1816. (in-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  1817. (package-name *package*) @result{} "COMMON-LISP-USER"
  1818. (package-name (symbol-package :test)) @result{} "KEYWORD"
  1819. (package-name (find-package 'common-lisp)) @result{} "COMMON-LISP"
  1820. @end example
  1821. @example
  1822. (defvar *foo-package* (make-package "FOO"))
  1823. (rename-package "FOO" "FOO0")
  1824. (package-name *foo-package*) @result{} "FOO0"
  1825. @end example
  1826. @subsubheading Exceptional Situations::
  1827. Should signal an error of @i{type} @b{type-error}
  1828. if @i{package} is not a @i{package designator}.
  1829. @node package-nicknames, package-shadowing-symbols, package-name, Packages Dictionary
  1830. @subsection package-nicknames [Function]
  1831. @code{package-nicknames} @i{package} @result{} @i{nicknames}
  1832. @subsubheading Arguments and Values::
  1833. @i{package}---a @i{package designator}.
  1834. @i{nicknames}---a @i{list} of @i{strings}.
  1835. @subsubheading Description::
  1836. Returns the @i{list} of nickname @i{strings}
  1837. for @i{package}, not including the name of @i{package}.
  1838. @subsubheading Examples::
  1839. @example
  1840. (package-nicknames (make-package 'temporary
  1841. :nicknames '("TEMP" "temp")))
  1842. @result{} ("temp" "TEMP")
  1843. @end example
  1844. @subsubheading Exceptional Situations::
  1845. Should signal an error of @i{type} @b{type-error}
  1846. if @i{package} is not a @i{package designator}.
  1847. @node package-shadowing-symbols, package-use-list, package-nicknames, Packages Dictionary
  1848. @subsection package-shadowing-symbols [Function]
  1849. @code{package-shadowing-symbols} @i{package} @result{} @i{symbols}
  1850. @subsubheading Arguments and Values::
  1851. @i{package}---a @i{package designator}.
  1852. @i{symbols}---a @i{list} of @i{symbols}.
  1853. @subsubheading Description::
  1854. Returns a @i{list} of @i{symbols} that have been declared
  1855. as @i{shadowing symbols} in @i{package} by @b{shadow}
  1856. or @b{shadowing-import} (or the equivalent @b{defpackage} options).
  1857. All @i{symbols} on this @i{list} are @i{present} in @i{package}.
  1858. @subsubheading Examples::
  1859. @example
  1860. (package-shadowing-symbols (make-package 'temp)) @result{} ()
  1861. (shadow 'cdr 'temp) @result{} T
  1862. (package-shadowing-symbols 'temp) @result{} (TEMP::CDR)
  1863. (intern "PILL" 'temp) @result{} TEMP::PILL, NIL
  1864. (shadowing-import 'pill 'temp) @result{} T
  1865. (package-shadowing-symbols 'temp) @result{} (PILL TEMP::CDR)
  1866. @end example
  1867. @subsubheading Exceptional Situations::
  1868. Should signal an error of @i{type} @b{type-error}
  1869. if @i{package} is not a @i{package designator}.
  1870. @subsubheading See Also::
  1871. @ref{shadow}
  1872. ,
  1873. @ref{shadowing-import}
  1874. @subsubheading Notes::
  1875. Whether the list of @i{symbols} is @i{fresh} is @i{implementation-dependent}.
  1876. @node package-use-list, package-used-by-list, package-shadowing-symbols, Packages Dictionary
  1877. @subsection package-use-list [Function]
  1878. @code{package-use-list} @i{package} @result{} @i{use-list}
  1879. @subsubheading Arguments and Values::
  1880. @i{package}---a @i{package designator}.
  1881. @i{use-list}---a @i{list} of @i{package} @i{objects}.
  1882. @subsubheading Description::
  1883. Returns a @i{list} of other @i{packages} used by @i{package}.
  1884. @subsubheading Examples::
  1885. @example
  1886. (package-use-list (make-package 'temp)) @result{} (#<PACKAGE "COMMON-LISP">)
  1887. (use-package 'common-lisp-user 'temp) @result{} T
  1888. (package-use-list 'temp) @result{} (#<PACKAGE "COMMON-LISP"> #<PACKAGE "COMMON-LISP-USER">)
  1889. @end example
  1890. @subsubheading Exceptional Situations::
  1891. Should signal an error of @i{type} @b{type-error}
  1892. if @i{package} is not a @i{package designator}.
  1893. @subsubheading See Also::
  1894. @ref{use-package}
  1895. ,
  1896. @ref{unuse-package}
  1897. @node package-used-by-list, packagep, package-use-list, Packages Dictionary
  1898. @subsection package-used-by-list [Function]
  1899. @code{package-used-by-list} @i{package} @result{} @i{used-by-list}
  1900. @subsubheading Arguments and Values::
  1901. @i{package}---a @i{package designator}.
  1902. @i{used-by-list}---a @i{list} of @i{package} @i{objects}.
  1903. @subsubheading Description::
  1904. @b{package-used-by-list} returns a @i{list}
  1905. of other @i{packages} that use @i{package}.
  1906. @subsubheading Examples::
  1907. @example
  1908. (package-used-by-list (make-package 'temp)) @result{} ()
  1909. (make-package 'trash :use '(temp)) @result{} #<PACKAGE "TRASH">
  1910. (package-used-by-list 'temp) @result{} (#<PACKAGE "TRASH">)
  1911. @end example
  1912. @subsubheading Exceptional Situations::
  1913. Should signal an error of @i{type} @b{type-error}
  1914. if @i{package} is not a @i{package}.
  1915. @subsubheading See Also::
  1916. @ref{use-package}
  1917. ,
  1918. @ref{unuse-package}
  1919. @node packagep, *package*, package-used-by-list, Packages Dictionary
  1920. @subsection packagep [Function]
  1921. @code{packagep} @i{object} @result{} @i{generalized-boolean}
  1922. @subsubheading Arguments and Values::
  1923. @i{object}---an @i{object}.
  1924. @i{generalized-boolean}---a @i{generalized boolean}.
  1925. @subsubheading Description::
  1926. Returns @i{true} if @i{object} is of @i{type} @b{package};
  1927. otherwise, returns @i{false}.
  1928. @subsubheading Examples::
  1929. @example
  1930. (packagep *package*) @result{} @i{true}
  1931. (packagep 'common-lisp) @result{} @i{false}
  1932. (packagep (find-package 'common-lisp)) @result{} @i{true}
  1933. @end example
  1934. @subsubheading Notes::
  1935. @example
  1936. (packagep @i{object}) @equiv{} (typep @i{object} 'package)
  1937. @end example
  1938. @node *package*, package-error, packagep, Packages Dictionary
  1939. @subsection *package* [Variable]
  1940. @subsubheading Value Type::
  1941. a @i{package} @i{object}.
  1942. @subsubheading Initial Value::
  1943. the @t{COMMON-LISP-USER} @i{package}.
  1944. @subsubheading Description::
  1945. Whatever @i{package} @i{object} is currently
  1946. the @i{value} of @b{*package*} is referred to as the @i{current package}.
  1947. @subsubheading Examples::
  1948. @example
  1949. (in-package "COMMON-LISP-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  1950. *package* @result{} #<PACKAGE "COMMON-LISP-USER">
  1951. (make-package "SAMPLE-PACKAGE" :use '("COMMON-LISP"))
  1952. @result{} #<PACKAGE "SAMPLE-PACKAGE">
  1953. (list
  1954. (symbol-package
  1955. (let ((*package* (find-package 'sample-package)))
  1956. (setq *some-symbol* (read-from-string "just-testing"))))
  1957. *package*)
  1958. @result{} (#<PACKAGE "SAMPLE-PACKAGE"> #<PACKAGE "COMMON-LISP-USER">)
  1959. (list (symbol-package (read-from-string "just-testing"))
  1960. *package*)
  1961. @result{} (#<PACKAGE "COMMON-LISP-USER"> #<PACKAGE "COMMON-LISP-USER">)
  1962. (eq 'foo (intern "FOO")) @result{} @i{true}
  1963. (eq 'foo (let ((*package* (find-package 'sample-package)))
  1964. (intern "FOO")))
  1965. @result{} @i{false}
  1966. @end example
  1967. @subsubheading Affected By::
  1968. @b{load},
  1969. @b{compile-file},
  1970. @b{in-package}
  1971. @subsubheading See Also::
  1972. @ref{compile-file}
  1973. ,
  1974. @ref{in-package}
  1975. ,
  1976. @ref{load}
  1977. ,
  1978. @ref{package}
  1979. @node package-error, package-error-package, *package*, Packages Dictionary
  1980. @subsection package-error [Condition Type]
  1981. @subsubheading Class Precedence List::
  1982. @b{package-error},
  1983. @b{error},
  1984. @b{serious-condition},
  1985. @b{condition},
  1986. @b{t}
  1987. @subsubheading Description::
  1988. The @i{type} @b{package-error} consists of @i{error} @i{conditions}
  1989. related to operations on @i{packages}.
  1990. The offending @i{package} (or @i{package} @i{name})
  1991. is initialized by the @t{:package} initialization argument to @b{make-condition},
  1992. and is @i{accessed} by the @i{function} @b{package-error-package}.
  1993. @subsubheading See Also::
  1994. @ref{package-error-package}
  1995. ,
  1996. @ref{Conditions}
  1997. @node package-error-package, , package-error, Packages Dictionary
  1998. @subsection package-error-package [Function]
  1999. @code{package-error-package} @i{condition} @result{} @i{package}
  2000. @subsubheading Arguments and Values::
  2001. @i{condition}---a @i{condition} of @i{type} @b{package-error}.
  2002. @i{package}---a @i{package designator}.
  2003. @subsubheading Description::
  2004. Returns a @i{designator} for the offending @i{package}
  2005. in the @i{situation} represented by the @i{condition}.
  2006. @subsubheading Examples::
  2007. @example
  2008. (package-error-package
  2009. (make-condition 'package-error
  2010. :package (find-package "COMMON-LISP")))
  2011. @result{} #<Package "COMMON-LISP">
  2012. @end example
  2013. @subsubheading See Also::
  2014. @b{package-error}
  2015. @c end of including dict-packages
  2016. @c %**end of chapter