1
0
Fork 0
cl-sites/lisp-docs.github.io/cl-language-reference/chap-7/h-b-object-creation-and-initialization.html

131 lines
No EOL
61 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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-7/h-b-object-creation-and-initialization" data-has-hydrated="false">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v3.0.1">
<title data-rh="true">7.1 Object Creation and Initialization | 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-7/h-b-object-creation-and-initialization"><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="7.1 Object Creation and Initialization | Common Lisp (New) Language Reference"><meta data-rh="true" name="description" content="7.1.1 Initialization Arguments"><meta data-rh="true" property="og:description" content="7.1.1 Initialization Arguments"><link data-rh="true" rel="icon" href="../img/favicon.ico"><link data-rh="true" rel="canonical" href="h-b-object-creation-and-initialization.html"><link data-rh="true" rel="alternate" href="h-b-object-creation-and-initialization.html" hreflang="en"><link data-rh="true" rel="alternate" href="h-b-object-creation-and-initialization.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="h-b-object-creation-and-initialization.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.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="navbarSearchContainer_Bca1"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><div class="docsWrapper_hBAB"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docRoot_UBD9"><aside class="theme-doc-sidebar-container docSidebarContainer_YfHR"><div class="sidebarViewport_aRkj"><div class="sidebar_njMd"><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="../index.html">Introduction</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-0/intro.html">Contents and Figures</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-1/b-b-scope-purpose-and-history.html">1. Introduction</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-2/c-b-character-syntax.html">2. Syntax</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-3/d-b-evaluation.html">3. Evaluation and Compilation</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-4/e-b-introduction.html">4. Types and Classes</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-5/f-b-generalized-reference.html">5. Data and Control Flow</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-6/g-b-the-loop-facility.html">6. Iteration</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" aria-expanded="true" href="h-b-object-creation-and-initialization.html">7. Objects</a></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link menu__link--active" aria-current="page" tabindex="0" href="h-b-object-creation-and-initialization.html">7.1 Object Creation and Initialization</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="h-c-changing-the-class-of-an-instance.html">7.2 Changing the Class of an Instance</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="h-d-reinitializing-an-instance.html">7.3 Reinitializing an Instance</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="h-e-metaobjects.html">7.4 Meta</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="h-f-slots.html">7.5 Slots</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="h-g-generic-functions-and-methods.html">7.6 Generic Functions and Methods</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="../category/77-objects-dictionary.html">7.7 Objects Dictionary</a><button aria-label="Expand sidebar category &#x27;7.7 Objects Dictionary&#x27;" type="button" class="clean-btn menu__caret"></button></div></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../category/81-structures-dictionary.html">8. Structures</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-9/j-b-condition-system-concepts.html">9. Conditions</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-10/ba-b-symbol-concepts.html">10. Symbols</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-11/bb-b-package-concepts.html">11. Packages</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-12/bc-b-number-concepts.html">12. Numbers</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-13/bd-b-character-concepts.html">13. Characters</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-14/be-b-cons-concepts.html">14. Conses</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-15/bf-b-array-concepts.html">15. Arrays</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-16/bg-b-string-concepts.html">16. Strings</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-17/bh-b-sequence-concepts.html">17. Sequences</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-18/bi-b-hash-table-concepts.html">18. Hash Tables</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-19/bj-b-overview-of-filenames.html">19. Filenames</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-20/ca-b-file-system-concepts.html">20. Files</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-21/cb-b-stream-concepts.html">21. Streams</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-22/cc-b-the-lisp-printer.html">22. Printer</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-23/cd-b-reader-concepts.html">23. Reader</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-24/ce-b-system-construction-concepts.html">24. System Construction</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-25/cf-b-the-external-environment.html">25. External Environment</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../environments.html">26. Environments</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../meta-object-protocol.html">27. Meta Object Protocol</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../data-structures.html">28. Data Structures</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../portability/trivial-packages.html">29. Portability</a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="../dictionary-entries.html">dictionary-entries</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-26/intro.html">Glossary</a></div></li></ul></nav></div></div></aside><main class="docMainContainer_TBSr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_VOVn"><div class="docItemContainer_Djhp"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label="Breadcrumbs"><ul class="breadcrumbs" itemscope="" itemtype="https://schema.org/BreadcrumbList"><li class="breadcrumbs__item"><a aria-label="Home page" class="breadcrumbs__link" href="../index.html"><svg viewBox="0 0 24 24" class="breadcrumbHomeIcon_YNFT"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li class="breadcrumbs__item"><span class="breadcrumbs__link">7. Objects</span><meta itemprop="position" content="1"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link" itemprop="name">7.1 Object Creation and Initialization</span><meta itemprop="position" content="2"></li></ul></nav><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><h1>7.1 Object Creation and Initialization</h1>
<!-- -->
<p>The <span><i>generic function</i></span> <span><b>make-instance</b></span> creates and returns a new <span><i>instance</i></span> of a <span><i>class</i></span>. The first argument is a <span><i>class</i></span> or the <span><i>name</i></span> of a <span><i>class</i></span>, and the remaining arguments form an <span><i>initialization argument list</i></span>.</p>
<p>The initialization of a new <span><i>instance</i></span> consists of several distinct steps, including the following: combining the explicitly supplied initialization arguments with default values for the unsupplied initialization arguments, checking the validity of the initialization arguments, allocating storage for the <span><i>instance</i></span>, filling <span><i>slots</i></span> with values, and executing user-supplied <span><i>methods</i></span> that perform additional initialization. Each step of <span><b>make-instance</b></span> is implemented by a <span><i>generic function</i></span> to provide a mechanism for customizing that step. In addition, <span><b>make-instance</b></span> is itself a <span><i>generic function</i></span> and thus also can be customized.</p>
<p>The object system specifies system-supplied primary <span><i>methods</i></span> for each step and thus specifies a well-defined standard behavior for the entire initialization process. The standard behavior provides four simple mechanisms for controlling initialization:</p>
<p><em></em> Declaring a <span><i>symbol</i></span> to be an initialization argument for a <span><i>slot</i></span>. An initialization argument is declared by using the <!-- -->:initarg<!-- --> slot option to <span><b>defclass</b></span>. This provides a mechanism for supplying a value for a <span><i>slot</i></span> in a call to <span><b>make-instance</b></span>.</p>
<p><em></em> Supplying a default value form for an initialization argument. Default value forms for initialization arguments are defined by using the <!-- -->:default-initargs<!-- --> class option to <span><b>defclass</b></span>. If an initialization argument is not explicitly provided as an argument to <span><b>make-instance</b></span>, the default value form is evaluated in the lexical environment of the <span><b>defclass</b></span> form that defined it, and the resulting value is used as the value of the initialization argument.</p>
<p><em></em> Supplying a default initial value form for a <span><i>slot</i></span>. A default initial value form for a <span><i>slot</i></span> is defined by using the <!-- -->:initform<!-- --> slot option to <span><b>defclass</b></span>. If no initialization argument associated with that <span><i>slot</i></span> is given as an argument to <span><b>make-instance</b></span> or is defaulted by <!-- -->:default-initargs<!-- -->, this default initial value form is evaluated in the lexical environment</p>
<p>of the <span><b>defclass</b></span> form that defined it, and the resulting value is stored in the <span><i>slot</i></span>. The <!-- -->:initform<!-- --> form for a <span><i>local slot</i></span> may be used when creating an <span><i>instance</i></span>, when updating an <span><i>instance</i></span> to conform to a redefined <span><i>class</i></span>, or when updating an <span><i>instance</i></span> to conform to the definition of a different <span><i>class</i></span>. The <!-- -->:initform<!-- --> form for a <span><i>shared slot</i></span> may be used when defining or re-defining the <span><i>class</i></span>.</p>
<p><em></em> Defining <span><i>methods</i></span> for <span><b>initialize-instance</b></span> and <span><b>shared-initialize</b></span>. The slot-filling behavior described above is implemented by a system-supplied primary <span><i>method</i></span> for <span><b>initialize-instance</b></span> which invokes <span><b>shared-initialize</b></span>. The <span><i>generic function</i></span> <span><b>shared-initialize</b></span> implements the parts of initialization shared by these four situations: when making an <span><i>instance</i></span>, when re-initializing an <span><i>instance</i></span>, when updating an <span><i>instance</i></span> to conform to a redefined <span><i>class</i></span>, and when updating an <span><i>instance</i></span> to conform to the definition of a different <span><i>class</i></span>. The system-supplied primary <span><i>method</i></span> for <span><b>shared-initialize</b></span> directly implements the slot-filling behavior described above, and <span><b>initialize-instance</b></span> simply invokes <span><b>shared-initialize</b></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="711-initialization-arguments">7.1.1 Initialization Arguments<a href="h-b-object-creation-and-initialization.html#711-initialization-arguments" class="hash-link" aria-label="Direct link to 7.1.1 Initialization Arguments" title="Direct link to 7.1.1 Initialization Arguments"></a></h2>
<!-- -->
<p>An initialization argument controls <span><i>object</i></span> creation and initialization. It is often convenient to use keyword <span><i>symbols</i></span> to name initialization arguments, but the <span><i>name</i></span> of an initialization argument can be any <span><i>symbol</i></span>, including <span><b>nil</b></span>. An initialization argument can be used in two ways: to fill a <span><i>slot</i></span> with</p>
<p>a value or to provide an argument for an initialization <span><i>method</i></span>. A single initialization argument can be used for both purposes.</p>
<p>An <span><i>initialization argument list</i></span> is a <span><i>property list</i></span> of initialization argument names and values. Its structure is identical to a <span><i>property list</i></span> and also to the portion of an argument list processed for <strong>&amp;key</strong> parameters. As in those lists, if an initialization argument name appears more than once in an initialization argument list, the leftmost occurrence supplies the value and the remaining</p>
<p>occurrences are ignored. The arguments to <span><b>make-instance</b></span> (after the first argument) form an <span><i>initialization argument list</i></span>.</p>
<p>An initialization argument can be associated with a <span><i>slot</i></span>. If the initialization argument has a value in the <span><i>initialization argument list</i></span>, the value is stored into the <span><i>slot</i></span> of the newly created <span><i>object</i></span>, overriding any <!-- -->:initform<!-- --> form associated with the <span><i>slot</i></span>. A single initialization argument can initialize more than one <span><i>slot</i></span>. An initialization argument that initializes a <span><i>shared slot</i></span> stores its value into the <span><i>shared slot</i></span>, replacing any previous value.</p>
<p>An initialization argument can be associated with a <span><i>method</i></span>. When an <span><i>object</i></span> is created and a particular initialization argument is supplied, the <span><i>generic functions</i></span> <span><b>initialize-instance</b></span>, <span><b>shared-initialize</b></span>, and <span><b>allocate-instance</b></span> are called with that initialization arguments name and value as a keyword argument pair. If a value for the initialization argument is not supplied in the <span><i>initialization argument list</i></span>, the <span><i>method</i></span>s <span><i>lambda list</i></span> supplies a default value.</p>
<p>Initialization arguments are used in four situations: when making an <span><i>instance</i></span>, when re-initializing an <span><i>instance</i></span>, when updating an <span><i>instance</i></span> to conform to a redefined <span><i>class</i></span>, and when updating an <span><i>instance</i></span> to conform to the definition of a different <span><i>class</i></span>.</p>
<p>Because initialization arguments are used to control the creation and initialization of an <span><i>instance</i></span> of some particular <span><i>class</i></span>, we say that an initialization argument is “an initialization argument for” that <span><i>class</i></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="712-declaring-the-validity-of-initialization-arguments">7.1.2 Declaring the Validity of Initialization Arguments<a href="h-b-object-creation-and-initialization.html#712-declaring-the-validity-of-initialization-arguments" class="hash-link" aria-label="Direct link to 7.1.2 Declaring the Validity of Initialization Arguments" title="Direct link to 7.1.2 Declaring the Validity of Initialization Arguments"></a></h2>
<!-- -->
<p>Initialization arguments are checked for validity in each of the four situations that use them. An initialization argument may be valid in one situation and not another. For example, the system-supplied primary <span><i>method</i></span> for <span><b>make-instance</b></span> defined for the <span><i>class</i></span> <span><b>standard-class</b></span> checks the validity of its initialization arguments and signals an error if an initialization argument is supplied that is not declared as valid in that situation.</p>
<p>There are two means for declaring initialization arguments valid.</p>
<p><em></em> Initialization arguments that fill <span><i>slots</i></span> are declared as valid by the <!-- -->:initarg<!-- --> slot option to <span><b>defclass</b></span>. The <!-- -->:initarg<!-- --> slot option is inherited from <em>superclasses</em>. Thus the set of valid</p>
<p>initialization arguments that fill <span><i>slots</i></span> for a <span><i>class</i></span> is the union of the initialization arguments that fill <span><i>slots</i></span> declared as valid by that <span><i>class</i></span> and its <em>superclasses</em>. Initialization arguments that fill <span><i>slots</i></span> are valid in all four contexts.</p>
<p><em></em> Initialization arguments that supply arguments to <span><i>methods</i></span> are declared as valid by defining those <span><i>methods</i></span>. The keyword name of each keyword parameter specified in the <span><i>method</i></span>s <span><i>lambda list</i></span> becomes an initialization argument for all <em>classes</em> for which the <span><i>method</i></span> is applicable. The presence of &amp;allow-other-keys in the <span><i>lambda list</i></span> of an applicable method disables validity checking of initialization arguments. Thus <span><i>method</i></span> inheritance controls the set of valid initialization arguments that supply arguments to <span><i>methods</i></span>. The <span><i>generic functions</i></span> for which <span><i>method</i></span> definitions serve to declare initialization arguments valid are as follows:</p>
<p> Making an <span><i>instance</i></span> of a <span><i>class</i></span>: <span><b>allocate-instance</b></span>, <span><b>initialize-instance</b></span>, and</p>
<p><span><b>shared-initialize</b></span>. Initialization arguments declared as valid by these <span><i>methods</i></span> are</p>
<p>valid when making an <span><i>instance</i></span> of a <span><i>class</i></span>.</p>
<p> Re-initializing an <span><i>instance</i></span>: <span><b>reinitialize-instance</b></span> and <span><b>shared-initialize</b></span>. Initializa tion arguments declared as valid by these <span><i>methods</i></span> are valid when re-initializing an</p>
<p><span><i>instance</i></span>.</p>
<p> Updating an <span><i>instance</i></span> to conform to a redefined <span><i>class</i></span>:</p>
<p><strong>update-instance-for-redefined-class</strong> and <span><b>shared-initialize</b></span>. Initialization ar</p>
<p>guments declared as valid by these <span><i>methods</i></span> are valid when updating an <span><i>instance</i></span></p>
<p>to conform to a redefined <span><i>class</i></span>.</p>
<p> Updating an <span><i>instance</i></span> to conform to the definition of a different <span><i>class</i></span>:</p>
<p><strong>update-instance-for-different-class</strong> and <span><b>shared-initialize</b></span>. Initialization</p>
<p>arguments declared as valid by these <span><i>methods</i></span> are valid when updating an <span><i>instance</i></span></p>
<p>to conform to the definition of a different <span><i>class</i></span>.</p>
<p>The set of valid initialization arguments for a <span><i>class</i></span> is the set of valid initialization arguments that either fill <span><i>slots</i></span> or supply arguments to <span><i>methods</i></span>, along with the predefined initialization argument <!-- -->:allow-other-keys<!-- -->. The default value for <!-- -->:allow-other-keys<!-- --> is <span><b>nil</b></span>. Validity checking of initialization arguments is disabled if the value of the initialization argument <!-- -->:allow-other-keys<!-- --> is <span><i>true</i></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="713-defaulting-of-initialization-arguments">7.1.3 Defaulting of Initialization Arguments<a href="h-b-object-creation-and-initialization.html#713-defaulting-of-initialization-arguments" class="hash-link" aria-label="Direct link to 7.1.3 Defaulting of Initialization Arguments" title="Direct link to 7.1.3 Defaulting of Initialization Arguments"></a></h2>
<!-- -->
<p>A default value <span><i>form</i></span> can be supplied for an initialization argument by using the <!-- -->:default-initargs<!-- --> <span><i>class</i></span> option. If an initialization argument is declared valid by some particular <span><i>class</i></span>, its default value form might be specified by a different <span><i>class</i></span>. In this case <!-- -->:default-initargs<!-- --> is used to supply a default value for an inherited initialization argument.</p>
<p>The <!-- -->:default-initargs<!-- --> option is used only to provide default values for initialization arguments; it does not declare a <span><i>symbol</i></span> as a valid initialization argument name. Furthermore, the <!-- -->:default-initargs<!-- --> option is used only to provide default values for initialization arguments when making an <span><i>instance</i></span>.</p>
<p>The argument to the <!-- -->:default-initargs<!-- --> class option is a list of alternating initialization argument names and <span><i>forms</i></span>. Each <span><i>form</i></span> is the default value form for the corresponding initialization argument. The default value <span><i>form</i></span> of an initialization argument is used and evaluated only if that initialization argument does not appear in the arguments to <span><b>make-instance</b></span> and is not defaulted by a more specific <span><i>class</i></span>. The default value <span><i>form</i></span> is evaluated in the lexical environment of the <span><b>defclass</b></span> form that supplied it; the resulting value is used as the initialization arguments value.</p>
<p>The initialization arguments supplied to <span><b>make-instance</b></span> are combined with defaulted initialization arguments to produce a <em>defaulted initialization argument list</em>. A <em>defaulted initialization argument list</em> is a list of alternating initialization argument names and values in which unsupplied initialization arguments are defaulted and in which the explicitly supplied initialization arguments appear earlier</p>
<p>in the list than the defaulted initialization arguments. Defaulted initialization arguments are ordered according to the order in the <span><i>class precedence list</i></span> of the <em>classes</em> that supplied the default values.</p>
<p>There is a distinction between the purposes of the <!-- -->:default-initargs<!-- --> and the <!-- -->:initform<!-- --> options with respect to the initialization of <span><i>slots</i></span>. The <!-- -->:default-initargs<!-- --> class option provides a mechanism for the user to give a default value <span><i>form</i></span> for an initialization argument without knowing whether the initialization argument initializes a <span><i>slot</i></span> or is passed to a <span><i>method</i></span>. If that initialization argument is not explicitly supplied in a call to <span><b>make-instance</b></span>, the default value <span><i>form</i></span> is used, just as if it had been supplied in the call. In contrast, the <!-- -->:initform<!-- --> slot option provides a mechanism for the user to give a default initial value form for a <span><i>slot</i></span>. An <!-- -->:initform<!-- --> form is used to initialize a <span><i>slot</i></span> only if no initialization argument associated with that <span><i>slot</i></span> is given as an argument to <span><b>make-instance</b></span> or is defaulted by <!-- -->:default-initargs<!-- -->.</p>
<p>The order of evaluation of default value <span><i>forms</i></span> for initialization arguments and the order of evaluation of <!-- -->:initform<!-- --> forms are undefined. If the order of evaluation is important, <span><b>initialize-instance</b></span> or <span><b>shared-initialize</b></span> <span><i>methods</i></span> should be used instead.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="714-rules-for-initialization-arguments">7.1.4 Rules for Initialization Arguments<a href="h-b-object-creation-and-initialization.html#714-rules-for-initialization-arguments" class="hash-link" aria-label="Direct link to 7.1.4 Rules for Initialization Arguments" title="Direct link to 7.1.4 Rules for Initialization Arguments"></a></h2>
<!-- -->
<p>The <!-- -->:initarg<!-- --> slot option may be specified more than once for a given <span><i>slot</i></span>.</p>
<p>The following rules specify when initialization arguments may be multiply defined:</p>
<p><em></em> A given initialization argument can be used to initialize more than one <span><i>slot</i></span> if the same initialization argument name appears in more than one <!-- -->:initarg<!-- --> slot option.</p>
<p><em></em> A given initialization argument name can appear in the <span><i>lambda list</i></span> of more than one initialization <span><i>method</i></span>.</p>
<p><em></em> A given initialization argument name can appear both in an <!-- -->:initarg<!-- --> slot option and in the <span><i>lambda list</i></span> of an initialization <span><i>method</i></span>.</p>
<p>If two or more initialization arguments that initialize the same <span><i>slot</i></span> are given in the arguments to <span><b>make-instance</b></span>, the leftmost of these initialization arguments in the <span><i>initialization argument list</i></span> supplies the value, even if the initialization arguments have different names.</p>
<p>If two or more different initialization arguments that initialize the same <span><i>slot</i></span> have default values and none is given explicitly in the arguments to <span><b>make-instance</b></span>, the initialization argument that appears in a <!-- -->:default-initargs<!-- --> class option in the most specific of the <em>classes</em> supplies the value. If a single <!-- -->:default-initargs<!-- --> class option specifies two or more initialization arguments that initialize the same <span><i>slot</i></span> and none is given explicitly in the arguments to <span><b>make-instance</b></span>, the leftmost in the <!-- -->:default-initargs<!-- --> class option supplies the value, and the values of the remaining default value <span><i>forms</i></span> are ignored.</p>
<p>Initialization arguments given explicitly in the arguments to <span><b>make-instance</b></span> appear to the left of defaulted initialization arguments. Suppose that the classes <em>C</em><sub>1</sub> and <em>C</em><sub>2</sub> supply the values of defaulted initialization arguments for different <span><i>slots</i></span>, and suppose that <em>C</em><sub>1</sub> is more specific than <em>C</em><sub>2</sub>; then the defaulted initialization argument whose value is supplied by <em>C</em><sub>1</sub> is to the left of</p>
<p>the defaulted initialization argument whose value is supplied by <em>C</em><sub>2</sub> in the <em>defaulted initialization argument list</em>. If a single <!-- -->:default-initargs<!-- --> class option supplies the values of initialization arguments for two different <span><i>slots</i></span>, the initialization argument whose value is specified farther to the left in the <!-- -->:default-initargs<!-- --> class option appears farther to the left in the <em>defaulted initialization argument list</em>.</p>
<p>If a <span><i>slot</i></span> has both an <!-- -->:initform<!-- --> form and an <!-- -->:initarg<!-- --> slot option, and the initialization argument is defaulted using <!-- -->:default-initargs<!-- --> or is supplied to <span><b>make-instance</b></span>, the captured <!-- -->:initform<!-- --> form is neither used nor evaluated.</p>
<p>The following is an example of the above rules:</p>
<p>(defclass q () ((x <!-- -->:initarg<!-- --> a)))</p>
<p>(defclass r (q) ((x <!-- -->:initarg<!-- --> b))</p>
<p>(<!-- -->:default-initargs<!-- --> a 1 b 2))</p>
<p><strong>Defaulted</strong></p>
<p><strong>Form Initialization Argument List Contents of Slot X</strong> (make-instance r) (a 1 b 2) 1</p>
<p>(make-instance r a 3) (a 3 b 2) 3</p>
<p>(make-instance r b 4) (b 4 a 1) 4</p>
<p>(make-instance r a 1 a 2) (a 1 a 2 b 2) 1</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="715-shared">7.1.5 Shared<a href="h-b-object-creation-and-initialization.html#715-shared" class="hash-link" aria-label="Direct link to 7.1.5 Shared" title="Direct link to 7.1.5 Shared"></a></h2>
<!-- -->
<p>The <span><i>generic function</i></span> <span><b>shared-initialize</b></span> is used to fill the <span><i>slots</i></span> of an <span><i>instance</i></span> using initialization arguments and <!-- -->:initform<!-- --> forms when an <span><i>instance</i></span> is created, when an <span><i>instance</i></span> is re-initialized, when an <span><i>instance</i></span> is updated to conform to a redefined <span><i>class</i></span>, and when an <span><i>instance</i></span> is updated to conform to a different <span><i>class</i></span>. It uses standard <span><i>method</i></span> combination. It takes the following</p>
<p>arguments: the <span><i>instance</i></span> to be initialized, a specification of a set of <span><i>names</i></span> of <em>slots accessible</em> in that <span><i>instance</i></span>, and any number of initialization arguments. The arguments after the first two must form an <span><i>initialization argument list</i></span>.</p>
<p>The second argument to <span><b>shared-initialize</b></span> may be one of the following:</p>
<p><em></em> It can be a (possibly empty) <span><i>list</i></span> of <span><i>slot</i></span> names, which specifies the set of those <span><i>slot</i></span> names.</p>
<p><em></em> It can be the symbol <span><b>t</b></span>, which specifies the set of all of the <span><i>slots</i></span>.</p>
<p>There is a system-supplied primary <span><i>method</i></span> for <span><b>shared-initialize</b></span> whose first <span><i>parameter specializer</i></span> is the <span><i>class</i></span> <span><b>standard-object</b></span>. This <span><i>method</i></span> behaves as follows on each <span><i>slot</i></span>, whether shared or local:</p>
<p><em></em> If an initialization argument in the <span><i>initialization argument list</i></span> specifies a value for that <span><i>slot</i></span>, that value is stored into the <span><i>slot</i></span>, even if a value has already been stored in the <span><i>slot</i></span> before the <span><i>method</i></span> is run. The affected <span><i>slots</i></span> are independent of which <span><i>slots</i></span> are indicated by the second argument to <span><b>shared-initialize</b></span>.</p>
<p><em></em> Any <span><i>slots</i></span> indicated by the second argument that are still unbound at this point are initialized according to their <!-- -->:initform<!-- --> forms. For any such <span><i>slot</i></span> that has an <!-- -->:initform<!-- --> form, that <span><i>form</i></span> is evaluated in the lexical environment of its defining <span><b>defclass</b></span> form and the result is stored into the <span><i>slot</i></span>. For example, if a <span><i>before method</i></span> stores a value in the <span><i>slot</i></span>, the <!-- -->:initform<!-- --> form will not be used to supply a value for the <span><i>slot</i></span>. If the second argument specifies a <span><i>name</i></span> that does not correspond to any <em>slots accessible</em> in the <span><i>instance</i></span>, the results are unspecified.</p>
<p><em></em> The rules mentioned in Section 7.1.4 (Rules for Initialization Arguments) are obeyed.</p>
<p>The generic function <span><b>shared-initialize</b></span> is called by the system-supplied primary <span><i>methods</i></span> for <span><b>reinitialize-instance</b></span>, <strong>update-instance-for-different-class</strong>, <strong>update-instance-for-redefined-class</strong>, and <span><b>initialize-instance</b></span>. Thus, <span><i>methods</i></span> can be written for <span><b>shared-initialize</b></span> to specify actions that should be taken in all of these contexts.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="716-initialize">7.1.6 Initialize<a href="h-b-object-creation-and-initialization.html#716-initialize" class="hash-link" aria-label="Direct link to 7.1.6 Initialize" title="Direct link to 7.1.6 Initialize"></a></h2>
<!-- -->
<p>The <span><i>generic function</i></span> <span><b>initialize-instance</b></span> is called by <span><b>make-instance</b></span> to initialize a newly created <span><i>instance</i></span>. It uses <span><i>standard method combination</i></span>. <span><i>Methods</i></span> for <span><b>initialize-instance</b></span> can be defined in order to perform any initialization that cannot be achieved simply by supplying initial values for <span><i>slots</i></span>.</p>
<p>During initialization, <span><b>initialize-instance</b></span> is invoked after the following actions have been taken:</p>
<p><em></em> The <em>defaulted initialization argument list</em> has been computed by combining the supplied <span><i>initialization argument list</i></span> with any default initialization arguments for the <span><i>class</i></span>.</p>
<p><em></em> The validity of the <em>defaulted initialization argument list</em> has been checked. If any of the initialization arguments has not been declared as valid, an error is signaled.</p>
<p><em></em> A new <span><i>instance</i></span> whose <span><i>slots</i></span> are unbound has been created.</p>
<p>The generic function <span><b>initialize-instance</b></span> is called with the new <span><i>instance</i></span> and the defaulted initialization arguments. There is a system-supplied primary <span><i>method</i></span> for <span><b>initialize-instance</b></span> whose <span><i>parameter specializer</i></span> is the <span><i>class</i></span> <span><b>standard-object</b></span>. This <span><i>method</i></span> calls the generic function <span><b>shared-initialize</b></span> to fill in the <span><i>slots</i></span> according to the initialization arguments and the <!-- -->:initform<!-- --> forms for the <span><i>slots</i></span>; the generic function <span><b>shared-initialize</b></span> is called with the following arguments: the <span><i>instance</i></span>, <span><b>t</b></span>, and the defaulted initialization arguments.</p>
<p>Note that <span><b>initialize-instance</b></span> provides the <em>defaulted initialization argument list</em> in its call to <span><b>shared-initialize</b></span>, so the first step performed by the system-supplied primary <span><i>method</i></span> for <span><b>shared-initialize</b></span> takes into account both the initialization arguments provided in the call to <span><b>make-instance</b></span> and the <em>defaulted initialization argument list</em>.</p>
<p><span><i>Methods</i></span> for <span><b>initialize-instance</b></span> can be defined to specify actions to be taken when an <span><i>instance</i></span> is initialized. If only <span><i>after methods</i></span> for <span><b>initialize-instance</b></span> are defined, they will be run after the system-supplied primary <span><i>method</i></span> for initialization and therefore will not interfere with the default behavior of <span><b>initialize-instance</b></span>.</p>
<p>The object system provides two <span><i>functions</i></span> that are useful in the bodies of <span><b>initialize-instance</b></span> methods. The <span><i>function</i></span> <span><b>slot-boundp</b></span> returns a <em>generic boolean</em> value that indicates whether a specified <span><i>slot</i></span> has a value; this provides a mechanism for writing <span><i>after methods</i></span> for <span><b>initialize-instance</b></span> that initialize <span><i>slots</i></span> only if they have not already been initialized. The <span><i>function</i></span> <span><b>slot-makunbound</b></span> causes the <span><i>slot</i></span> to have no value.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="717-definitions-of-make">7.1.7 Definitions of Make<a href="h-b-object-creation-and-initialization.html#717-definitions-of-make" class="hash-link" aria-label="Direct link to 7.1.7 Definitions of Make" title="Direct link to 7.1.7 Definitions of Make"></a></h2>
<!-- -->
<!-- -->
<p>The generic function <span><b>make-instance</b></span> behaves as if it were defined as follows, except that certain optimizations are permitted:</p>
<p>(defmethod make-instance ((class standard-class) &amp;rest initargs)</p>
<p>...</p>
<p>(let ((instance (apply #allocate-instance class initargs)))</p>
<p>(apply #initialize-instance instance initargs)</p>
<p>instance))</p>
<p>(defmethod make-instance ((class-name symbol) &amp;rest initargs)</p>
<p>(apply #make-instance (find-class class-name) initargs))</p>
<p>The elided code in the definition of <span><b>make-instance</b></span> augments the initargs with any <em>defaulted initialization arguments</em> and checks the resulting initialization arguments to determine whether</p>
<p>an initialization argument was supplied that neither filled a <span><i>slot</i></span> nor supplied an argument to an applicable <span><i>method</i></span>.</p>
<p>The generic function <span><b>initialize-instance</b></span> behaves as if it were defined as follows, except that certain optimizations are permitted:</p>
<p>(defmethod initialize-instance ((instance standard-object) &amp;rest initargs)</p>
<p>(apply #shared-initialize instance t initargs)))</p>
<p>These procedures can be customized.</p>
<p>Customizing at the Programmer Interface level includes using the <!-- -->:initform<!-- -->, <!-- -->:initarg<!-- -->, and <!-- -->:default-initargs<!-- --> options to <span><b>defclass</b></span>, as well as defining <span><i>methods</i></span> for <span><b>make-instance</b></span>, <span><b>allocate-instance</b></span>, and <span><b>initialize-instance</b></span>. It is also possible to define <span><i>methods</i></span> for <span><b>shared-initialize</b></span>, which would be invoked by the generic functions <span><b>reinitialize-instance</b></span>, <strong>update-instance-for-redefined-class</strong>, <strong>update-instance-for-different-class</strong>, and <span><b>initialize-instance</b></span>. The meta-object level supports additional customization.</p>
<p>Implementations are permitted to make certain optimizations to <span><b>initialize-instance</b></span> and <span><b>shared-initialize</b></span>. The description of <span><b>shared-initialize</b></span> in Chapter 7 mentions the possible optimizations.</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-7/h-b-object-creation-and-initialization.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-6/g-c-dictionary/loop_macro.html"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">loop</div></a><a class="pagination-nav__link pagination-nav__link--next" href="h-c-changing-the-class-of-an-instance.html"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">7.2 Changing the Class of an Instance</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="h-b-object-creation-and-initialization.html#711-initialization-arguments" class="table-of-contents__link toc-highlight">7.1.1 Initialization Arguments</a></li><li><a href="h-b-object-creation-and-initialization.html#712-declaring-the-validity-of-initialization-arguments" class="table-of-contents__link toc-highlight">7.1.2 Declaring the Validity of Initialization Arguments</a></li><li><a href="h-b-object-creation-and-initialization.html#713-defaulting-of-initialization-arguments" class="table-of-contents__link toc-highlight">7.1.3 Defaulting of Initialization Arguments</a></li><li><a href="h-b-object-creation-and-initialization.html#714-rules-for-initialization-arguments" class="table-of-contents__link toc-highlight">7.1.4 Rules for Initialization Arguments</a></li><li><a href="h-b-object-creation-and-initialization.html#715-shared" class="table-of-contents__link toc-highlight">7.1.5 Shared</a></li><li><a href="h-b-object-creation-and-initialization.html#716-initialize" class="table-of-contents__link toc-highlight">7.1.6 Initialize</a></li><li><a href="h-b-object-creation-and-initialization.html#717-definitions-of-make" class="table-of-contents__link toc-highlight">7.1.7 Definitions of Make</a></li></ul></div></div></div></div></main></div></div></div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Docs</div><ul class="footer__items clean-list"><li class="footer__item"><a href="../../docs/tutorial.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Common Lisp Tutorial</a></li><li class="footer__item"><a href="../index.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Common Lisp Technical Reference</a></li><li class="footer__item"><a href="../../docs/help.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Help</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/common-lisp" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow<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></li><li class="footer__item"><a href="https://discord.gg/hhk46CE" target="_blank" rel="noopener noreferrer" class="footer__link-item">Discord<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></li><li class="footer__item"><a href="https://www.reddit.com/r/common_lisp" target="_blank" rel="noopener noreferrer" class="footer__link-item">Reddit<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></li><li class="footer__item"><a href="https://irclog.tymoon.eu/libera/commonlisp" target="_blank" rel="noopener noreferrer" class="footer__link-item">IRC<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></li></ul></div><div class="col footer__col"><div class="footer__title">More</div><ul class="footer__items clean-list"><li class="footer__item"><a href="../../blog.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Blog</a></li><li class="footer__item"><a href="https://github.com/lisp-docs/lisp-docs.github.io" target="_blank" rel="noopener noreferrer" class="footer__link-item">Tutorial and General Content 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></li><li class="footer__item"><a href="https://github.com/lisp-docs/cl-language-reference/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Technical Reference 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></li><li class="footer__item"><a href="../../docs/contribute.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Contribute to the Docs</a></li></ul></div><div class="col footer__col"><div class="footer__title">Common Lisp Docs</div><ul class="footer__items clean-list"><li class="footer__item"><a href="../../docs/about.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">About</a></li><li class="footer__item"><a href="../../docs/whylisp.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Why Lisp</a></li><li class="footer__item"><a href="../../docs/getting-started.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Getting Started</a></li><li class="footer__item"><a href="../../docs/faq.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">FAQ</a></li><li class="footer__item"><a href="../../docs/help.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Getting Help</a></li><li class="footer__item"><a href="../../docs/howto.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">How To Guides</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Copyright © 2024 Common Lisp Docs, MIT License (see GitHub Repo).</div></div></div></footer></div>
</body>
</html>