1
0
Fork 0
cl-sites/lisp-docs.github.io/cl-language-reference/chap-11/bb-b-package-concepts.html

139 lines
61 KiB
HTML
Raw Normal View History

2024-03-13 23:00:32 +01:00
<!doctype html>
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-chap-11/bb-b-package-concepts" data-has-hydrated="false">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v3.0.1">
<title data-rh="true">11.1 Package Concepts | Common Lisp (New) Language Reference</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" name="twitter:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" property="og:url" content="https://lisp-docs.github.io/cl-language-reference/chap-11/bb-b-package-concepts"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="google-site-verification" content="Vzaw013_bfdKeUVG89Ch3W1zC9_vH9ID2dPB9Dz0vr0"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="11.1 Package Concepts | Common Lisp (New) Language Reference"><meta data-rh="true" name="description" content="11.1.1 Introduction to Packages"><meta data-rh="true" property="og:description" content="11.1.1 Introduction to Packages"><link data-rh="true" rel="icon" href="../img/favicon.ico"><link data-rh="true" rel="canonical" href="bb-b-package-concepts.html"><link data-rh="true" rel="alternate" href="bb-b-package-concepts.html" hreflang="en"><link data-rh="true" rel="alternate" href="bb-b-package-concepts.html" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://C1F2Q5VM6X-dsn.algolia.net" crossorigin="anonymous"><link rel="preconnect" href="https://www.google-analytics.com">
<link rel="preconnect" href="https://www.googletagmanager.com">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-8TJCE4NSF8"></script>
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-8TJCE4NSF8",{})</script>
<link rel="search" type="application/opensearchdescription+xml" title="Common Lisp (New) Language Reference" href="../opensearch.xml"><link rel="stylesheet" href="../assets/css/styles.f13b59fe.css">
<script src="../assets/js/runtime~main.02699c25.js" defer="defer"></script>
<script src="../assets/js/main.4f0a7a76.js" defer="defer"></script>
</head>
<body class="navigation-with-keyboard">
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="bb-b-package-concepts.html#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a href="../../index.html" target="_blank" rel="noopener noreferrer" class="navbar__brand"><div class="navbar__logo"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div><b class="navbar__title text--truncate">Common Lisp Docs</b></a><a href="../../docs/tutorial/index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Tutorial</a><a href="../index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Technical Reference</a><a href="../../docs/whylisp.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Why Lisp?</a><a href="../../docs/howto.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Guides</a></div><div class="navbar__items navbar__items--right"><a href="../../docs/contribute.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Contribute!</a><a href="../../docs/help.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Getting Help</a><a href="../../docs/about.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">About</a><a href="../../blog.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Blog</a><a href="https://github.com/lisp-docs" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.
<!-- -->
<!-- -->
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1111-introduction-to-packages">11.1.1 Introduction to Packages<a href="bb-b-package-concepts.html#1111-introduction-to-packages" class="hash-link" aria-label="Direct link to 11.1.1 Introduction to Packages" title="Direct link to 11.1.1 Introduction to Packages"></a></h2>
<!-- -->
<p>A <span><i>package</i></span> establishes a mapping from names to <span><i>symbols</i></span>. At any given time, one <span><i>package</i></span> is current. The <span><i>current package</i></span> is the one that is the <span><i>value</i></span> of <span><b>*package*</b></span>. When using the <em>Lisp reader</em> , it is possible to refer to <span><i>symbols</i></span> in <span><i>packages</i></span> other than the current one through the use of <em>package prefixes</em> in the printed representation of the <span><i>symbol</i></span>.</p>
<p>Figure 111 lists some <span><i>defined names</i></span> that are applicable to <span><i>packages</i></span>. Where an <span><i>operator</i></span> takes an argument that is either a <span><i>symbol</i></span> or a <span><i>list</i></span> of <span><i>symbols</i></span>, an argument of <span><b>nil</b></span> is treated as an empty <span><i>list</i></span> of <span><i>symbols</i></span>. Any <span><i>package</i></span> argument may be either a <span><i>string</i></span>, a <span><i>symbol</i></span>, or a <span><i>package</i></span>. If a <span><i>symbol</i></span> is supplied, its name will be used as the <span><i>package</i></span> name.</p>
<p>|<strong>*modules* import provide *package* in-package rename-package defpackage intern require do-all-symbols list-all-packages shadow do-external-symbols make-package shadowing-import do-symbols package-name unexport export package-nicknames unintern find-all-symbols package-shadowing-symbols unuse-package find-package package-use-list use-package find-symbol package-used-by-list</strong>|</p>
<p>| :- |</p>
<p><strong>Figure 111. Some Defined Names related to Packages</strong></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="11111-package-names-and-nicknames">11.1.1.1 Package Names and Nicknames<a href="bb-b-package-concepts.html#11111-package-names-and-nicknames" class="hash-link" aria-label="Direct link to 11.1.1.1 Package Names and Nicknames" title="Direct link to 11.1.1.1 Package Names and Nicknames"></a></h3>
<!-- -->
<p>Each <span><i>package</i></span> has a <span><i>name</i></span> (a <span><i>string</i></span>) and perhaps some <span><i>nicknames</i></span> (also <span><i>strings</i></span>). These are assigned when the <span><i>package</i></span> is created and can be changed later.</p>
<p>There is a single namespace for <span><i>packages</i></span>. The <span><i>function</i></span> <span><b>find-package</b></span> translates a package <span><i>name</i></span> or <span><i>nickname</i></span> into the associated <span><i>package</i></span>. The <span><i>function</i></span> <span><b>package-name</b></span> returns the <span><i>name</i></span> of a <span><i>package</i></span>. The <span><i>function</i></span> <span><b>package-nicknames</b></span> returns a <span><i>list</i></span> of all <span><i>nicknames</i></span> for a <span><i>package</i></span>. <span><b>rename-package</b></span></p>
<p>removes a <span><i>package</i></span>s current <span><i>name</i></span> and <span><i>nicknames</i></span> and replaces them with new ones specified by the caller.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="11112-symbols-in-a-package">11.1.1.2 Symbols in a Package<a href="bb-b-package-concepts.html#11112-symbols-in-a-package" class="hash-link" aria-label="Direct link to 11.1.1.2 Symbols in a Package" title="Direct link to 11.1.1.2 Symbols in a Package"></a></h3>
<!-- -->
<!-- -->
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111121-internal-and-external-symbols">11.1.1.2.1 Internal and External Symbols<a href="bb-b-package-concepts.html#111121-internal-and-external-symbols" class="hash-link" aria-label="Direct link to 11.1.1.2.1 Internal and External Symbols" title="Direct link to 11.1.1.2.1 Internal and External Symbols"></a></h4>
<!-- -->
<p>The mappings in a <span><i>package</i></span> are divided into two classes, external and internal. The <span><i>symbols</i></span> targeted by these different mappings are called <span><i>external symbols</i></span> and <span><i>internal symbols</i></span> of the <span><i>package</i></span>. Within a <span><i>package</i></span>, a name refers to one <span><i>symbol</i></span> or to none; if it does refer to a <span><i>symbol</i></span>, then it is either external or internal in that <span><i>package</i></span>, but not both. <span><i>External symbols</i></span> are part of the packages public interface to other <span><i>packages</i></span>. <span><i>Symbols</i></span> become <span><i>external symbols</i></span> of a given <span><i>package</i></span> if they have been <span><i>exported</i></span> from that <span><i>package</i></span>.</p>
<p>A <span><i>symbol</i></span> has the same <span><i>name</i></span> no matter what <span><i>package</i></span> it is <span><i>present</i></span> in, but it might be an <span><i>external symbol</i></span> of some <span><i>packages</i></span> and an <span><i>internal symbol</i></span> of others.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111122-package-inheritance">11.1.1.2.2 Package Inheritance<a href="bb-b-package-concepts.html#111122-package-inheritance" class="hash-link" aria-label="Direct link to 11.1.1.2.2 Package Inheritance" title="Direct link to 11.1.1.2.2 Package Inheritance"></a></h4>
<!-- -->
<p><span><i>Packages</i></span> can be built up in layers. From one point of view, a <span><i>package</i></span> is a single collection of mappings from <span><i>strings</i></span> into <span><i>internal symbols</i></span> and <span><i>external symbols</i></span>. However, some of these mappings might be established within the <span><i>package</i></span> itself, while other mappings are inherited from other <span><i>packages</i></span> via <span><b>use-package</b></span>. A <span><i>symbol</i></span> is said to be <span><i>present</i></span> in a <span><i>package</i></span> if the mapping is in the <span><i>package</i></span> itself and is not inherited from somewhere else.</p>
<p>There is no way to inherit the <span><i>internal symbols</i></span> of another <span><i>package</i></span>; to refer to an <span><i>internal symbol</i></span> using the <em>Lisp reader</em> , a <span><i>package</i></span> containing the <span><i>symbol</i></span> must be made to be the <span><i>current package</i></span>, a <span><i>package prefix</i></span> must be used, or the <span><i>symbol</i></span> must be <em>imported</em> into the <span><i>current package</i></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111123-accessibility-of-symbols-in-a-package">11.1.1.2.3 Accessibility of Symbols in a Package<a href="bb-b-package-concepts.html#111123-accessibility-of-symbols-in-a-package" class="hash-link" aria-label="Direct link to 11.1.1.2.3 Accessibility of Symbols in a Package" title="Direct link to 11.1.1.2.3 Accessibility of Symbols in a Package"></a></h4>
<!-- -->
<p>A <span><i>symbol</i></span> becomes <span><i>accessible</i></span> in a <span><i>package</i></span> if that is its <span><i>home package</i></span> when it is created, or if it is <em>imported</em> into that <span><i>package</i></span>, or by inheritance via <span><b>use-package</b></span>.</p>
<p>If a <span><i>symbol</i></span> is <span><i>accessible</i></span> in a <span><i>package</i></span>, it can be referred to when using the <em>Lisp reader</em> without a <span><i>package prefix</i></span> when that <span><i>package</i></span> is the <span><i>current package</i></span>, regardless of whether it is <span><i>present</i></span> or inherited.</p>
<p><span><i>Symbols</i></span> from one <span><i>package</i></span> can be made <span><i>accessible</i></span> in another <span><i>package</i></span> in two ways.</p>
<p> Any individual <span><i>symbol</i></span> can be added to a <span><i>package</i></span> by use of <span><b>import</b></span>. After the call to <span><b>import</b></span> the <span><i>symbol</i></span> is <span><i>present</i></span> in the importing <span><i>package</i></span>. The status of the <span><i>symbol</i></span> in the <span><i>package</i></span> it came from (if any) is unchanged, and the <span><i>home package</i></span> for this <span><i>symbol</i></span> is unchanged. Once <em>imported</em>, a <span><i>symbol</i></span> is <span><i>present</i></span> in the importing <span><i>package</i></span> and can be removed only by calling <span><b>unintern</b></span>.</p>
<p>A <span><i>symbol</i></span> is <em>shadowed</em> <sub>3</sub> by another <span><i>symbol</i></span> in some <span><i>package</i></span> if the first <span><i>symbol</i></span> would be <span><i>accessible</i></span> by inheritance if not for the presence of the second <span><i>symbol</i></span>. See <span><b>shadowing-import</b></span>.</p>
<p> The second mechanism for making <span><i>symbols</i></span> from one <em>package accessible</em> in another is provided by <span><b>use-package</b></span>. All of the <span><i>external symbols</i></span> of the used <span><i>package</i></span> are inherited</p>
<p>by the using <span><i>package</i></span>. The <span><i>function</i></span> <span><b>unuse-package</b></span> undoes the effects of a previous <span><b>use-package</b></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111124-locating-a-symbol-in-a-package">11.1.1.2.4 Locating a Symbol in a Package<a href="bb-b-package-concepts.html#111124-locating-a-symbol-in-a-package" class="hash-link" aria-label="Direct link to 11.1.1.2.4 Locating a Symbol in a Package" title="Direct link to 11.1.1.2.4 Locating a Symbol in a Package"></a></h4>
<!-- -->
<p>When a <span><i>symbol</i></span> is to be located in a given <span><i>package</i></span> the following occurs:</p>
<p> The <span><i>external symbols</i></span> and <span><i>internal symbols</i></span> of the <span><i>package</i></span> are searched for the <span><i>symbol</i></span>.</p>
<p> The <span><i>external symbols</i></span> of the used <span><i>packages</i></span> are searched in some unspecified order. The order does not matter; see the rules for handling name conflicts listed below.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111125-prevention-of-name-conflicts-in-packages">11.1.1.2.5 Prevention of Name Conflicts in Packages<a href="bb-b-package-concepts.html#111125-prevention-of-name-conflicts-in-packages" class="hash-link" aria-label="Direct link to 11.1.1.2.5 Prevention of Name Conflicts in Packages" title="Direct link to 11.1.1.2.5 Prevention of Name Conflicts in Packages"></a></h4>
<!-- -->
<p>Within one <span><i>package</i></span>, any particular name can refer to at most one <span><i>symbol</i></span>. A name conflict is said to occur when there would be more than one candidate <span><i>symbol</i></span>. Any time a name conflict is about to occur, a <em>correctable error</em> is signaled.</p>
<p>The following rules apply to name conflicts:</p>
<p> Name conflicts are detected when they become possible, that is, when the package structure is altered. Name conflicts are not checked during every name lookup.</p>
<p> If the <em>same symbol</em> is <span><i>accessible</i></span> to a <span><i>package</i></span> through more than one path, there is no name conflict. A <span><i>symbol</i></span> cannot conflict with itself. Name conflicts occur only between <em>distinct symbols</em> with the same name (under <span><b>string=</b></span>).</p>
<p> Every <span><i>package</i></span> has a list of shadowing <span><i>symbols</i></span>. A shadowing <span><i>symbol</i></span> takes precedence over any other <span><i>symbol</i></span> of the same name that would otherwise be <span><i>accessible</i></span> in the <span><i>package</i></span>. A name conflict involving a shadowing symbol is always resolved in favor of the shadowing <span><i>symbol</i></span>, without signaling an error (except for one exception involving <span><b>import</b></span>). See <span><b>shadow</b></span> and <span><b>shadowing-import</b></span>.</p>
<p> The functions <span><b>use-package</b></span>, <span><b>import</b></span>, and <span><b>export</b></span> check for name conflicts.</p>
<p> <span><b>shadow</b></span> and <span><b>shadowing-import</b></span> never signal a name-conflict error.</p>
<p> <span><b>unuse-package</b></span> and <span><b>unexport</b></span> do not need to do any name-conflict checking. <span><b>unintern</b></span> does name-conflict checking only when a <span><i>symbol</i></span> being <span><i>uninterned</i></span> is a <span><i>shadowing symbol</i></span>.</p>
<p> Giving a shadowing symbol to <span><b>unintern</b></span> can uncover a name conflict that had previously been resolved by the shadowing.</p>
<p> Package functions signal name-conflict errors of <span><i>type</i></span> <span><b>package-error</b></span> before making any change to the package structure. When multiple changes are to be made, it is permissible for the implementation to process each change separately. For example, when <span><b>export</b></span> is</p>
<p>given a <span><i>list</i></span> of <span><i>symbols</i></span>, aborting from a name conflict caused by the second <span><i>symbol</i></span> in the <span><i>list</i></span> might still export the first <span><i>symbol</i></span> in the <span><i>list</i></span>. However, a name-conflict error caused by <span><b>export</b></span> of a single <span><i>symbol</i></span> will be signaled before that <span><i>symbol</i></span>s <span><i>accessibility</i></span> in any <span><i>package</i></span> is changed.</p>
<p> Continuing from a name-conflict error must offer the user a chance to resolve the name conflict in favor of either of the candidates. The <span><i>package</i></span> structure should be altered to reflect the resolution of the name conflict, via <span><b>shadowing-import</b></span>, <span><b>unintern</b></span>, or <span><b>unexport</b></span>.</p>
<p> A name conflict in <span><b>use-package</b></span> between a <em>symbol present</em> in the using <span><i>package</i></span> and an <span><i>external symbol</i></span> of the used <span><i>package</i></span> is resolved in favor of the first <span><i>symbol</i></span> by making it a shadowing <span><i>symbol</i></span>, or in favor of the second <span><i>symbol</i></span> by uninterning the first <span><i>symbol</i></span> from the using <span><i>package</i></span>.</p>
<p> A name conflict in <span><b>export</b></span> or <span><b>unintern</b></span> due to a <span><i>package</i></span>s inheriting two <em>distinct symbols</em> with the <em>same name</em> (under <span><b>string=</b></span>) from two other <span><i>packages</i></span> can be resolved in favor of either <span><i>symbol</i></span> by importing it into the using <span><i>package</i></span> and making it a <span><i>shadowing symbol</i></span>, just as with <span><b>use-package</b></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1112-standardized-packages">11.1.2 Standardized Packages<a href="bb-b-package-concepts.html#1112-standardized-packages" class="hash-link" aria-label="Direct link to 11.1.2 Standardized Packages" title="Direct link to 11.1.2 Standardized Packages"></a></h2>
<!-- -->
<p>This section describes the <span><i>packages</i></span> that are available in every <span><i>conforming implementation</i></span>. A summary of the <span><i>names</i></span> and <span><i>nicknames</i></span> of those <em>standardized packages</em> is given in Figure 112.</p>
<p>|<strong>Name Nicknames</strong>|</p>
<p>| :- |</p>
<p>|</p><p>COMMON-LISP CL </p><p>COMMON-LISP-USER CL-USER </p><p>KEYWORD <em>none</em></p>|<p></p>
<p><strong>Figure 112. Standardized Package Names</strong></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="11121-the-common">11.1.2.1 The COMMON<a href="bb-b-package-concepts.html#11121-the-common" class="hash-link" aria-label="Direct link to 11.1.2.1 The COMMON" title="Direct link to 11.1.2.1 The COMMON"></a></h3>
<!-- -->
<p>The COMMON-LISP <span><i>package</i></span> contains the primitives of the Common Lisp system as defined by this specification. Its <span><i>external symbols</i></span> include all of the <span><i>defined names</i></span> (except for <span><i>defined names</i></span> in the KEYWORD <span><i>package</i></span>) that are present in the Common Lisp system, such as <span><b>car</b></span>, <span><b>cdr</b></span>, <span><b>*package*</b></span>, etc. The COMMON-LISP <span><i>package</i></span> has the <span><i>nickname</i></span> CL.</p>
<p>The COMMON-LISP <span><i>package</i></span> has as <span><i>external symbols</i></span> those symbols enumerated in the figures in Section 1.9 (Symbols in the COMMON-LISP Package), and no others. These <span><i>external symbols</i></span> are <span><i>present</i></span> in the COMMON-LISP <span><i>package</i></span> but their <span><i>home package</i></span> need not be the COMMON-LISP <span><i>package</i></span>.</p>
<p>For example, the symbol HELP cannot be an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> because it is not mentioned in Section 1.9 (Symbols in the COMMON-LISP Package). In contrast, the <span><i>symbol</i></span></p>
<p><strong>variable</strong> must be an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> even though it has no definition because it is listed in that section (to support its use as a valid second <span><i>argument</i></span> to the <span><i>function</i></span> <strong>documentation</strong>).</p>
<p>The COMMON-LISP <span><i>package</i></span> can have additional <span><i>internal symbols</i></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111211-constraints-on-the-common">11.1.2.1.1 Constraints on the COMMON<a href="bb-b-package-concepts.html#111211-constraints-on-the-common" class="hash-link" aria-label="Direct link to 11.1.2.1.1 Constraints on the COMMON" title="Direct link to 11.1.2.1.1 Constraints on the COMMON"></a></h4>
<!-- -->
<p>In a <span><i>conforming implementation</i></span>, an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> can have a <span><i>function</i></span>, <span><i>macro</i></span>, or <span><i>special operator</i></span> definition, a <span><i>global variable</i></span> definition (or other status as a <span><i>dynamic variable</i></span> due to a <span><b>special</b></span> <span><i>proclamation</i></span>), or a <span><i>type</i></span> definition only if explicitly permitted in this standard. For example, <span><b>fboundp</b></span> <em>yields false</em> for any <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> that is not the <span><i>name</i></span> of a <em>standardized function</em>, <span><i>macro</i></span> or <span><i>special operator</i></span> , and <span><b>boundp</b></span> returns <span><i>false</i></span> for any <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> that is not the <span><i>name</i></span> of a <em>standardized global variable</em>. It also follows that <span><i>conforming programs</i></span> can use <span><i>external symbols</i></span> of the COMMON-LISP <span><i>package</i></span> as the <span><i>names</i></span> of local <span><i>lexical variables</i></span> with confidence that those <span><i>names</i></span> have not been <em>proclaimed</em> <span><b>special</b></span> by the <span><i>implementation</i></span> unless those <span><i>symbols</i></span> are <span><i>names</i></span> of <em>standardized global variables</em>.</p>
<p>A <span><i>conforming implementation</i></span> must not place any <span><i>property</i></span> on an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> using a <span><i>property indicator</i></span> that is either an <span><i>external symbol</i></span> of any <em>standardized package</em> or a <span><i>symbol</i></span> that is otherwise <span><i>accessible</i></span> in the COMMON-LISP-USER <span><i>package</i></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111212-constraints-on-the-common">11.1.2.1.2 Constraints on the COMMON<a href="bb-b-package-concepts.html#111212-constraints-on-the-common" class="hash-link" aria-label="Direct link to 11.1.2.1.2 Constraints on the COMMON" title="Direct link to 11.1.2.1.2 Constraints on the COMMON"></a></h4>
<!-- -->
<p>Except where explicitly allowed, the consequences are undefined if any of the following actions are performed on an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span>:</p>
<p>1. <span><i>Binding</i></span> or altering its value (lexically or dynamically). (Some exceptions are noted below.) 2. Defining, undefining, or <span><i>binding</i></span> it as a <span><i>function</i></span>. (Some exceptions are noted below.)</p>
<p>3. Defining, undefining, or <span><i>binding</i></span> it as a <span><i>macro</i></span> or <span><i>compiler macro</i></span>. (Some exceptions are noted below.)</p>
<p>4. Defining it as a <span><i>type specifier</i></span> (via <span><b>defstruct</b></span>, <span><b>defclass</b></span>, <span><b>deftype</b></span>, <span><b>define-condition</b></span>). 5. Defining it as a structure (via <span><b>defstruct</b></span>).</p>
<p>6. Defining it as a <span><i>declaration</i></span> with a <span><b>declaration</b></span> <span><i>proclamation</i></span>.</p>
<p>7. Defining it as a <span><i>symbol macro</i></span>.</p>
<p>8. Altering its <span><i>home package</i></span>.</p>
<p>9. Tracing it (via <span><b>trace</b></span>).</p>
<p>10. Declaring or proclaiming it <span><b>special</b></span> (via <span><b>declare</b></span>, <span><b>declaim</b></span>, or <span><b>proclaim</b></span>).</p>
<p>11. Declaring or proclaiming its <span><b>type</b></span> or <span><b>ftype</b></span> (via <span><b>declare</b></span>, <span><b>declaim</b></span>, or <span><b>proclaim</b></span>). (Some exceptions are noted below.)</p>
<p>12. Removing it from the COMMON-LISP <span><i>package</i></span>.</p>
<p>13. Defining a <span><i>setf expander</i></span> for it (via <span><b>defsetf</b></span> or <strong>define-setf-method</strong>).</p>
<p>14. Defining, undefining, or binding its <span><i>setf function name</i></span>.</p>
<p>15. Defining it as a <span><i>method combination</i></span> type (via <span><b>define-method-combination</b></span>).</p>
<p>16. Using it as the class-name argument to <span><b>setf</b></span> of <span><b>find-class</b></span>.</p>
<p>17. Binding it as a <span><i>catch tag</i></span>.</p>
<p>18. Binding it as a <em>restart name</em>.</p>
<p>19. Defining a <span><i>method</i></span> for a <em>standardized generic function</em> which is <span><i>applicable</i></span> when all of the <span><i>arguments</i></span> are <span><i>direct instances</i></span> of <em>standardized classes</em>.</p>
<h5 class="anchor anchorWithStickyNavbar_LWe7" id="1112121-some-exceptions-to-constraints-on-the-common">11.1.2.1.2.1 Some Exceptions to Constraints on the COMMON<a href="bb-b-package-concepts.html#1112121-some-exceptions-to-constraints-on-the-common" class="hash-link" aria-label="Direct link to 11.1.2.1.2.1 Some Exceptions to Constraints on the COMMON" title="Direct link to 11.1.2.1.2.1 Some Exceptions to Constraints on the COMMON"></a></h5>
<!-- -->
<p>If an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> is not globally defined as a <em>standardized dynamic variable</em> or <span><i>constant variable</i></span>, it is allowed to lexically <span><i>bind</i></span> it and to declare the <span><b>type</b></span> of that <span><i>binding</i></span>, and it is allowed to locally <span><i>establish</i></span> it as a <span><i>symbol macro</i></span> (<em>e.g.</em>, with <span><b>symbol-macrolet</b></span>).</p>
<p>Unless explicitly specified otherwise, if an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> is globally defined as a <em>standardized dynamic variable</em>, it is permitted to <span><i>bind</i></span> or <span><i>assign</i></span> that <span><i>dynamic variable</i></span> provided that the “Value Type” constraints on the <span><i>dynamic variable</i></span> are maintained, and that the new <span><i>value</i></span> of the <span><i>variable</i></span> is consistent with the stated purpose of the <span><i>variable</i></span>.</p>
<p>If an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> is not defined as a <em>standardized function</em>, <span><i>macro</i></span>, or <span><i>special operator</i></span> , it is allowed to lexically <span><i>bind</i></span> it as a <span><i>function</i></span> (<em>e.g.</em>, with <span><b>flet</b></span>), to declare the <span><b>ftype</b></span> of that <span><i>binding</i></span>, and (in <span><i>implementations</i></span> which provide the ability to do so) to <span><b>trace</b></span> that <span><i>binding</i></span>.</p>
<p>If an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> is not defined as a <em>standardized function</em>, <span><i>macro</i></span>, or <span><i>special operator</i></span> , it is allowed to lexically <span><i>bind</i></span> it as a <span><i>macro</i></span> (<em>e.g.</em>, with <span><b>macrolet</b></span>).</p>
<p>If an <span><i>external symbol</i></span> of the COMMON-LISP <span><i>package</i></span> is not defined as a <em>standardized function</em>, <span><i>macro</i></span>, or <span><i>special operator</i></span> , it is allowed to lexically <span><i>bind</i></span> its <span><i>setf function name</i></span> as a <span><i>function</i></span>, and to declare the <span><b>ftype</b></span> of that <span><i>binding</i></span>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="11122-the-common">11.1.2.2 The COMMON<a href="bb-b-package-concepts.html#11122-the-common" class="hash-link" aria-label="Direct link to 11.1.2.2 The COMMON" title="Direct link to 11.1.2.2 The COMMON"></a></h3>
<!-- -->
<p>The COMMON-LISP-USER <span><i>package</i></span> is the <span><i>current package</i></span> when a Common Lisp system starts up. This <em>package uses</em> the COMMON-LISP <span><i>package</i></span>. The COMMON-LISP-USER <span><i>package</i></span> has the <span><i>nickname</i></span> CL-USER. The COMMON-LISP-USER <span><i>package</i></span> can have additional <em>symbols interned</em> within it; it can <span><i>use</i></span> other <em>implementation-defined packages</em>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="11123-the-keyword-package">11.1.2.3 The KEYWORD Package<a href="bb-b-package-concepts.html#11123-the-keyword-package" class="hash-link" aria-label="Direct link to 11.1.2.3 The KEYWORD Package" title="Direct link to 11.1.2.3 The KEYWORD Package"></a></h3>
<!-- -->
<p>The KEYWORD <span><i>package</i></span> contains <span><i>symbols</i></span>, called <span><i>keywords</i></span><sub>1</sub>, that are typically used as special markers in <span><i>programs</i></span> and their associated data <span><i>expressions</i></span><sub>1</sub>.</p>
<p><em>Symbol tokens</em> that start with a <span><i>package marker</i></span> are parsed by the <em>Lisp reader</em> as <span><i>symbols</i></span> in the KEYWORD <span><i>package</i></span>; see Section 2.3.4 (Symbols as Tokens). This makes it notationally convenient to use <span><i>keywords</i></span> when communicating between programs in different <span><i>packages</i></span>. For example, the mechanism for passing <span><i>keyword parameters</i></span> in a <span><i>call</i></span> uses <span><i>keywords</i></span><sub>1</sub> to name the corresponding <span><i>arguments</i></span>; see Section 3.4.1 (Ordinary Lambda Lists).</p>
<p><span><i>Symbols</i></span> in the KEYWORD <span><i>package</i></span> are, by definition, of <span><i>type</i></span> <span><b>keyword</b></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111231-interning-a-symbol-in-the-keyword-package">11.1.2.3.1 Interning a Symbol in the KEYWORD Package<a href="bb-b-package-concepts.html#111231-interning-a-symbol-in-the-keyword-package" class="hash-link" aria-label="Direct link to 11.1.2.3.1 Interning a Symbol in the KEYWORD Package" title="Direct link to 11.1.2.3.1 Interning a Symbol in the KEYWORD Package"></a></h4>
<!-- -->
<p>The KEYWORD <span><i>package</i></span> is treated differently than other <span><i>packages</i></span> in that special actions are taken when a <span><i>symbol</i></span> is <span><i>interned</i></span> in it. In particular, when a <span><i>symbol</i></span> is <span><i>interned</i></span> in the KEYWORD <span><i>package</i></span>, it is automatically made to be an <span><i>external symbol</i></span> and is automatically made to be a <span><i>constant variable</i></span> with itself as a <span><i>value</i></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="111232-notes-about-the-keyword-package">11.1.2.3.2 Notes about The KEYWORD Package<a href="bb-b-package-concepts.html#111232-notes-about-the-keyword-package" class="hash-link" aria-label="Direct link to 11.1.2.3.2 Notes about The KEYWORD Package" title="Direct link to 11.1.2.3.2 Notes about The KEYWORD Package"></a></h4>
<!-- -->
<p>It is generally best to confine the use of <span><i>keywords</i></span> to situations in which there are a finitely enumerable set of names to be selected between. For example, if there were two states of a light switch, they might be called <!-- -->:on<!-- --> and <!-- -->:off<!-- -->.</p>
<p>In situations where the set of names is not finitely enumerable (<em>i.e.</em>, where name conflicts might arise) it is frequently best to use <span><i>symbols</i></span> in some <span><i>package</i></span> other than KEYWORD so that conflicts will be naturally avoided. For example, it is generally not wise for a <span><i>program</i></span> to use a <span><i>keyword</i></span> <sub>1</sub> as a <span><i>property indicator</i></span> , since if there were ever another <span><i>program</i></span> that did the same thing, each would clobber the others data.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="11124-implementation">11.1.2.4 Implementation<a href="bb-b-package-concepts.html#11124-implementation" class="hash-link" aria-label="Direct link to 11.1.2.4 Implementation" title="Direct link to 11.1.2.4 Implementation"></a></h3>
<!-- -->
<!-- -->
<p>Other, <em>implementation-defined packages</em> might be present in the initial Common Lisp environment.</p>
<p>It is recommended, but not required, that the documentation for a <span><i>conforming implementation</i></span> contain a full list of all <span><i>package</i></span> names initially present in that <span><i>implementation</i></span> but not specified in this specification. (See also the <span><i>function</i></span> <span><b>list-all-packages</b></span>.)</p></div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/lisp-docs/cl-language-reference/tree/main/docs/chap-11/bb-b-package-concepts.md" target="_blank" rel="noopener noreferrer" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col lastUpdated_vwxv"><span class="theme-last-updated">Last updated<!-- --> by <b>daninus14</b></span></div></div></footer></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href="../chap-10/ba-c-dictionary/unbound-variable_condition-type.html"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">unbound-variable</div></a><a class="pagination-nav__link pagination-nav__link--next" href="../category/112-packages-dictionary.html"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">11.2 Packages Dictionary</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="bb-b-package-concepts.html#1111-introduction-to-packages" class="table-of-contents__link toc-highlight">11.1.1 Introduction to Packages</a><ul><li><a href="bb-b-package-concepts.html#11111-package-names-and-nicknames" class="table-of-contents__link toc-highlight">11.1.1.1 Package Names and Nicknames</a></li><li><a href="bb-b-package-concepts.html#11112-symbols-in-a-package" class="table-of-contents__link toc-highlight">11.1.1.2 Symbols in a Package</a><ul><li><a href="bb-b-package-concepts.html#111121-internal-and-external-symbols" class="table-of-contents__link toc-highlight">11.1.1.2.1 Internal and External Symbols</a></li><li><a href="bb-b-package-concepts.html#111122-package-inheritance" class="table-of-contents__link toc-highlight">11.1.1.2.2 Package Inheritance</a></li><li><a href="bb-b-package-concepts.html#111123-accessibility-of-symbols-in-a-package" class="table-of-contents__link toc-highlight">11.1.1.2.3 Accessibility of Symbols in a Package</a></li><li><a href="bb-b-package-concepts.html#111124-locating-a-symbol-in-a-package" class="table-of-contents__link toc-highlight">11.1.1.2.4 Locating a Symbol in a Package</a></li><li><a href="bb-b-package-concepts.html#111125-prevention-of-name-conflicts-in-packages" class="table-of-contents__link toc-highlight">11.1.1.2.5 Prevention of Name Conflicts in Packages</a></li></ul></li></ul></li><li><a href="bb-b-package-concepts.html#1112-standardized-packages" class="table-of-contents__link toc-highlight">11.1.2 Standardized Packages</a><ul><li><a href="bb-b-package-concepts.html#11121-the-common" class="table-of-contents__link toc-highlight">11.1.2.1 The COMMON</a><ul><li><a href="bb-b-package-concepts.html#111211-constraints-on-the-common" class="table-of-contents__link toc-highlight">11.1.2.1.1 Constraints on the COMMON</a></li><li><a href="bb-b-package-concepts.html#111212-constraints-on-the-common" class="table-of-contents__link toc-highlight">11.1.2.1.2 Constraints on the COMMON</a><ul><li><a href="bb-b-package-concepts.html#1112121-some-exceptions-to-constraints-on-the-common" class="table-of-contents__link toc-highlight">11.1.2.1.2.1 Some Exceptions to Constraints on the COMMON</a></li></ul></li></ul></li><li><a href="bb-b-package-concepts.html#11122-the-common"
</body>
</html>