CINXE.COM

Comparison of programming languages (associative array) - Wikipedia

<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Comparison of programming languages (associative array) - Wikipedia</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy", "wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"1cede071-7eb9-4db5-89d8-69f2d9ede9c4","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Comparison_of_programming_languages_(associative_array)","wgTitle":"Comparison of programming languages (associative array)","wgCurRevisionId":1241597169,"wgRevisionId":1241597169,"wgArticleId":13941848,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Dynamic lists","Articles needing additional references from February 2011","All articles needing additional references","Articles to be expanded from September 2010","All articles to be expanded","Articles with example Julia code","Associative arrays","Programming language comparisons"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName": "Comparison_of_programming_languages_(associative_array)","wgRelevantArticleId":13941848,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgRedirectedFrom":"Comparison_of_programming_languages_(associative_arrays)","wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":90000,"wgInternalRedirectTargetUrl":"/wiki/Comparison_of_programming_languages_(associative_array)","wgRelatedArticlesCompat":[],"wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage", "wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q5155960","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.pygments":"ready","ext.cite.styles":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","jquery.makeCollapsible.styles":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"}; RLPAGEMODULES=["mediawiki.action.view.redirect","ext.pygments.view","ext.cite.ux-enhancements","site","mediawiki.page.ready","jquery.makeCollapsible","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints","ext.quicksurveys.init","ext.growthExperiments.SuggestedEditSession","wikibase.sidebar.tracking"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=ext.cite.styles%7Cext.pygments%2CwikimediaBadges%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cjquery.makeCollapsible.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022"> <script async="" src="/w/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.4"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="Comparison of programming languages (associative array) - Wikipedia"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//en.m.wikipedia.org/wiki/Comparison_of_programming_languages_(associative_array)"> <link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png"> <link rel="icon" href="/static/favicon/wikipedia.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Wikipedia (en)"> <link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(associative_array)"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en"> <link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&amp;feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="//login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-Comparison_of_programming_languages_associative_array rootpage-Comparison_of_programming_languages_associative_array skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-contents" class="mw-list-item"><a href="/wiki/Wikipedia:Contents" title="Guides to browsing Wikipedia"><span>Contents</span></a></li><li id="n-currentevents" class="mw-list-item"><a href="/wiki/Portal:Current_events" title="Articles related to current events"><span>Current events</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Visit a randomly selected article [x]" accesskey="x"><span>Random article</span></a></li><li id="n-aboutsite" class="mw-list-item"><a href="/wiki/Wikipedia:About" title="Learn about Wikipedia and how it works"><span>About Wikipedia</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us" title="How to contact Wikipedia"><span>Contact us</span></a></li> </ul> </div> </div> <div id="p-interaction" class="vector-menu mw-portlet mw-portlet-interaction" > <div class="vector-menu-heading"> Contribute </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Help:Contents" title="Guidance on how to use and edit Wikipedia"><span>Help</span></a></li><li id="n-introduction" class="mw-list-item"><a href="/wiki/Help:Introduction" title="Learn how to edit Wikipedia"><span>Learn to edit</span></a></li><li id="n-portal" class="mw-list-item"><a href="/wiki/Wikipedia:Community_portal" title="The hub for editors"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes to Wikipedia [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_upload_wizard" title="Add images or other media for use on Wikipedia"><span>Upload file</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Main_Page" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Wikipedia" src="/static/images/mobile/copyright/wikipedia-wordmark-en.svg" style="width: 7.5em; height: 1.125em;"> <img class="mw-logo-tagline" alt="The Free Encyclopedia" src="/static/images/mobile/copyright/wikipedia-tagline-en.svg" width="117" height="13" style="width: 7.3125em; height: 0.8125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search Wikipedia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikipedia" aria-label="Search Wikipedia" autocapitalize="sentences" title="Search Wikipedia [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page&#039;s font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=C13_en.wikipedia.org&amp;uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&amp;returnto=Comparison+of+programming+languages+%28associative+array%29" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&amp;returnto=Comparison+of+programming+languages+%28associative+array%29" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Log in and more options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=C13_en.wikipedia.org&amp;uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&amp;returnto=Comparison+of+programming+languages+%28associative+array%29" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=Comparison+of+programming+languages+%28associative+array%29" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">(Top)</div> </a> </li> <li id="toc-Language_support" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Language_support"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Language support</span> </div> </a> <button aria-controls="toc-Language_support-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Language support subsection</span> </button> <ul id="toc-Language_support-sublist" class="vector-toc-list"> <li id="toc-AWK" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#AWK"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1</span> <span>AWK</span> </div> </a> <ul id="toc-AWK-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-C" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#C"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.2</span> <span>C</span> </div> </a> <ul id="toc-C-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-C#" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#C#"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3</span> <span>C#</span> </div> </a> <ul id="toc-C#-sublist" class="vector-toc-list"> <li id="toc-Creation" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Creation"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3.1</span> <span>Creation</span> </div> </a> <ul id="toc-Creation-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Access_by_key" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Access_by_key"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3.2</span> <span>Access by key</span> </div> </a> <ul id="toc-Access_by_key-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Enumeration" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Enumeration"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3.3</span> <span>Enumeration</span> </div> </a> <ul id="toc-Enumeration-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-C++" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#C++"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.4</span> <span>C++</span> </div> </a> <ul id="toc-C++-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Cobra" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Cobra"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.5</span> <span>Cobra</span> </div> </a> <ul id="toc-Cobra-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-ColdFusion_Markup_Language" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#ColdFusion_Markup_Language"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.6</span> <span>ColdFusion Markup Language</span> </div> </a> <ul id="toc-ColdFusion_Markup_Language-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-D" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#D"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.7</span> <span>D</span> </div> </a> <ul id="toc-D-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Delphi" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Delphi"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.8</span> <span>Delphi</span> </div> </a> <ul id="toc-Delphi-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Erlang" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Erlang"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.9</span> <span>Erlang</span> </div> </a> <ul id="toc-Erlang-sublist" class="vector-toc-list"> <li id="toc-Keylists" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Keylists"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.9.1</span> <span>Keylists</span> </div> </a> <ul id="toc-Keylists-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Dictionaries" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Dictionaries"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.9.2</span> <span>Dictionaries</span> </div> </a> <ul id="toc-Dictionaries-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Maps" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Maps"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.9.3</span> <span>Maps</span> </div> </a> <ul id="toc-Maps-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-F#" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#F#"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10</span> <span>F#</span> </div> </a> <ul id="toc-F#-sublist" class="vector-toc-list"> <li id="toc-Map&lt;&#039;Key,&#039;Value&gt;" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Map&lt;&#039;Key,&#039;Value&gt;"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10.1</span> <span>Map&lt;'Key,'Value></span> </div> </a> <ul id="toc-Map&lt;&#039;Key,&#039;Value&gt;-sublist" class="vector-toc-list"> <li id="toc-Creation_2" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Creation_2"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10.1.1</span> <span>Creation</span> </div> </a> <ul id="toc-Creation_2-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Access_by_key_2" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Access_by_key_2"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10.1.2</span> <span>Access by key</span> </div> </a> <ul id="toc-Access_by_key_2-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Dictionary&lt;&#039;TKey,&#039;TValue&gt;" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Dictionary&lt;&#039;TKey,&#039;TValue&gt;"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10.2</span> <span>Dictionary&lt;'TKey,'TValue></span> </div> </a> <ul id="toc-Dictionary&lt;&#039;TKey,&#039;TValue&gt;-sublist" class="vector-toc-list"> <li id="toc-Creation_3" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Creation_3"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10.2.1</span> <span>Creation</span> </div> </a> <ul id="toc-Creation_3-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Access_by_key_3" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Access_by_key_3"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10.2.2</span> <span>Access by key</span> </div> </a> <ul id="toc-Access_by_key_3-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Enumeration_2" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Enumeration_2"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.10.3</span> <span>Enumeration</span> </div> </a> <ul id="toc-Enumeration_2-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-FoxPro" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#FoxPro"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.11</span> <span>FoxPro</span> </div> </a> <ul id="toc-FoxPro-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Go" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Go"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.12</span> <span>Go</span> </div> </a> <ul id="toc-Go-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Haskell" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Haskell"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.13</span> <span>Haskell</span> </div> </a> <ul id="toc-Haskell-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Java" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Java"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.14</span> <span>Java</span> </div> </a> <ul id="toc-Java-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-JavaScript" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#JavaScript"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.15</span> <span>JavaScript</span> </div> </a> <ul id="toc-JavaScript-sublist" class="vector-toc-list"> <li id="toc-Map_and_WeakMap" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Map_and_WeakMap"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.15.1</span> <span>Map and WeakMap</span> </div> </a> <ul id="toc-Map_and_WeakMap-sublist" class="vector-toc-list"> <li id="toc-Creation_4" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Creation_4"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.15.1.1</span> <span>Creation</span> </div> </a> <ul id="toc-Creation_4-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Access_by_key_4" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Access_by_key_4"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.15.1.2</span> <span>Access by key</span> </div> </a> <ul id="toc-Access_by_key_4-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Enumeration_3" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Enumeration_3"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.15.1.3</span> <span>Enumeration</span> </div> </a> <ul id="toc-Enumeration_3-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Object" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Object"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.15.2</span> <span>Object</span> </div> </a> <ul id="toc-Object-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Julia" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Julia"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.16</span> <span>Julia</span> </div> </a> <ul id="toc-Julia-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-KornShell_93,_and_compliant_shells" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#KornShell_93,_and_compliant_shells"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.17</span> <span>KornShell 93, and compliant shells</span> </div> </a> <ul id="toc-KornShell_93,_and_compliant_shells-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Lisp" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Lisp"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.18</span> <span>Lisp</span> </div> </a> <ul id="toc-Lisp-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-LPC" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#LPC"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.19</span> <span>LPC</span> </div> </a> <ul id="toc-LPC-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Lua" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Lua"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.20</span> <span>Lua</span> </div> </a> <ul id="toc-Lua-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Mathematica_and_Wolfram_Language" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Mathematica_and_Wolfram_Language"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.21</span> <span>Mathematica and Wolfram Language</span> </div> </a> <ul id="toc-Mathematica_and_Wolfram_Language-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-MUMPS" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#MUMPS"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.22</span> <span>MUMPS</span> </div> </a> <ul id="toc-MUMPS-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Objective-C_(Cocoa/GNUstep)" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Objective-C_(Cocoa/GNUstep)"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.23</span> <span>Objective-C (Cocoa/GNUstep)</span> </div> </a> <ul id="toc-Objective-C_(Cocoa/GNUstep)-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-OCaml" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#OCaml"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.24</span> <span>OCaml</span> </div> </a> <ul id="toc-OCaml-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-OptimJ" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#OptimJ"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.25</span> <span>OptimJ</span> </div> </a> <ul id="toc-OptimJ-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Perl_5" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Perl_5"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.26</span> <span>Perl 5</span> </div> </a> <ul id="toc-Perl_5-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Perl_6_(Raku)" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Perl_6_(Raku)"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.27</span> <span>Perl 6 (Raku)</span> </div> </a> <ul id="toc-Perl_6_(Raku)-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-PHP" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#PHP"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.28</span> <span>PHP</span> </div> </a> <ul id="toc-PHP-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Pike" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Pike"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.29</span> <span>Pike</span> </div> </a> <ul id="toc-Pike-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-PostScript" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#PostScript"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.30</span> <span>PostScript</span> </div> </a> <ul id="toc-PostScript-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Prolog" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Prolog"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.31</span> <span>Prolog</span> </div> </a> <ul id="toc-Prolog-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Python" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Python"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.32</span> <span>Python</span> </div> </a> <ul id="toc-Python-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Red" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Red"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.33</span> <span>Red</span> </div> </a> <ul id="toc-Red-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-REXX" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#REXX"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.34</span> <span>REXX</span> </div> </a> <ul id="toc-REXX-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Ruby" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Ruby"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.35</span> <span>Ruby</span> </div> </a> <ul id="toc-Ruby-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Rust" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Rust"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.36</span> <span>Rust</span> </div> </a> <ul id="toc-Rust-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-S-Lang" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#S-Lang"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.37</span> <span>S-Lang</span> </div> </a> <ul id="toc-S-Lang-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Scala" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Scala"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.38</span> <span>Scala</span> </div> </a> <ul id="toc-Scala-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Smalltalk" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Smalltalk"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.39</span> <span>Smalltalk</span> </div> </a> <ul id="toc-Smalltalk-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-SNOBOL" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#SNOBOL"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.40</span> <span>SNOBOL</span> </div> </a> <ul id="toc-SNOBOL-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Standard_ML" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Standard_ML"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.41</span> <span>Standard ML</span> </div> </a> <ul id="toc-Standard_ML-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Tcl" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Tcl"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.42</span> <span>Tcl</span> </div> </a> <ul id="toc-Tcl-sublist" class="vector-toc-list"> <li id="toc-array" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#array"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.42.1</span> <span>array</span> </div> </a> <ul id="toc-array-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-dict" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#dict"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.42.2</span> <span>dict</span> </div> </a> <ul id="toc-dict-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Visual_Basic" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Visual_Basic"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.43</span> <span>Visual Basic</span> </div> </a> <ul id="toc-Visual_Basic-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Visual_Basic_.NET" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Visual_Basic_.NET"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.44</span> <span>Visual Basic .NET</span> </div> </a> <ul id="toc-Visual_Basic_.NET-sublist" class="vector-toc-list"> <li id="toc-Creation_5" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Creation_5"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.44.1</span> <span>Creation</span> </div> </a> <ul id="toc-Creation_5-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Access_by_key_5" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Access_by_key_5"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.44.2</span> <span>Access by key</span> </div> </a> <ul id="toc-Access_by_key_5-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Enumeration_4" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Enumeration_4"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.44.3</span> <span>Enumeration</span> </div> </a> <ul id="toc-Enumeration_4-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Windows_PowerShell" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Windows_PowerShell"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.45</span> <span>Windows PowerShell</span> </div> </a> <ul id="toc-Windows_PowerShell-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Data_serialization_formats_support" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Data_serialization_formats_support"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Data serialization formats support</span> </div> </a> <button aria-controls="toc-Data_serialization_formats_support-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Data serialization formats support subsection</span> </button> <ul id="toc-Data_serialization_formats_support-sublist" class="vector-toc-list"> <li id="toc-JSON" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#JSON"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1</span> <span>JSON</span> </div> </a> <ul id="toc-JSON-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-YAML" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#YAML"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2</span> <span>YAML</span> </div> </a> <ul id="toc-YAML-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-References" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#References"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>References</span> </div> </a> <ul id="toc-References-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Comparison of programming languages (associative array)</span></h1> <div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" > <input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="This article exist only in this language. Add the article for other languages" > <label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-0" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span> <span class="vector-dropdown-label-text">Add languages</span> </label> <div class="vector-dropdown-content"> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> <div class="after-portlet after-portlet-lang"><span class="uls-after-portlet-link"></span><span class="wb-langlinks-add wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q5155960#sitelinks-wikipedia" title="Add interlanguage links" class="wbc-editpage">Add links</a></span></div> </div> </div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Comparison_of_programming_languages_(associative_array)" title="View the content page [c]" accesskey="c"><span>Article</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Talk:Comparison_of_programming_languages_(associative_array)" rel="discussion" title="Discuss improvements to the content page [t]" accesskey="t"><span>Talk</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Comparison_of_programming_languages_(associative_array)"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Comparison_of_programming_languages_(associative_array)"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Comparison_of_programming_languages_(associative_array)" title="List of all English Wikipedia pages containing links to this page [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Comparison_of_programming_languages_(associative_array)" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_Upload_Wizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;oldid=1241597169" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&amp;page=Comparison_of_programming_languages_%28associative_array%29&amp;id=1241597169&amp;wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FComparison_of_programming_languages_%28associative_array%29"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrCode&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FComparison_of_programming_languages_%28associative_array%29"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&amp;page=Comparison_of_programming_languages_%28associative_array%29&amp;action=show-download-screen" title="Download this page as a PDF file"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q5155960" title="Structured data on this page hosted by Wikidata [g]" accesskey="g"><span>Wikidata item</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> </div> <div id="siteSub" class="noprint">From Wikipedia, the free encyclopedia</div> </div> <div id="contentSub"><div id="mw-content-subtitle"><span class="mw-redirectedfrom">(Redirected from <a href="/w/index.php?title=Comparison_of_programming_languages_(associative_arrays)&amp;redirect=no" class="mw-redirect" title="Comparison of programming languages (associative arrays)">Comparison of programming languages (associative arrays)</a>)</span></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><style data-mw-deduplicate="TemplateStyles:r1129693374">.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}</style><style data-mw-deduplicate="TemplateStyles:r1246091330">.mw-parser-output .sidebar{width:22em;float:right;clear:right;margin:0.5em 0 1em 1em;background:var(--background-color-neutral-subtle,#f8f9fa);border:1px solid var(--border-color-base,#a2a9b1);padding:0.2em;text-align:center;line-height:1.4em;font-size:88%;border-collapse:collapse;display:table}body.skin-minerva .mw-parser-output .sidebar{display:table!important;float:right!important;margin:0.5em 0 1em 1em!important}.mw-parser-output .sidebar-subgroup{width:100%;margin:0;border-spacing:0}.mw-parser-output .sidebar-left{float:left;clear:left;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-none{float:none;clear:both;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-outer-title{padding:0 0.4em 0.2em;font-size:125%;line-height:1.2em;font-weight:bold}.mw-parser-output .sidebar-top-image{padding:0.4em}.mw-parser-output .sidebar-top-caption,.mw-parser-output .sidebar-pretitle-with-top-image,.mw-parser-output .sidebar-caption{padding:0.2em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-pretitle{padding:0.4em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-title,.mw-parser-output .sidebar-title-with-pretitle{padding:0.2em 0.8em;font-size:145%;line-height:1.2em}.mw-parser-output .sidebar-title-with-pretitle{padding:0.1em 0.4em}.mw-parser-output .sidebar-image{padding:0.2em 0.4em 0.4em}.mw-parser-output .sidebar-heading{padding:0.1em 0.4em}.mw-parser-output .sidebar-content{padding:0 0.5em 0.4em}.mw-parser-output .sidebar-content-with-subgroup{padding:0.1em 0.4em 0.2em}.mw-parser-output .sidebar-above,.mw-parser-output .sidebar-below{padding:0.3em 0.8em;font-weight:bold}.mw-parser-output .sidebar-collapse .sidebar-above,.mw-parser-output .sidebar-collapse .sidebar-below{border-top:1px solid #aaa;border-bottom:1px solid #aaa}.mw-parser-output .sidebar-navbar{text-align:right;font-size:115%;padding:0 0.4em 0.4em}.mw-parser-output .sidebar-list-title{padding:0 0.4em;text-align:left;font-weight:bold;line-height:1.6em;font-size:105%}.mw-parser-output .sidebar-list-title-c{padding:0 0.4em;text-align:center;margin:0 3.3em}@media(max-width:640px){body.mediawiki .mw-parser-output .sidebar{width:100%!important;clear:both;float:none!important;margin-left:0!important;margin-right:0!important}}body.skin--responsive .mw-parser-output .sidebar a>img{max-width:none!important}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media print{body.ns-0 .mw-parser-output .sidebar{display:none!important}}</style><table class="sidebar nomobile nowraplinks" style="width:115px"><tbody><tr><th class="sidebar-title"><a href="/wiki/Comparison_of_programming_languages" title="Comparison of programming languages">Comparison of<br />programming languages</a></th></tr><tr><td class="sidebar-content" style="text-align: left"> <ul><li><a href="/wiki/Comparison_of_programming_languages" title="Comparison of programming languages">General comparison</a></li> <li><a href="/wiki/Assignment_(computer_science)#Notation" title="Assignment (computer science)">Assignment</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(syntax)" title="Comparison of programming languages (syntax)">Basic syntax</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(basic_instructions)" title="Comparison of programming languages (basic instructions)">Basic instructions</a></li> <li><a href="/wiki/Comment_(computer_programming)#Comparison" title="Comment (computer programming)">Comments</a></li> <li>Control flow <ul><li><a href="/wiki/Foreach_loop#Language_support" title="Foreach loop">Foreach loops</a></li> <li><a href="/wiki/While_loop#Demonstrating_while_loops" title="While loop">While loops</a></li> <li><a href="/wiki/For_loop#Timeline_of_the_for-loop_syntax_in_various_programming_languages" title="For loop">For loops</a></li> <li><a href="/wiki/Do_while_loop#Demonstrating_do_while_loops" title="Do while loop">Do-while</a></li></ul></li> <li><a href="/wiki/Exception_handling_syntax" title="Exception handling syntax">Exception handling</a></li> <li><a href="/wiki/Enumerated_type#Syntax_in_several_programming_languages" title="Enumerated type">Enumerated types</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(algebraic_data_type)" title="Comparison of programming languages (algebraic data type)">Algebraic data types</a></li> <li><a href="/wiki/Generator_(computer_programming)#Timeline" title="Generator (computer programming)">Generators</a></li> <li><a href="/wiki/Anonymous_function#Examples" title="Anonymous function">Anonymous functions</a></li> <li><a href="/wiki/Ternary_conditional_operator" title="Ternary conditional operator">Conditional expressions</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(functional_instructions)" class="mw-redirect" title="Comparison of programming languages (functional instructions)">Functional instructions</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(array)" title="Comparison of programming languages (array)">Arrays</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(associative_arrays)" class="mw-redirect" title="Comparison of programming languages (associative arrays)">Associative arrays</a></li> <li><a href="/wiki/Scope_(computer_science)#By_language" title="Scope (computer science)">Scope</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(strings)" title="Comparison of programming languages (strings)">String operations</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(string_functions)" title="Comparison of programming languages (string functions)">String functions</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(higher-order_functions)" class="mw-redirect" title="Comparison of programming languages (higher-order functions)">Higher-order functions</a> <ul><li><a href="/wiki/Filter_(higher-order_function)#Language_comparison" title="Filter (higher-order function)">Filter</a></li> <li><a href="/wiki/Fold_(higher-order_function)#In_various_languages" title="Fold (higher-order function)">Fold</a></li> <li><a href="/wiki/Map_(higher-order_function)#Language_comparison" title="Map (higher-order function)">Map</a></li></ul></li> <li><a href="/wiki/Comparison_of_programming_languages_by_type_system" title="Comparison of programming languages by type system">Type systems</a> <ul><li><a href="/wiki/Comparison_of_programming_languages_with_dependent_types" class="mw-redirect" title="Comparison of programming languages with dependent types">Dependent types</a></li></ul></li> <li><a href="/wiki/Comparison_of_programming_languages_(list_comprehension)" title="Comparison of programming languages (list comprehension)">List comprehension</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(object-oriented_programming)" title="Comparison of programming languages (object-oriented programming)">Object-oriented programming</a></li> <li><a href="/wiki/Constructor_(object-oriented_programming)" title="Constructor (object-oriented programming)">Object-oriented constructors</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(operators)" class="mw-redirect" title="Comparison of programming languages (operators)">Operators</a> <ul><li><a href="/wiki/Ternary_conditional_operator#Usage" title="Ternary conditional operator">Ternary conditional operator</a></li> <li><a href="/wiki/Null_coalescing_operator#Examples_by_languages" title="Null coalescing operator">Null coalescing operators</a></li> <li><a href="/wiki/Safe_navigation_operator#Examples" title="Safe navigation operator">Safe navigation operators</a></li> <li><a href="/wiki/Modulo_operation#In_programming_languages" class="mw-redirect" title="Modulo operation">Modulo operators</a></li></ul></li></ul></td> </tr><tr><td class="sidebar-content" style="text-align: left"> <ul><li><a href="/wiki/Evaluation_strategy" title="Evaluation strategy">Evaluation strategy</a></li> <li><a href="https://en.wikibooks.org/wiki/Computer_Programming/Hello_world" class="extiw" title="b:Computer Programming/Hello world">List of "Hello World" programs</a></li></ul></td> </tr><tr><td class="sidebar-content" style="text-align: left"> <hr /> <div class="collapsible-list mw-collapsible mw-collapsed" style="text-align: left;"> <div style="line-height: 1.6em; font-weight: bold;"><div>Comparison of individual<br />languages</div></div> <ul class="mw-collapsible-content" style="margin-top: 0; margin-bottom: 0; line-height: inherit;"><li style="line-height: inherit; margin: 0">Comparison of Java and .NET platforms </li><li style="line-height: inherit; margin: 0"><a href="/wiki/ALGOL_58#ALGOL_58&#39;s_influence_on_ALGOL_60" title="ALGOL 58">ALGOL 58's influence on ALGOL 60</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/ALGOL_60#Comparisons_with_other_languages" title="ALGOL 60">ALGOL 60: Comparisons with other languages</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_ALGOL_68_and_C%2B%2B" title="Comparison of ALGOL 68 and C++">Comparison of ALGOL 68 and C++</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/ALGOL_68#Comparisons_with_other_languages" title="ALGOL 68">ALGOL 68: Comparisons with other languages</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Compatibility_of_C_and_C%2B%2B" title="Compatibility of C and C++">Compatibility of C and C++</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Pascal_and_Delphi" title="Comparison of Pascal and Delphi">Comparison of Pascal and Borland Delphi</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Object_Pascal_and_C" class="mw-redirect" title="Comparison of Object Pascal and C">Comparison of Object Pascal and C</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Pascal_and_C" title="Comparison of Pascal and C">Comparison of Pascal and C</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Java_and_C%2B%2B" title="Comparison of Java and C++">Comparison of Java and C++</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_C_Sharp_and_Java" title="Comparison of C Sharp and Java">Comparison of C# and Java</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_C_Sharp_and_Visual_Basic_.NET" title="Comparison of C Sharp and Visual Basic .NET">Comparison of C# and Visual Basic .NET</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Visual_Basic_and_Visual_Basic_.NET" title="Comparison of Visual Basic and Visual Basic .NET">Comparison of Visual Basic and Visual Basic .NET</a> </li></ul> </div></td> </tr><tr><td class="sidebar-navbar"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><style data-mw-deduplicate="TemplateStyles:r1239400231">.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}</style><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:Comparison_of_programming_languages" title="Template:Comparison of programming languages"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:Comparison_of_programming_languages" title="Template talk:Comparison of programming languages"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:Comparison_of_programming_languages" title="Special:EditPage/Template:Comparison of programming languages"><abbr title="Edit this template">e</abbr></a></li></ul></div></td></tr></tbody></table> <style data-mw-deduplicate="TemplateStyles:r886046785">.mw-parser-output .toclimit-2 .toclevel-1 ul,.mw-parser-output .toclimit-3 .toclevel-2 ul,.mw-parser-output .toclimit-4 .toclevel-3 ul,.mw-parser-output .toclimit-5 .toclevel-4 ul,.mw-parser-output .toclimit-6 .toclevel-5 ul,.mw-parser-output .toclimit-7 .toclevel-6 ul{display:none}</style><div class="toclimit-3"><meta property="mw:PageProp/toc" /></div> <p>This <b>comparison of programming languages (associative arrays)</b> compares the features of <a href="/wiki/Associative_array" title="Associative array">associative array</a> <a href="/wiki/Data_structure" title="Data structure">data structures</a> or array-lookup processing for over 40 computer <a href="/wiki/Programming_language" title="Programming language">programming languages</a>. </p> <div class="mw-heading mw-heading2"><h2 id="Language_support">Language support</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=1" title="Edit section: Language support"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1236090951">.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}</style><div role="note" class="hatnote navigation-not-searchable">This is a <a href="/wiki/Wikipedia:WikiProject_Lists#Dynamic_lists" title="Wikipedia:WikiProject Lists">dynamic list</a> and may never be able to satisfy particular standards for completeness. You can help by <a href="/wiki/Special:EditPage/Comparison_of_programming_languages_(associative_array)" title="Special:EditPage/Comparison of programming languages (associative array)">adding missing items</a> with <a href="/wiki/Wikipedia:Reliable_sources" title="Wikipedia:Reliable sources">reliable sources</a>.</div> <p>The following is a comparison of <a href="/wiki/Associative_array" title="Associative array">associative arrays</a> (also "mapping", "hash", and "dictionary") in various programming languages. </p> <div class="mw-heading mw-heading3"><h3 id="AWK">AWK</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=2" title="Edit section: AWK"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/AWK" title="AWK">AWK</a> has built-in, language-level support for associative arrays. </p><p>For example: </p> <div class="mw-highlight mw-highlight-lang-awk mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">phonebook</span><span class="p">[</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;555-9999&quot;</span> <span class="nx">phonebook</span><span class="p">[</span><span class="s2">&quot;John Doe&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;555-1212&quot;</span> <span class="nx">phonebook</span><span class="p">[</span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;555-1337&quot;</span> </pre></div> <p>The following code loops through an associated array and prints its contents: </p> <div class="mw-highlight mw-highlight-lang-awk mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span> <span class="p">(</span><span class="nx">name</span> <span class="o">in</span> <span class="nx">phonebook</span><span class="p">)</span> <span class="p">{</span> <span class="kr">print</span> <span class="nx">name</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="nx">phonebook</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="p">}</span> </pre></div> <p>The user can search for elements in an associative array, and delete elements from the array. </p><p>The following shows how multi-dimensional associative arrays can be simulated in standard AWK using concatenation and the built-in string-separator variable SUBSEP: </p> <div class="mw-highlight mw-highlight-lang-awk mw-content-ltr" dir="ltr"><pre><span></span><span class="p">{</span> <span class="c1"># for every input line</span> <span class="nx">multi</span><span class="p">[</span><span class="o">$</span><span class="mi">1</span> <span class="nb">SUBSEP</span> <span class="o">$</span><span class="mi">2</span><span class="p">]</span><span class="o">++</span><span class="p">;</span> <span class="p">}</span> <span class="c1">#</span> <span class="nb">END</span> <span class="p">{</span> <span class="k">for</span> <span class="p">(</span><span class="nx">x</span> <span class="o">in</span> <span class="nx">multi</span><span class="p">)</span> <span class="p">{</span> <span class="kr">split</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">arr</span><span class="p">,</span> <span class="nb">SUBSEP</span><span class="p">);</span> <span class="kr">print</span> <span class="nx">arr</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nx">arr</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="nx">multi</span><span class="p">[</span><span class="nx">x</span><span class="p">];</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="C">C</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=3" title="Edit section: C"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>There is no standard implementation of associative arrays in <a href="/wiki/C_(programming_language)" title="C (programming language)">C</a>, but a 3rd-party library, C Hash Table, with BSD license, is available.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup> </p><p>Another 3rd-party library, uthash, also creates associative arrays from C structures. A structure represents a value, and one of the structure fields serves as the key.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup> </p><p>Finally, the <a href="/wiki/GLib" title="GLib">GLib</a> library also supports associative arrays, along with many other advanced data types and is the recommended implementation of the GNU Project.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">&#91;</span>3<span class="cite-bracket">&#93;</span></a></sup> </p><p>Similar to <a href="/wiki/GLib" title="GLib">GLib</a>, <a href="/wiki/Apple_Inc." title="Apple Inc.">Apple</a>'s cross-platform <a href="/wiki/Core_Foundation" title="Core Foundation">Core Foundation</a> framework provides several basic data types. In particular, there are reference-counted CFDictionary and CFMutableDictionary. </p> <div class="mw-heading mw-heading3"><h3 id="C#"><span id="C.23"></span>C#</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=4" title="Edit section: C#"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a> uses the collection classes provided by the <a href="/wiki/.NET_Framework" title=".NET Framework">.NET Framework</a>. The most commonly used associative array type is <code>System.Collections.Generic.Dictionary&lt;TKey, TValue&gt;</code>, which is implemented as a mutable hash table. The relatively new <code>System.Collections.Immutable</code> package, available in .NET Framework versions 4.5 and above, and in all versions of <a href="/wiki/.NET_Core" class="mw-redirect" title=".NET Core">.NET Core</a>, also includes the <code>System.Collections.Immutable.Dictionary&lt;TKey, TValue&gt;</code> type, which is implemented using an <a href="/wiki/AVL_tree" title="AVL tree">AVL tree</a>. The methods that would normally mutate the object in-place instead return a new object that represents the state of the original object after mutation. </p> <div class="mw-heading mw-heading4"><h4 id="Creation">Creation</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=5" title="Edit section: Creation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The following demonstrates three means of populating a mutable dictionary: </p> <ul><li>the <code>Add</code> method, which adds a key and value and throws an <a href="/wiki/Exception_handling" title="Exception handling">exception</a> if the key already exists in the dictionary;</li> <li>assigning to the indexer, which overwrites any existing value, if present; and</li> <li>assigning to the backing property of the indexer, for which the indexer is <a href="/wiki/Syntactic_sugar" title="Syntactic sugar">syntactic sugar</a> (not applicable to C#, see <a href="#F#">F#</a> or <a href="#Visual_Basic_.NET">VB.NET</a> examples).</li></ul> <div class="mw-highlight mw-highlight-lang-csharp mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">dictionary</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Dictionary</span><span class="o">&lt;</span><span class="kt">string</span><span class="p">,</span><span class="w"> </span><span class="kt">string</span><span class="o">&gt;</span><span class="p">();</span> <span class="n">dictionary</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">);</span> <span class="n">dictionary</span><span class="p">[</span><span class="s">&quot;John Doe&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">;</span> <span class="c1">// Not allowed in C#.</span> <span class="c1">// dictionary.Item(&quot;J. Random Hacker&quot;) = &quot;553-1337&quot;;</span> <span class="n">dictionary</span><span class="p">[</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">;</span> </pre></div> <p>The dictionary can also be initialized during construction using a "collection initializer", which compiles to repeated calls to <code>Add</code>. </p> <div class="mw-highlight mw-highlight-lang-csharp mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">dictionary</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Dictionary</span><span class="o">&lt;</span><span class="kt">string</span><span class="p">,</span><span class="w"> </span><span class="kt">string</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="w"> </span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="w"> </span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="w"> </span><span class="p">}</span> <span class="p">};</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Access_by_key"><span class="anchor" id="C#_access"></span>Access by key</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=6" title="Edit section: Access by key"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Values are primarily retrieved using the indexer (which throws an exception if the key does not exist) and the <code>TryGetValue</code> method, which has an output parameter for the sought value and a Boolean return-value indicating whether the key was found. </p> <div class="mw-highlight mw-highlight-lang-csharp mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dictionary</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">];</span> </pre></div> <div class="mw-highlight mw-highlight-lang-csharp mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">dictionary</span><span class="p">.</span><span class="n">TryGetValue</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">out</span><span class="w"> </span><span class="kt">var</span><span class="w"> </span><span class="n">result</span><span class="p">)</span><span class="w"> </span><span class="o">?</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="s">&quot;n/a&quot;</span><span class="p">;</span> </pre></div> <p>In this example, the <code>sallyNumber</code> value will now contain the string <code>"555-9999"</code>. </p> <div class="mw-heading mw-heading4"><h4 id="Enumeration"><span class="anchor" id="C#_enumeration"></span>Enumeration</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=7" title="Edit section: Enumeration"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>A dictionary can be viewed as a sequence of keys, sequence of values, or sequence of pairs of keys and values represented by instances of the <code>KeyValuePair&lt;TKey, TValue&gt;</code> type, although there is no guarantee of order. For a sorted dictionary, the programmer could choose to use a <code>SortedDictionary&lt;TKey, TValue&gt;</code> or use the <code>.Sort</code> <a href="/wiki/Language_Integrated_Query" title="Language Integrated Query">LINQ</a> extension method when enumerating. </p><p>The following demonstrates enumeration using a <a href="/wiki/Foreach_loop" title="Foreach loop">foreach loop</a>: </p> <div class="mw-highlight mw-highlight-lang-csharp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// loop through the collection and display each entry.</span> <span class="k">foreach</span><span class="w"> </span><span class="p">(</span><span class="n">KeyValuePair</span><span class="o">&lt;</span><span class="kt">string</span><span class="p">,</span><span class="kt">string</span><span class="o">&gt;</span><span class="w"> </span><span class="n">kvp</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">dictionary</span><span class="p">)</span> <span class="p">{</span> <span class="w"> </span><span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">&quot;Phone number for {0} is {1}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">kvp</span><span class="p">.</span><span class="n">Key</span><span class="p">,</span><span class="w"> </span><span class="n">kvp</span><span class="p">.</span><span class="n">Value</span><span class="p">);</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="C++"><span id="C.2B.2B"></span>C++</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=8" title="Edit section: C++"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/C%2B%2B" title="C++">C++</a> has a form of associative array called <a href="/wiki/Map_(C%2B%2B)" class="mw-redirect" title="Map (C++)"><code>std::map</code></a> (see <a href="/wiki/Standard_Template_Library#Containers" title="Standard Template Library">Standard Template Library#Containers</a>). One could create a phone-book map with the following code in C++: </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;map&gt;</span> <span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;string&gt;</span> <span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;utility&gt;</span> <span class="w"> </span> <span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">map</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;</span><span class="w"> </span><span class="n">phone_book</span><span class="p">;</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">));</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">));</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">));</span> <span class="p">}</span> </pre></div> <p>Or less efficiently, as this creates temporary <code>std::string</code> values: </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;map&gt;</span> <span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;string&gt;</span> <span class="w"> </span> <span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">map</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;</span><span class="w"> </span><span class="n">phone_book</span><span class="p">;</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">;</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;John Doe&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">;</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>With the extension of <a href="/wiki/C%2B%2B11#Initializer_lists" title="C++11">initialization lists</a> in C++11, entries can be added during a map's construction as shown below: </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;map&gt;</span> <span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;string&gt;</span> <span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">map</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;</span><span class="w"> </span><span class="n">phone_book</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">}</span> <span class="w"> </span><span class="p">};</span> <span class="p">}</span> </pre></div> <p>You can iterate through the list with the following code (C++03): </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">map</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;::</span><span class="n">iterator</span><span class="w"> </span><span class="n">curr</span><span class="p">,</span><span class="w"> </span><span class="n">end</span><span class="p">;</span> <span class="k">for</span><span class="p">(</span><span class="n">curr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">phone_book</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span><span class="w"> </span><span class="n">end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">phone_book</span><span class="p">.</span><span class="n">end</span><span class="p">();</span><span class="w"> </span><span class="n">curr</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">end</span><span class="p">;</span><span class="w"> </span><span class="o">++</span><span class="n">curr</span><span class="p">)</span> <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">curr</span><span class="o">-&gt;</span><span class="n">first</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot; = &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">curr</span><span class="o">-&gt;</span><span class="n">second</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> </pre></div> <p>The same task in C++11: </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="k">auto</span><span class="o">&amp;</span><span class="w"> </span><span class="n">curr</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">phone_book</span><span class="p">)</span> <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">curr</span><span class="p">.</span><span class="n">first</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot; = &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">curr</span><span class="p">.</span><span class="n">second</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> </pre></div> <p>Using the structured binding available in <a href="/wiki/C%2B%2B17" title="C++17">C++17</a>: </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="k">auto</span><span class="o">&amp;</span><span class="w"> </span><span class="p">[</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">number</span><span class="p">]</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">phone_book</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot; = &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">number</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>In C++, the <code>std::map</code> class is <a href="/wiki/Generic_programming#Templates_in_C.2B.2B" title="Generic programming">templated</a> which allows the <a href="/wiki/Data_type" title="Data type">data types</a> of keys and values to be different for different <code>map</code> instances. For a given instance of the <code>map</code> class the keys must be of the same base type. The same must be true for all of the values. Although <code>std::map</code> is typically implemented using a <a href="/wiki/Self-balancing_binary_search_tree" title="Self-balancing binary search tree">self-balancing binary search tree</a>, C++11 defines a second map called <code><a href="/wiki/Std::unordered_map" class="mw-redirect" title="Std::unordered map">std::unordered_map</a></code>, which has the algorithmic characteristics of a hash table. This is a common vendor extension to the <a href="/wiki/Standard_Template_Library" title="Standard Template Library">Standard Template Library</a> (STL) as well, usually called <code>hash_map</code>, available from such implementations as SGI and STLPort. </p> <div class="mw-heading mw-heading3"><h3 id="Cobra">Cobra</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=9" title="Edit section: Cobra"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Initializing an empty dictionary and adding items in <a href="/wiki/Cobra_(programming_language)" title="Cobra (programming language)">Cobra</a>: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="n">dic</span> <span class="k">as</span> <span class="n">Dictionary</span><span class="o">&lt;</span><span class="n">of</span> <span class="n">String</span><span class="p">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="o">=</span> <span class="n">Dictionary</span><span class="o">&lt;</span><span class="n">of</span> <span class="n">String</span><span class="p">,</span> <span class="n">String</span><span class="o">&gt;</span><span class="p">()</span> <span class="n">dic</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;Sally Smart&#39;</span><span class="p">,</span> <span class="s1">&#39;555-9999&#39;</span><span class="p">)</span> <span class="n">dic</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;John Doe&#39;</span><span class="p">,</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">)</span> <span class="n">dic</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">,</span> <span class="s1">&#39;553-1337&#39;</span><span class="p">)</span> <span class="k">assert</span> <span class="n">dic</span><span class="p">[</span><span class="s1">&#39;Sally Smart&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;555-9999&#39;</span> </pre></div> <p>Alternatively, a dictionary can be initialized with all items during construction: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="n">dic</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">&#39;Sally Smart&#39;</span><span class="p">:</span><span class="s1">&#39;555-9999&#39;</span><span class="p">,</span> <span class="s1">&#39;John Doe&#39;</span><span class="p">:</span><span class="s1">&#39;555-1212&#39;</span><span class="p">,</span> <span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">:</span><span class="s1">&#39;553-1337&#39;</span> <span class="p">}</span> </pre></div> <p>The dictionary can be enumerated by a for-loop, but there is no guaranteed order: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">dic</span> <span class="nb">print</span> <span class="s2">&quot;[key]&#39;s phone number is [val]&quot;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="ColdFusion_Markup_Language">ColdFusion Markup Language</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=10" title="Edit section: ColdFusion Markup Language"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>A structure in <a href="/wiki/ColdFusion_Markup_Language" title="ColdFusion Markup Language">ColdFusion Markup Language</a> (CFML) is equivalent to an associative array: </p> <div class="mw-highlight mw-highlight-lang-cfs mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">dynamicKeyName</span> <span class="o">=</span> <span class="s2">&quot;John Doe&quot;</span><span class="p">;</span> <span class="nv">phoneBook</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">&quot;Sally Smart&quot;</span> <span class="o">=</span> <span class="s2">&quot;555-9999&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s s-Interp">#dynamicKeyName#</span><span class="s2">&quot;</span> <span class="o">=</span> <span class="s2">&quot;555-4321&quot;</span><span class="p">,</span> <span class="s2">&quot;J. Random Hacker&quot;</span> <span class="o">=</span> <span class="s2">&quot;555-1337&quot;</span><span class="p">,</span> <span class="nv">UnknownComic</span> <span class="o">=</span> <span class="s2">&quot;???&quot;</span> <span class="p">};</span> <span class="nf">writeOutput</span><span class="p">(</span><span class="nv">phoneBook.UnknownComic</span><span class="p">);</span> <span class="c1">//&#160;???</span> <span class="nf">writeDump</span><span class="p">(</span><span class="nv">phoneBook</span><span class="p">);</span> <span class="c1">// entire struct</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="D">D</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=11" title="Edit section: D"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/D_programming_language" class="mw-redirect" title="D programming language">D</a> offers direct support for associative arrays in the core language; such arrays are implemented as a chaining hash table with binary trees.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">&#91;</span>4<span class="cite-bracket">&#93;</span></a></sup> The equivalent example would be: </p> <div class="mw-highlight mw-highlight-lang-d mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="n">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nb">string</span><span class="p">[</span><span class="w"> </span><span class="nb">string</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="n">phone_book</span><span class="p">;</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">;</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;John Doe&quot;</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">;</span> <span class="w"> </span><span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">;</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>Keys and values can be any types, but all the keys in an associative array must be of the same type, and the same goes for dependent values. </p><p>Looping through all properties and associated values, and printing them, can be coded as follows: </p> <div class="mw-highlight mw-highlight-lang-d mw-content-ltr" dir="ltr"><pre><span></span><span class="k">foreach</span><span class="w"> </span><span class="p">(</span><span class="n">key</span><span class="p">,</span><span class="w"> </span><span class="n">value</span><span class="p">;</span><span class="w"> </span><span class="n">phone_book</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">writeln</span><span class="p">(</span><span class="s">&quot;Number for &quot;</span><span class="w"> </span><span class="p">~</span><span class="w"> </span><span class="n">key</span><span class="w"> </span><span class="p">~</span><span class="w"> </span><span class="s">&quot;: &quot;</span><span class="w"> </span><span class="p">~</span><span class="w"> </span><span class="n">value</span><span class="w"> </span><span class="p">);</span> <span class="p">}</span> </pre></div> <p>A property can be removed as follows: </p> <div class="mw-highlight mw-highlight-lang-d mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phone_book</span><span class="p">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">);</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Delphi">Delphi</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=12" title="Edit section: Delphi"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Delphi_(software)" title="Delphi (software)">Delphi</a> supports several standard containers, including TDictionary&lt;T&gt;: </p> <div class="mw-highlight mw-highlight-lang-delphi mw-content-ltr" dir="ltr"><pre><span></span><span class="k">uses</span> <span class="w"> </span><span class="n">SysUtils</span><span class="o">,</span> <span class="w"> </span><span class="n">Generics</span><span class="o">.</span><span class="n">Collections</span><span class="o">;</span> <span class="k">var</span> <span class="w"> </span><span class="n">PhoneBook</span><span class="o">:</span><span class="w"> </span><span class="n">TDictionary</span><span class="o">&lt;</span><span class="k">string</span><span class="o">,</span><span class="w"> </span><span class="k">string</span><span class="o">&gt;;</span> <span class="w"> </span><span class="n">Entry</span><span class="o">:</span><span class="w"> </span><span class="n">TPair</span><span class="o">&lt;</span><span class="k">string</span><span class="o">,</span><span class="w"> </span><span class="k">string</span><span class="o">&gt;;</span> <span class="k">begin</span> <span class="w"> </span><span class="n">PhoneBook</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="n">TDictionary</span><span class="o">&lt;</span><span class="k">string</span><span class="o">,</span><span class="w"> </span><span class="k">string</span><span class="o">&gt;.</span><span class="n">Create</span><span class="o">;</span> <span class="w"> </span><span class="n">PhoneBook</span><span class="o">.</span><span class="n">Add</span><span class="p">(</span><span class="s">&#39;Sally Smart&#39;</span><span class="o">,</span><span class="w"> </span><span class="s">&#39;555-9999&#39;</span><span class="p">)</span><span class="o">;</span> <span class="w"> </span><span class="n">PhoneBook</span><span class="o">.</span><span class="n">Add</span><span class="p">(</span><span class="s">&#39;John Doe&#39;</span><span class="o">,</span><span class="w"> </span><span class="s">&#39;555-1212&#39;</span><span class="p">)</span><span class="o">;</span> <span class="w"> </span><span class="n">PhoneBook</span><span class="o">.</span><span class="n">Add</span><span class="p">(</span><span class="s">&#39;J. Random Hacker&#39;</span><span class="o">,</span><span class="w"> </span><span class="s">&#39;553-1337&#39;</span><span class="p">)</span><span class="o">;</span> <span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Entry</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">PhoneBook</span><span class="w"> </span><span class="k">do</span> <span class="w"> </span><span class="nb">Writeln</span><span class="p">(</span><span class="nb">Format</span><span class="p">(</span><span class="s">&#39;Number for %s: %s&#39;</span><span class="o">,</span><span class="p">[</span><span class="n">Entry</span><span class="o">.</span><span class="n">Key</span><span class="o">,</span><span class="w"> </span><span class="n">Entry</span><span class="o">.</span><span class="n">Value</span><span class="p">]))</span><span class="o">;</span> <span class="k">end</span><span class="o">.</span> </pre></div> <p>Pre-2009 Delphi versions do not support associative arrays directly. Such arrays can be simulated using the TStrings class: </p> <div class="mw-highlight mw-highlight-lang-delphi mw-content-ltr" dir="ltr"><pre><span></span><span class="k">procedure</span><span class="w"> </span><span class="nc">TForm1</span><span class="o">.</span><span class="nf">Button1Click</span><span class="p">(</span><span class="n">Sender</span><span class="o">:</span><span class="w"> </span><span class="kt">TObject</span><span class="p">)</span><span class="o">;</span> <span class="k">var</span> <span class="w"> </span><span class="n">DataField</span><span class="o">:</span><span class="w"> </span><span class="n">TStrings</span><span class="o">;</span> <span class="w"> </span><span class="n">i</span><span class="o">:</span><span class="w"> </span><span class="kt">Integer</span><span class="o">;</span> <span class="k">begin</span> <span class="w"> </span><span class="n">DataField</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="n">TStringList</span><span class="o">.</span><span class="n">Create</span><span class="o">;</span> <span class="w"> </span><span class="n">DataField</span><span class="o">.</span><span class="n">Values</span><span class="p">[</span><span class="s">&#39;Sally Smart&#39;</span><span class="p">]</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="s">&#39;555-9999&#39;</span><span class="o">;</span> <span class="w"> </span><span class="n">DataField</span><span class="o">.</span><span class="n">Values</span><span class="p">[</span><span class="s">&#39;John Doe&#39;</span><span class="p">]</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="s">&#39;555-1212&#39;</span><span class="o">;</span> <span class="w"> </span><span class="n">DataField</span><span class="o">.</span><span class="n">Values</span><span class="p">[</span><span class="s">&#39;J. Random Hacker&#39;</span><span class="p">]</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="s">&#39;553-1337&#39;</span><span class="o">;</span> <span class="w"> </span><span class="c1">// access an entry and display it in a message box</span> <span class="w"> </span><span class="n">ShowMessage</span><span class="p">(</span><span class="n">DataField</span><span class="o">.</span><span class="n">Values</span><span class="p">[</span><span class="s">&#39;Sally Smart&#39;</span><span class="p">])</span><span class="o">;</span> <span class="w"> </span><span class="c1">// loop through the associative array </span> <span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="n">DataField</span><span class="o">.</span><span class="n">Count</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="k">do</span> <span class="w"> </span><span class="k">begin</span> <span class="w"> </span><span class="n">ShowMessage</span><span class="p">(</span><span class="s">&#39;Number for &#39;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">DataField</span><span class="o">.</span><span class="n">Names</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&#39;: &#39;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">DataField</span><span class="o">.</span><span class="n">ValueFromIndex</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">;</span> <span class="w"> </span><span class="k">end</span><span class="o">;</span> <span class="w"> </span><span class="n">DataField</span><span class="o">.</span><span class="n">Free</span><span class="o">;</span> <span class="k">end</span><span class="o">;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Erlang">Erlang</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=13" title="Edit section: Erlang"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Erlang_(programming_language)" title="Erlang (programming language)">Erlang</a> offers many ways to represent mappings; three of the most common in the standard library are keylists, dictionaries, and maps. </p> <div class="mw-heading mw-heading4"><h4 id="Keylists">Keylists</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=14" title="Edit section: Keylists"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Keylists are lists of <a href="/wiki/Tuple" title="Tuple">tuples</a>, where the first element of each tuple is a key, and the second is a value. Functions for operating on keylists are provided in the <code>lists</code> module. </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PhoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[{</span><span class="s">&quot;Sally Smith&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">}].</span> </pre></div> <p>Accessing an element of the keylist can be done with the <code>lists:keyfind/3</code> function: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="p">{_,</span><span class="w"> </span><span class="nv">Phone</span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">lists</span><span class="p">:</span><span class="nf">keyfind</span><span class="p">(</span><span class="s">&quot;Sally Smith&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="nv">PhoneBook</span><span class="p">),</span> <span class="nn">io</span><span class="p">:</span><span class="nf">format</span><span class="p">(</span><span class="s">&quot;Phone number: </span><span class="si">~s~n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="nv">Phone</span><span class="p">]).</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Dictionaries">Dictionaries</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=15" title="Edit section: Dictionaries"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Dictionaries are implemented in the <code>dict</code> module of the standard library. A new dictionary is created using the <code>dict:new/0</code> function and new key/value pairs are stored using the <code>dict:store/3</code> function: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PhoneBook1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">dict</span><span class="p">:</span><span class="nf">new</span><span class="p">(),</span> <span class="nv">PhoneBook2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">dict</span><span class="p">:</span><span class="nf">store</span><span class="p">(</span><span class="s">&quot;Sally Smith&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span><span class="w"> </span><span class="nv">Dict1</span><span class="p">),</span> <span class="nv">PhoneBook3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">dict</span><span class="p">:</span><span class="nf">store</span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span><span class="w"> </span><span class="nv">Dict2</span><span class="p">),</span> <span class="nv">PhoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">dict</span><span class="p">:</span><span class="nf">store</span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">,</span><span class="w"> </span><span class="nv">Dict3</span><span class="p">).</span> </pre></div> <p>Such a serial initialization would be more idiomatically represented in Erlang with the appropriate function: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PhoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">dict</span><span class="p">:</span><span class="nf">from_list</span><span class="p">([{</span><span class="s">&quot;Sally Smith&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">}]).</span> </pre></div> <p>The dictionary can be accessed using the <code>dict:find/2</code> function: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="p">{</span><span class="n">ok</span><span class="p">,</span><span class="w"> </span><span class="nv">Phone</span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">dict</span><span class="p">:</span><span class="nf">find</span><span class="p">(</span><span class="s">&quot;Sally Smith&quot;</span><span class="p">,</span><span class="w"> </span><span class="nv">PhoneBook</span><span class="p">),</span> <span class="nn">io</span><span class="p">:</span><span class="nf">format</span><span class="p">(</span><span class="s">&quot;Phone: </span><span class="si">~s~n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="nv">Phone</span><span class="p">]).</span> </pre></div> <p>In both cases, any Erlang term can be used as the key. Variations include the <code>orddict</code> module, implementing ordered dictionaries, and <code>gb_trees</code>, implementing general balanced trees. </p> <div class="mw-heading mw-heading4"><h4 id="Maps">Maps</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=16" title="Edit section: Maps"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Maps were introduced in OTP 17.0,<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> and combine the strengths of keylists and dictionaries. A map is defined using the syntax <code>#{ K1 =&gt; V1, ... Kn =&gt; Vn }</code>: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PhoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">#{</span><span class="s">&quot;Sally Smith&quot;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">}.</span> </pre></div> <p>Basic functions to interact with maps are available from the <code>maps</code> module. For example, the <code>maps:find/2</code> function returns the value associated with a key: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="p">{</span><span class="n">ok</span><span class="p">,</span><span class="w"> </span><span class="nv">Phone</span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">maps</span><span class="p">:</span><span class="nf">find</span><span class="p">(</span><span class="s">&quot;Sally Smith&quot;</span><span class="p">,</span><span class="w"> </span><span class="nv">PhoneBook</span><span class="p">),</span> <span class="nn">io</span><span class="p">:</span><span class="nf">format</span><span class="p">(</span><span class="s">&quot;Phone: </span><span class="si">~s~n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="nv">Phone</span><span class="p">]).</span> </pre></div> <p>Unlike dictionaries, maps can be pattern matched upon: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="p">#{</span><span class="s">&quot;Sally Smith&quot;</span><span class="p">,</span><span class="w"> </span><span class="nv">Phone</span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">PhoneBook</span><span class="p">,</span> <span class="nn">io</span><span class="p">:</span><span class="nf">format</span><span class="p">(</span><span class="s">&quot;Phone: </span><span class="si">~s~n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="nv">Phone</span><span class="p">]).</span> </pre></div> <p>Erlang also provides syntax sugar for functional updates—creating a new map based on an existing one, but with modified values or additional keys: </p> <div class="mw-highlight mw-highlight-lang-erlang mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PhoneBook2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">PhoneBook</span><span class="p">#{</span> <span class="w"> </span><span class="c">% the `:=` operator updates the value associated with an existing key</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="s">&quot;355-7331&quot;</span><span class="p">,</span> <span class="w"> </span><span class="c">% the `=&gt;` operator adds a new key-value pair, potentially replacing an existing one</span> <span class="w"> </span><span class="s">&quot;Alice Wonderland&quot;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&quot;555-1865&quot;</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="F#"><span id="F.23"></span>F#</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=17" title="Edit section: F#"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading4"><h4 id="Map&lt;'Key,'Value&gt;"><span id="Map.3C.27Key.2C.27Value.3E"></span>Map&lt;'Key,'Value&gt;</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=18" title="Edit section: Map&lt;&#039;Key,&#039;Value&gt;"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>At runtime, <a href="/wiki/F_Sharp_(programming_language)" title="F Sharp (programming language)">F#</a> provides the <code>Collections.Map&lt;'Key,'Value&gt;</code> type, which is an immutable <a href="/wiki/AVL_tree" title="AVL tree">AVL tree</a>. </p> <div class="mw-heading mw-heading5"><h5 id="Creation_2">Creation</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=19" title="Edit section: Creation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The following example calls the <code>Map</code> constructor, which operates on a list (a semicolon delimited sequence of elements enclosed in square brackets) of tuples (which in F# are comma-delimited sequences of elements). </p> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">let</span><span class="w"> </span><span class="nv">numbers</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="o">[</span> <span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="o">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="o">;</span><span class="w"> </span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="o">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="o">;</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="o">,</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span> <span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="o">|&gt;</span><span class="w"> </span><span class="n">Map</span> </pre></div> <div class="mw-heading mw-heading5"><h5 id="Access_by_key_2">Access by key</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=20" title="Edit section: Access by key"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Values can be looked up via one of the <code>Map</code> members, such as its indexer or <code>Item</code> property (which throw an <a href="/wiki/Exception_handling" title="Exception handling">exception</a> if the key does not exist) or the <code>TryFind</code> function, which returns an <a href="/wiki/Option_type" title="Option type">option type</a> with a value of <code>Some &lt;result&gt;</code>, for a successful lookup, or <code>None</code>, for an unsuccessful one. <a href="/wiki/Pattern_matching" title="Pattern matching">Pattern matching</a> can then be used to extract the raw value from the result, or a default value can be set. </p> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">let</span><span class="w"> </span><span class="nv">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">numbers</span><span class="o">.[</span><span class="s">&quot;Sally Smart&quot;</span><span class="o">]</span> <span class="c1">// or</span> <span class="k">let</span><span class="w"> </span><span class="nv">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">numbers</span><span class="o">.</span><span class="n">Item</span><span class="o">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="o">)</span> </pre></div> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">let</span><span class="w"> </span><span class="nv">sallyNumber</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">numbers</span><span class="o">.</span><span class="n">TryFind</span><span class="o">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="o">)</span><span class="w"> </span><span class="k">with</span> <span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">Some</span><span class="o">(</span><span class="n">number</span><span class="o">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">number</span> <span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">None</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;n/a&quot;</span> </pre></div> <p>In both examples above, the <code>sallyNumber</code> value would contain the string <code>"555-9999"</code>. </p> <div class="mw-heading mw-heading4"><h4 id="Dictionary&lt;'TKey,'TValue&gt;"><span id="Dictionary.3C.27TKey.2C.27TValue.3E"></span>Dictionary&lt;'TKey,'TValue&gt;</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=21" title="Edit section: Dictionary&lt;&#039;TKey,&#039;TValue&gt;"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Because F# is a .NET language, it also has access to features of the <a href="/wiki/.NET_Framework" title=".NET Framework">.NET Framework</a>, including the <code class="mw-highlight mw-highlight-lang-f# mw-content-ltr" style="" dir="ltr"><span class="nn">System</span><span class="p">.</span><span class="nn">Collections</span><span class="p">.</span><span class="nn">Generic</span><span class="p">.</span><span class="n">Dictionary</span><span class="o">&lt;</span><span class="k">&#39;</span><span class="n">TKey</span><span class="o">,</span><span class="k">&#39;</span><span class="n">TValue</span><span class="o">&gt;</span></code> type (which is implemented as a <a href="/wiki/Hash_table" title="Hash table">hash table</a>), which is the primary associative array type used in C# and Visual Basic. This type may be preferred when writing code that is intended to operate with other languages on the .NET Framework, or when the performance characteristics of a hash table are preferred over those of an AVL tree. </p> <div class="mw-heading mw-heading5"><h5 id="Creation_3">Creation</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=22" title="Edit section: Creation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The <code>dict</code> function provides a means of conveniently creating a .NET dictionary that is not intended to be mutated; it accepts a sequence of tuples and returns an immutable object that implements <code>IDictionary&lt;'TKey,'TValue&gt;</code>. </p> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">let</span><span class="w"> </span><span class="nv">numbers</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="o">[</span> <span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="o">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="o">;</span><span class="w"> </span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="o">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="o">;</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="o">,</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span> <span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="o">|&gt;</span><span class="w"> </span><span class="n">dict</span> </pre></div> <p>When a mutable dictionary is needed, the constructor of <code class="mw-highlight mw-highlight-lang-f# mw-content-ltr" style="" dir="ltr"><span class="nn">System</span><span class="p">.</span><span class="nn">Collections</span><span class="p">.</span><span class="nn">Generic</span><span class="p">.</span><span class="n">Dictionary</span><span class="o">&lt;</span><span class="k">&#39;</span><span class="n">TKey</span><span class="o">,</span><span class="k">&#39;</span><span class="n">TValue</span><span class="o">&gt;</span></code> can be called directly. See <a href="#C#">the C# example on this page</a> for additional information. </p> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">let</span><span class="w"> </span><span class="nv">numbers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">System</span><span class="p">.</span><span class="nn">Collections</span><span class="p">.</span><span class="nn">Generic</span><span class="p">.</span><span class="n">Dictionary</span><span class="o">&lt;</span><span class="kt">string</span><span class="o">,</span><span class="w"> </span><span class="kt">string</span><span class="o">&gt;</span><span class="bp">()</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Add</span><span class="o">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="o">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="o">)</span> <span class="n">numbers</span><span class="o">.[</span><span class="s">&quot;John Doe&quot;</span><span class="o">]</span><span class="w"> </span><span class="o">&lt;-</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Item</span><span class="o">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="o">)</span><span class="w"> </span><span class="o">&lt;-</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span> </pre></div> <div class="mw-heading mw-heading5"><h5 id="Access_by_key_3">Access by key</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=23" title="Edit section: Access by key"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><code>IDictionary</code> instances have an indexer that is used in the same way as <code>Map</code>, although the equivalent to <code>TryFind</code> is <code>TryGetValue</code>, which has an output parameter for the sought value and a Boolean return value indicating whether the key was found. </p> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">let</span><span class="w"> </span><span class="nv">sallyNumber</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="k">let</span><span class="w"> </span><span class="nv">mutable</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;&quot;</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">numbers</span><span class="o">.</span><span class="n">TryGetValue</span><span class="o">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="o">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">result</span><span class="o">)</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s">&quot;n/a&quot;</span> </pre></div> <p>F# also allows the function to be called as if it had no output parameter and instead returned a tuple containing its regular return value and the value assigned to the output parameter: </p> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">let</span><span class="w"> </span><span class="nv">sallyNumber</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">numbers</span><span class="o">.</span><span class="n">TryGetValue</span><span class="o">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="o">)</span><span class="w"> </span><span class="k">with</span> <span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">true</span><span class="o">,</span><span class="w"> </span><span class="n">number</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">number</span> <span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="o">_</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;n/a&quot;</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Enumeration_2">Enumeration</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=24" title="Edit section: Enumeration"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>A dictionary or map can be enumerated using <code>Seq.map</code>. </p> <div class="mw-highlight mw-highlight-lang-fsharp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// loop through the collection and display each entry.</span> <span class="n">numbers</span><span class="w"> </span><span class="o">|&gt;</span><span class="w"> </span><span class="nn">Seq</span><span class="p">.</span><span class="n">map</span><span class="w"> </span><span class="o">(</span><span class="k">fun</span><span class="w"> </span><span class="n">kvp</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">printfn</span><span class="w"> </span><span class="s">&quot;Phone number for %O is %O&quot;</span><span class="w"> </span><span class="n">kvp</span><span class="o">.</span><span class="n">Key</span><span class="w"> </span><span class="n">kvp</span><span class="o">.</span><span class="n">Value</span><span class="o">)</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="FoxPro">FoxPro</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=25" title="Edit section: FoxPro"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Visual_FoxPro" title="Visual FoxPro">Visual FoxPro</a> implements mapping with the Collection Class. </p> <div class="mw-highlight mw-highlight-lang-foxpro mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">mapping</span> = <span class="nf">NEWOBJECT</span>(<span class="s">&quot;Collection&quot;</span>) <span class="nv">mapping</span><span class="nf">.Add</span>(<span class="s">&quot;Daffodils&quot;</span>, <span class="s">&quot;flower2&quot;</span>) <span class="c1">&amp;&amp; Add(object, key) – key must be character</span> <span class="kr">index</span> = mapping<span class="nf">.GetKey</span>(<span class="s">&quot;flower2&quot;</span>) <span class="c1">&amp;&amp; returns the index value 1</span> <span class="nv">object</span> = mapping(<span class="s">&quot;flower2&quot;</span>) <span class="c1">&amp;&amp; returns &quot;Daffodils&quot; (retrieve by key)</span> <span class="nv">object</span> = mapping(1) <span class="c1">&amp;&amp; returns &quot;Daffodils&quot; (retrieve by index)</span> </pre></div> <p>GetKey returns 0 if the key is not found. </p> <div class="mw-heading mw-heading3"><h3 id="Go">Go</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=26" title="Edit section: Go"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Go_(programming_language)" title="Go (programming language)">Go</a> has built-in, language-level support for associative arrays, called "maps". A map's key type may only be a boolean, numeric, string, array, struct, pointer, interface, or channel type. </p><p>A map type is written: <code>map[keytype]valuetype</code> </p><p>Adding elements one at a time: </p> <div class="mw-highlight mw-highlight-lang-go mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">phone_book</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nb">make</span><span class="p">(</span><span class="kd">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="w"> </span><span class="kt">string</span><span class="p">)</span><span class="w"> </span><span class="c1">// make an empty map</span> <span class="nx">phone_book</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span> <span class="nx">phone_book</span><span class="p">[</span><span class="s">&quot;John Doe&quot;</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span> <span class="nx">phone_book</span><span class="p">[</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span> </pre></div> <p>A map literal: </p> <div class="mw-highlight mw-highlight-lang-go mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">phone_book</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="kd">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">,</span> <span class="p">}</span> </pre></div> <p>Iterating through a map: </p> <div class="mw-highlight mw-highlight-lang-go mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// over both keys and values</span> <span class="k">for</span><span class="w"> </span><span class="nx">key</span><span class="p">,</span><span class="w"> </span><span class="nx">value</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="k">range</span><span class="w"> </span><span class="nx">phone_book</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">fmt</span><span class="p">.</span><span class="nx">Printf</span><span class="p">(</span><span class="s">&quot;Number for %s: %s\n&quot;</span><span class="p">,</span><span class="w"> </span><span class="nx">key</span><span class="p">,</span><span class="w"> </span><span class="nx">value</span><span class="p">)</span> <span class="p">}</span> <span class="c1">// over just keys</span> <span class="k">for</span><span class="w"> </span><span class="nx">key</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="k">range</span><span class="w"> </span><span class="nx">phone_book</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">fmt</span><span class="p">.</span><span class="nx">Printf</span><span class="p">(</span><span class="s">&quot;Name: %s\n&quot;</span><span class="p">,</span><span class="w"> </span><span class="nx">key</span><span class="p">)</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Haskell">Haskell</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=27" title="Edit section: Haskell"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The <a href="/wiki/Haskell" title="Haskell">Haskell</a> programming language provides only one kind of associative container – a list of pairs: </p> <div class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span></span><span class="nf">m</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="p">[(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">),</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">),</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">)]</span> <span class="nf">main</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="p">(</span><span class="n">lookup</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="n">m</span><span class="p">)</span> </pre></div> <p>output: </p> <pre>Just "555-1212" </pre> <p>Note that the lookup function returns a "Maybe" value, which is "Nothing" if not found, or "Just 'result<span style="padding-right:.15em;">'</span>" when found. </p><p>The <a href="/wiki/Glasgow_Haskell_Compiler" title="Glasgow Haskell Compiler">Glasgow Haskell Compiler</a> (GHC), the most commonly used implementation of Haskell, provides two more types of associative containers. Other implementations may also provide these. </p><p>One is polymorphic functional maps (represented as immutable balanced binary trees): </p> <div class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span></span><span class="hll"><span class="kr">import</span><span class="w"> </span><span class="k">qualified</span><span class="w"> </span><span class="nn">Data.Map</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">M</span> </span> <span class="nf">m</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kt">M</span><span class="o">.</span><span class="n">insert</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="w"> </span><span class="kt">M</span><span class="o">.</span><span class="n">empty</span> <span class="nf">m&#39;</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kt">M</span><span class="o">.</span><span class="n">insert</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="w"> </span><span class="n">m</span> <span class="nf">m&#39;&#39;</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kt">M</span><span class="o">.</span><span class="n">insert</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="w"> </span><span class="n">m&#39;</span> <span class="nf">main</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="p">(</span><span class="kt">M</span><span class="o">.</span><span class="n">lookup</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="n">m&#39;&#39;</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Maybe</span><span class="w"> </span><span class="kt">String</span><span class="p">)</span> </pre></div> <p>output: </p> <pre>Just "555-1212" </pre> <p>A specialized version for integer keys also exists as Data.IntMap. </p><p>Finally, a polymorphic hash table: </p> <div class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">import</span><span class="w"> </span><span class="k">qualified</span><span class="w"> </span><span class="nn">Data.HashTable</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">H</span> <span class="nf">main</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kr">do</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="ow">&lt;-</span><span class="w"> </span><span class="kt">H</span><span class="o">.</span><span class="n">new</span><span class="w"> </span><span class="p">(</span><span class="o">==</span><span class="p">)</span><span class="w"> </span><span class="kt">H</span><span class="o">.</span><span class="n">hashString</span> <span class="w"> </span><span class="kt">H</span><span class="o">.</span><span class="n">insert</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span> <span class="w"> </span><span class="kt">H</span><span class="o">.</span><span class="n">insert</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span> <span class="w"> </span><span class="kt">H</span><span class="o">.</span><span class="n">insert</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span> <span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="ow">&lt;-</span><span class="w"> </span><span class="kt">H</span><span class="o">.</span><span class="n">lookup</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span> <span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="n">foo</span> </pre></div> <p>output: </p> <pre>Just "555-1212" </pre> <p>Lists of pairs and functional maps both provide a purely functional interface, which is more idiomatic in Haskell. In contrast, hash tables provide an imperative interface in the <a href="/wiki/Monad_(functional_programming)#IO_monad" title="Monad (functional programming)">IO monad</a>. </p> <div class="mw-heading mw-heading3"><h3 id="Java">Java</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=28" title="Edit section: Java"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a> associative arrays are implemented as "maps", which are part of the <a href="/wiki/Java_collections_framework" title="Java collections framework">Java collections framework</a>. Since <a href="/wiki/Java_Platform,_Standard_Edition" title="Java Platform, Standard Edition">J2SE</a> 5.0 and the introduction of <a href="/wiki/Generic_programming" title="Generic programming">generics</a> into Java, collections can have a type specified; for example, an associative array that maps strings to strings might be specified as follows: </p> <div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="o">&gt;</span><span class="w"> </span><span class="n">phoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">HashMap</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="o">&gt;</span><span class="p">();</span> <span class="n">phoneBook</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">);</span> <span class="n">phoneBook</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">);</span> <span class="n">phoneBook</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span><span class="p">);</span> </pre></div> <p>The <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Map.html#get(java.lang.Object)">get</a></code> method is used to access a key; for example, the value of the expression <code>phoneBook.get("Sally Smart")</code> is <code>"555-9999"</code>. This code uses a hash map to store the associative array, by calling the constructor of the <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/HashMap.html">HashMap</a></code> class. However, since the code only uses methods common to the interface <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Map.html">Map</a></code>, a self-balancing binary tree could be used by calling the constructor of the <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/TreeMap.html">TreeMap</a></code> class (which implements the subinterface <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/SortedMap.html">SortedMap</a></code>), without changing the definition of the <code>phoneBook</code> variable, or the rest of the code, or using other underlying data structures that implement the <code>Map</code> interface. </p><p>The hash function in Java, used by HashMap and HashSet, is provided by the <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/Object.html#hashCode()">Object.hashCode()</a></code> method. Since every class in Java <a href="/wiki/Inheritance_(object-oriented_programming)" title="Inheritance (object-oriented programming)">inherits</a> from <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/Object.html">Object</a></code>, every object has a hash function. A class can <a href="/wiki/Method_overriding_(programming)" class="mw-redirect" title="Method overriding (programming)">override</a> the default implementation of <code>hashCode()</code> to provide a custom hash function more in accordance with the properties of the object. </p><p>The <code>Object</code> class also contains the <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)">equals(Object)</a></code> method, which tests an object for equality with another object. Hashed data structures in Java rely on objects maintaining the following contract between their <code>hashCode()</code> and <code>equals()</code> methods: </p><p>For two objects <i>a</i> and <i>b</i>, </p> <div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">a</span><span class="p">.</span><span class="na">equals</span><span class="p">(</span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="na">equals</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="k">if</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="na">equals</span><span class="p">(</span><span class="n">b</span><span class="p">),</span><span class="w"> </span><span class="n">then</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="na">hashCode</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="na">hashCode</span><span class="p">()</span> </pre></div> <p>In order to maintain this contract, a class that overrides <code>equals()</code> must also override <code>hashCode()</code>, and vice versa, so that <code>hashCode()</code> is based on the same properties (or a subset of the properties) as <code>equals()</code>. </p><p>A further contract that a hashed data structure has with the object is that the results of the <code>hashCode()</code> and <code>equals()</code> methods will not change once the object has been inserted into the map. For this reason, it is generally a good practice to base the hash function on <a href="/wiki/Immutable_object" title="Immutable object">immutable</a> properties of the object. </p><p>Analogously, TreeMap, and other sorted data structures, require that an ordering be defined on the data type. Either the data type must already have defined its own ordering, by implementing the <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/Comparable.html">Comparable</a></code> interface; or a custom <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Comparator.html">Comparator</a></code> must be provided at the time the map is constructed. As with HashMap above, the relative ordering of keys in a TreeMap should not change once they have been inserted into the map. </p> <div class="mw-heading mw-heading3"><h3 id="JavaScript">JavaScript</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=29" title="Edit section: JavaScript"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/JavaScript" title="JavaScript">JavaScript</a> (and its standardized version, <a href="/wiki/ECMAScript" title="ECMAScript">ECMAScript</a>) is a <a href="/wiki/Prototype-based_programming" title="Prototype-based programming">prototype-based</a> <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented</a> language. </p> <div class="mw-heading mw-heading4"><h4 id="Map_and_WeakMap">Map and WeakMap</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=30" title="Edit section: Map and WeakMap"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Modern JavaScript handles associative arrays, using the <code>Map</code> and <code>WeakMap</code> classes. A map does not contain any keys by default; it only contains what is explicitly put into it. The keys and values can be any type (including functions, objects, or any primitive). </p> <div class="mw-heading mw-heading5"><h5 id="Creation_4">Creation</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=31" title="Edit section: Creation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>A map can be initialized with all items during construction: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">phoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nb">Map</span><span class="p">([</span> <span class="w"> </span><span class="p">[</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;555-9999&quot;</span><span class="p">],</span> <span class="w"> </span><span class="p">[</span><span class="s2">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;555-1212&quot;</span><span class="p">],</span> <span class="w"> </span><span class="p">[</span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;553-1337&quot;</span><span class="p">],</span> <span class="p">]);</span> </pre></div> <p>Alternatively, you can initialize an empty map and then add items: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">phoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nb">Map</span><span class="p">();</span> <span class="nx">phoneBook</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;555-9999&quot;</span><span class="p">);</span> <span class="nx">phoneBook</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s2">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;555-1212&quot;</span><span class="p">);</span> <span class="nx">phoneBook</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;553-1337&quot;</span><span class="p">);</span> </pre></div> <div class="mw-heading mw-heading5"><h5 id="Access_by_key_4">Access by key</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=32" title="Edit section: Access by key"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Accessing an element of the map can be done with the <code>get</code> method: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">phoneBook</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">);</span> </pre></div> <p>In this example, the value <code>sallyNumber</code> will now contain the string "555-9999". </p> <div class="mw-heading mw-heading5"><h5 id="Enumeration_3">Enumeration</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=33" title="Edit section: Enumeration"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The keys in a map are ordered. Thus, when iterating through it, a map object returns keys in order of insertion. The following demonstrates enumeration using a for-loop: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// loop through the collection and display each entry.</span> <span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kd">const</span><span class="w"> </span><span class="p">[</span><span class="nx">name</span><span class="p">,</span><span class="w"> </span><span class="nx">number</span><span class="p">]</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="nx">phoneBook</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="sb">`Phone number for </span><span class="si">${</span><span class="nx">name</span><span class="si">}</span><span class="sb"> is </span><span class="si">${</span><span class="nx">number</span><span class="si">}</span><span class="sb">`</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p>A key can be removed as follows: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">phoneBook</span><span class="p">.</span><span class="ow">delete</span><span class="p">(</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">);</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Object">Object</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=34" title="Edit section: Object"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>An object is similar to a map—both let you set keys to values, retrieve those values, delete keys, and detect whether a value is stored at a key. For this reason (and because there were no built-in alternatives), objects historically have been used as maps. </p><p>However, there are important differences that make a map preferable in certain cases. In JavaScript an object is a mapping from property names to values—that is, an associative array with one caveat: the keys of an object must be either a string or a symbol (native objects and primitives implicitly converted to a string keys are allowed). Objects also include one feature unrelated to associative arrays: an object has a prototype, so it contains default keys that could conflict with user-defined keys. So, doing a lookup for a property will point the lookup to the prototype's definition if the object does not define the property. </p><p>An object literal is written as <code>{ property1: value1, property2: value2, ... }</code>. For example: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">myObject</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="s2">&quot;Sally Smart&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s2">&quot;John Doe&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;553-1337&quot;</span><span class="p">,</span> <span class="p">};</span> </pre></div> <p>To prevent the lookup from using the prototype's properties, you can use the <code>Object.setPrototypeOf</code> function: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">Object</span><span class="p">.</span><span class="nx">setPrototypeOf</span><span class="p">(</span><span class="nx">myObject</span><span class="p">,</span><span class="w"> </span><span class="kc">null</span><span class="p">);</span> </pre></div> <p>As of ECMAScript 5 (ES5), the prototype can also be bypassed by using <code>Object.create(null)</code>: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">myObject</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">assign</span><span class="p">(</span><span class="nx">myObject</span><span class="p">,</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="s2">&quot;Sally Smart&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s2">&quot;John Doe&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;553-1337&quot;</span><span class="p">,</span> <span class="p">});</span> </pre></div> <p>If the property name is a valid identifier, the quotes can be omitted, e.g.: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">myOtherObject</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">foo</span><span class="o">:</span><span class="w"> </span><span class="mf">42</span><span class="p">,</span><span class="w"> </span><span class="nx">bar</span><span class="o">:</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">};</span> </pre></div> <p>Lookup is written using property-access notation, either square brackets, which always work, or dot notation, which only works for identifier keys: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">myObject</span><span class="p">[</span><span class="s2">&quot;John Doe&quot;</span><span class="p">]</span> <span class="nx">myOtherObject</span><span class="p">.</span><span class="nx">foo</span> </pre></div> <p>You can also loop through all enumerable properties and associated values as follows (a for-in loop): </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kd">const</span><span class="w"> </span><span class="nx">property</span><span class="w"> </span><span class="ow">in</span><span class="w"> </span><span class="nx">myObject</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">myObject</span><span class="p">[</span><span class="nx">property</span><span class="p">];</span> <span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="sb">`myObject[</span><span class="si">${</span><span class="nx">property</span><span class="si">}</span><span class="sb">] = </span><span class="si">${</span><span class="nx">value</span><span class="si">}</span><span class="sb">`</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p>Or (a for-of loop): </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kd">const</span><span class="w"> </span><span class="p">[</span><span class="nx">property</span><span class="p">,</span><span class="w"> </span><span class="nx">value</span><span class="p">]</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="nb">Object</span><span class="p">.</span><span class="nx">entries</span><span class="p">(</span><span class="nx">myObject</span><span class="p">))</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="sb">`</span><span class="si">${</span><span class="nx">property</span><span class="si">}</span><span class="sb"> = </span><span class="si">${</span><span class="nx">value</span><span class="si">}</span><span class="sb">`</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p>A property can be removed as follows: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="ow">delete</span><span class="w"> </span><span class="nx">myObject</span><span class="p">[</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">];</span> </pre></div> <p>As mentioned before, properties are strings and symbols. Since every native object and primitive can be implicitly converted to a string, you can do: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">myObject</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span><span class="w"> </span><span class="c1">// key is &quot;1&quot;; note that myObject[1] == myObject[&quot;1&quot;]</span> <span class="nx">myObject</span><span class="p">[[</span><span class="s2">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;b&quot;</span><span class="p">]]</span><span class="w"> </span><span class="c1">// key is &quot;a,b&quot;</span> <span class="nx">myObject</span><span class="p">[{</span><span class="w"> </span><span class="nx">toString</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="s2">&quot;hello world&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}]</span><span class="w"> </span><span class="c1">// key is &quot;hello world&quot;</span> </pre></div> <p>In modern JavaScript it's considered bad form to use the Array type as an associative array. Consensus is that the Object type and <code>Map</code>/<code>WeakMap</code> classes are best for this purpose. The reasoning behind this is that if Array is extended via prototype and Object is kept pristine, for and for-in loops will work as expected on associative 'arrays'. This issue has been brought to the fore by the popularity of JavaScript frameworks that make heavy and sometimes indiscriminate use of prototypes to extend JavaScript's inbuilt types. </p><p>See <a rel="nofollow" class="external text" href="http://blog.metawrap.com/2006/05/30/june-6th-is-javascript-array-and-object-prototype-awareness-day/">JavaScript Array And Object Prototype Awareness Day</a> for more information on the issue. </p> <div class="mw-heading mw-heading3"><h3 id="Julia">Julia</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=35" title="Edit section: Julia"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Julia_(programming_language)" title="Julia (programming language)">Julia</a>, the following operations manage associative arrays. </p><p>Declare dictionary: </p> <div class="mw-highlight mw-highlight-lang-julia mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">Dict</span><span class="p">(</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span><span class="w"> </span><span class="p">)</span> </pre></div> <p>Access element: </p> <div class="mw-highlight mw-highlight-lang-julia mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">]</span> </pre></div> <p>Add element: </p> <div class="mw-highlight mw-highlight-lang-julia mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="p">[</span><span class="s">&quot;New Contact&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-2222&quot;</span> </pre></div> <p>Delete element: </p> <div class="mw-highlight mw-highlight-lang-julia mw-content-ltr" dir="ltr"><pre><span></span><span class="n">delete!</span><span class="p">(</span><span class="n">phonebook</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="p">)</span> </pre></div> <p>Get keys and values as <a href="/wiki/Iterator#Implicit_iterators" title="Iterator">iterables</a>: </p> <div class="mw-highlight mw-highlight-lang-julia mw-content-ltr" dir="ltr"><pre><span></span><span class="n">keys</span><span class="p">(</span><span class="n">phonebook</span><span class="p">)</span> <span class="n">values</span><span class="p">(</span><span class="n">phonebook</span><span class="p">)</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="KornShell_93,_and_compliant_shells"><span id="KornShell_93.2C_and_compliant_shells"></span>KornShell 93, and compliant shells</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=36" title="Edit section: KornShell 93, and compliant shells"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Korn_Shell" class="mw-redirect" title="Korn Shell">KornShell</a> 93, and compliant shells (ksh93, bash4...), the following operations can be used with associative arrays. </p><p>Definition: </p> <div class="mw-highlight mw-highlight-lang-ksh mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">typeset</span><span class="w"> </span>-A<span class="w"> </span>phonebook<span class="p">;</span><span class="w"> </span><span class="c1"># ksh93; in bash4+, &quot;typeset&quot; is a synonym of the more preferred &quot;declare&quot;, which works identically in this case</span> <span class="nv">phonebook</span><span class="o">=([</span><span class="s2">&quot;Sally Smart&quot;</span><span class="o">]=</span><span class="s2">&quot;555-9999&quot;</span><span class="w"> </span><span class="o">[</span><span class="s2">&quot;John Doe&quot;</span><span class="o">]=</span><span class="s2">&quot;555-1212&quot;</span><span class="w"> </span><span class="o">[</span><span class="s2">&quot;[[J. Random Hacker]]&quot;</span><span class="o">]=</span><span class="s2">&quot;555-1337&quot;</span><span class="o">)</span><span class="p">;</span> </pre></div> <p>Dereference: </p> <div class="mw-highlight mw-highlight-lang-ksh mw-content-ltr" dir="ltr"><pre><span></span><span class="si">${</span><span class="nv">phonebook</span><span class="p">[</span><span class="s2">&quot;John Doe&quot;</span><span class="p">]</span><span class="si">}</span><span class="p">;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Lisp">Lisp</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=37" title="Edit section: Lisp"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Lisp_programming_language" class="mw-redirect" title="Lisp programming language">Lisp</a> was originally conceived as a "LISt Processing" language, and one of its most important data types is the linked list, which can be treated as an <a href="/wiki/Association_list" title="Association list">association list</a> ("alist"). </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="o">&#39;</span><span class="p">((</span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">))</span> </pre></div> <p>The syntax <code>(x . y)</code> is used to indicate a <a href="/wiki/Cons" title="Cons"><code>cons</code>ed</a> pair. Keys and values need not be the same type within an alist. Lisp and <a href="/wiki/Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a> provide operators such as <code>assoc</code> to manipulate alists in ways similar to associative arrays. </p><p>A set of operations specific to the handling of association lists exists for <a href="/wiki/Common_Lisp" title="Common Lisp">Common Lisp</a>, each of these working non-destructively. </p><p>To add an entry the <code>acons</code> function is employed, creating and returning a new association list. An association list in Common Lisp mimicks a stack, that is, adheres to the last-in-first-out (LIFO) principle, and hence prepends to the list head. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="k">let</span><span class="w"> </span><span class="p">((</span><span class="nv">phone-book</span><span class="w"> </span><span class="no">NIL</span><span class="p">))</span> <span class="w"> </span><span class="p">(</span><span class="nb">setf</span><span class="w"> </span><span class="nv">phone-book</span><span class="w"> </span><span class="p">(</span><span class="nb">acons</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">))</span> <span class="w"> </span><span class="p">(</span><span class="nb">setf</span><span class="w"> </span><span class="nv">phone-book</span><span class="w"> </span><span class="p">(</span><span class="nb">acons</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">))</span> <span class="w"> </span><span class="p">(</span><span class="nb">setf</span><span class="w"> </span><span class="nv">phone-book</span><span class="w"> </span><span class="p">(</span><span class="nb">acons</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)))</span> </pre></div> <p>This function can be construed as an accommodation for <code>cons</code> operations.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">&#91;</span>6<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; The effect of</span> <span class="c1">;; (cons (cons KEY VALUE) ALIST)</span> <span class="c1">;; is equivalent to</span> <span class="c1">;; (acons KEY VALUE ALIST)</span> <span class="p">(</span><span class="k">let</span><span class="w"> </span><span class="p">((</span><span class="nv">phone-book</span><span class="w"> </span><span class="o">&#39;</span><span class="p">((</span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">))))</span> <span class="w"> </span><span class="p">(</span><span class="nb">cons</span><span class="w"> </span><span class="p">(</span><span class="nb">cons</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span><span class="p">)</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">))</span> </pre></div> <p>Of course, the destructive <code>push</code> operation also allows inserting entries into an association list, an entry having to constitute a key-value cons in order to retain the mapping's validity. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">push</span><span class="w"> </span><span class="p">(</span><span class="nb">cons</span><span class="w"> </span><span class="s">&quot;Dummy&quot;</span><span class="w"> </span><span class="s">&quot;123-4567&quot;</span><span class="p">)</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>Searching for an entry by its key is performed via <code>assoc</code>, which might be configured for the test predicate and direction, especially searching the association list from its end to its front. The result, if positive, returns the entire entry cons, not only its value. Failure to obtain a matching key leads to a return of the <code>NIL</code> value. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">assoc</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="w"> </span><span class="ss">:test</span><span class="w"> </span><span class="nf">#&#39;</span><span class="nb">string=</span><span class="p">)</span> </pre></div> <p>Two generalizations of <code>assoc</code> exist: <code>assoc-if</code> expects a predicate function that tests each entry's key, returning the first entry for which the predicate produces a non-<code>NIL</code> value upon invocation. <code>assoc-if-not</code> inverts the logic, accepting the same arguments, but returning the first entry generating <code>NIL</code>. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Find the first entry whose key equals &quot;John Doe&quot;.</span> <span class="p">(</span><span class="nb">assoc-if</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">key</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">string=</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="p">))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> <span class="c1">;; Finds the first entry whose key is neither &quot;Sally Smart&quot; nor &quot;John Doe&quot;</span> <span class="p">(</span><span class="nb">assoc-if-not</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">key</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">member</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="o">&#39;</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="p">)</span><span class="w"> </span><span class="ss">:test</span><span class="w"> </span><span class="nf">#&#39;</span><span class="nb">string=</span><span class="p">))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>The inverse process, the detection of an entry by its value, utilizes <code>rassoc</code>. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Find the first entry with a value of &quot;555-9999&quot;.</span> <span class="c1">;; We test the entry string values with the &quot;string=&quot; predicate.</span> <span class="p">(</span><span class="nb">rassoc</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="w"> </span><span class="ss">:test</span><span class="w"> </span><span class="nf">#&#39;</span><span class="nb">string=</span><span class="p">)</span> </pre></div> <p>The corresponding generalizations <code>rassoc-if</code> and <code>rassoc-if-not</code> exist. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Finds the first entry whose value is &quot;555-9999&quot;.</span> <span class="p">(</span><span class="nb">rassoc-if</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">value</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">string=</span><span class="w"> </span><span class="nv">value</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> <span class="c1">;; Finds the first entry whose value is not &quot;555-9999&quot;.</span> <span class="p">(</span><span class="nb">rassoc-if-not</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">value</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">string=</span><span class="w"> </span><span class="nv">value</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>All of the previous entry search functions can be replaced by general list-centric variants, such as <code>find</code>, <code>find-if</code>, <code>find-if-not</code>, as well as pertinent functions like <code>position</code> and its derivates. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Find an entry with the key &quot;John Doe&quot; and the value &quot;555-1212&quot;.</span> <span class="p">(</span><span class="nb">find</span><span class="w"> </span><span class="p">(</span><span class="nb">cons</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">)</span><span class="w"> </span><span class="nv">phone-book</span><span class="w"> </span><span class="ss">:test</span><span class="w"> </span><span class="nf">#&#39;</span><span class="nb">equal</span><span class="p">)</span> </pre></div> <p>Deletion, lacking a specific counterpart, is based upon the list facilities, including destructive ones. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Create and return an alist without any entry whose key equals &quot;John Doe&quot;.</span> <span class="p">(</span><span class="nb">remove-if</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">entry</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">string=</span><span class="w"> </span><span class="p">(</span><span class="nb">car</span><span class="w"> </span><span class="nv">entry</span><span class="p">)</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="p">))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>Iteration is accomplished with the aid of any function that expects a list. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Iterate via &quot;map&quot;.</span> <span class="p">(</span><span class="nb">map</span><span class="w"> </span><span class="no">NIL</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">entry</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">destructuring-bind</span><span class="w"> </span><span class="p">(</span><span class="nv">key</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span><span class="w"> </span><span class="nv">entry</span> <span class="w"> </span><span class="p">(</span><span class="nb">format</span><span class="w"> </span><span class="no">T</span><span class="w"> </span><span class="s">&quot;~&amp;~s =&gt; ~s&quot;</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="nv">value</span><span class="p">)))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> <span class="c1">;; Iterate via &quot;dolist&quot;.</span> <span class="p">(</span><span class="nb">dolist</span><span class="w"> </span><span class="p">(</span><span class="nv">entry</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">destructuring-bind</span><span class="w"> </span><span class="p">(</span><span class="nv">key</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span><span class="w"> </span><span class="nv">entry</span> <span class="w"> </span><span class="p">(</span><span class="nb">format</span><span class="w"> </span><span class="no">T</span><span class="w"> </span><span class="s">&quot;~&amp;~s =&gt; ~s&quot;</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="nv">value</span><span class="p">)))</span> </pre></div> <p>These being structured lists, processing and transformation operations can be applied without constraints. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Return a vector of the &quot;phone-book&quot; values.</span> <span class="p">(</span><span class="nb">map</span><span class="w"> </span><span class="ss">&#39;vector</span><span class="w"> </span><span class="nf">#&#39;</span><span class="nb">cdr</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> <span class="c1">;; Destructively modify the &quot;phone-book&quot; via &quot;map-into&quot;.</span> <span class="p">(</span><span class="nb">map-into</span><span class="w"> </span><span class="nv">phone-book</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">entry</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">destructuring-bind</span><span class="w"> </span><span class="p">(</span><span class="nv">key</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span><span class="w"> </span><span class="nv">entry</span> <span class="w"> </span><span class="p">(</span><span class="nb">cons</span><span class="w"> </span><span class="p">(</span><span class="nb">reverse</span><span class="w"> </span><span class="nv">key</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="nb">reverse</span><span class="w"> </span><span class="nv">value</span><span class="p">))))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>Because of their linear nature, alists are used for relatively small sets of data. <a href="/wiki/Common_Lisp" title="Common Lisp">Common Lisp</a> also supports a <a href="/wiki/Hash_table" title="Hash table">hash table</a> data type, and for <a href="/wiki/Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a> they are implemented in <a href="/wiki/Scheme_Requests_for_Implementation" title="Scheme Requests for Implementation">SRFI</a> 69. Hash tables have greater overhead than alists, but provide much faster access when there are many elements. A further characteristic is the fact that Common Lisp hash tables do not, as opposed to association lists, maintain the order of entry insertion. </p><p>Common Lisp hash tables are constructed via the <code>make-hash-table</code> function, whose arguments encompass, among other configurations, a predicate to test the entry key. While tolerating arbitrary objects, even heterogeneity within a single hash table instance, the specification of this key <code>:test</code> function is confined to distinguishable entities: the Common Lisp standard only mandates the support of <code>eq</code>, <code>eql</code>, <code>equal</code>, and <code>equalp</code>, yet designating additional or custom operations as permissive for concrete implementations. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="k">let</span><span class="w"> </span><span class="p">((</span><span class="nv">phone-book</span><span class="w"> </span><span class="p">(</span><span class="nb">make-hash-table</span><span class="w"> </span><span class="ss">:test</span><span class="w"> </span><span class="nf">#&#39;</span><span class="nb">equal</span><span class="p">)))</span> <span class="w"> </span><span class="p">(</span><span class="nb">setf</span><span class="w"> </span><span class="p">(</span><span class="nb">gethash</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">setf</span><span class="w"> </span><span class="p">(</span><span class="nb">gethash</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">setf</span><span class="w"> </span><span class="p">(</span><span class="nb">gethash</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">))</span> </pre></div> <p>The <code>gethash</code> function permits obtaining the value associated with a key. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">gethash</span><span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>Additionally, a default value for the case of an absent key may be specified. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">gethash</span><span class="w"> </span><span class="s">&quot;Incognito&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="w"> </span><span class="ss">&#39;no-such-key</span><span class="p">)</span> </pre></div> <p>An invocation of <code>gethash</code> actually returns two values: the value or substitute value for the key and a boolean indicator, returning <code>T</code> if the hash table contains the key and <code>NIL</code> to signal its absence. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">multiple-value-bind</span><span class="w"> </span><span class="p">(</span><span class="nv">value</span><span class="w"> </span><span class="nv">contains-key</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="nb">gethash</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="k">if</span><span class="w"> </span><span class="nv">contains-key</span> <span class="w"> </span><span class="p">(</span><span class="nb">format</span><span class="w"> </span><span class="no">T</span><span class="w"> </span><span class="s">&quot;~&amp;The associated value is: ~s&quot;</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">format</span><span class="w"> </span><span class="no">T</span><span class="w"> </span><span class="s">&quot;~&amp;The key could not be found.&quot;</span><span class="p">)))</span> </pre></div> <p>Use <code>remhash</code> for deleting the entry associated with a key. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">remhash</span><span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p><code>clrhash</code> completely empties the hash table. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">clrhash</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>The dedicated <code>maphash</code> function specializes in iterating hash tables. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">maphash</span> <span class="w"> </span><span class="nf">#&#39;</span><span class="p">(</span><span class="k">lambda</span><span class="w"> </span><span class="p">(</span><span class="nv">key</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">format</span><span class="w"> </span><span class="no">T</span><span class="w"> </span><span class="s">&quot;~&amp;~s =&gt; ~s&quot;</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="nv">value</span><span class="p">))</span> <span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> </pre></div> <p>Alternatively, the <code>loop</code> construct makes provisions for iterations, through keys, values, or conjunctions of both. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">;; Iterate the keys and values of the hash table.</span> <span class="p">(</span><span class="nb">loop</span> <span class="w"> </span><span class="nv">for</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="nv">being</span><span class="w"> </span><span class="k">the</span><span class="w"> </span><span class="nv">hash-keys</span><span class="w"> </span><span class="nv">of</span><span class="w"> </span><span class="nv">phone-book</span> <span class="w"> </span><span class="nv">using</span><span class="w"> </span><span class="p">(</span><span class="nv">hash-value</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span> <span class="w"> </span><span class="nb">do</span><span class="w"> </span><span class="p">(</span><span class="nb">format</span><span class="w"> </span><span class="no">T</span><span class="w"> </span><span class="s">&quot;~&amp;~s =&gt; ~s&quot;</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="nv">value</span><span class="p">))</span> <span class="c1">;; Iterate the values of the hash table.</span> <span class="p">(</span><span class="nb">loop</span> <span class="w"> </span><span class="nv">for</span><span class="w"> </span><span class="nv">value</span><span class="w"> </span><span class="nv">being</span><span class="w"> </span><span class="k">the</span><span class="w"> </span><span class="nv">hash-values</span><span class="w"> </span><span class="nv">of</span><span class="w"> </span><span class="nv">phone-book</span> <span class="w"> </span><span class="nb">do</span><span class="w"> </span><span class="p">(</span><span class="nb">print</span><span class="w"> </span><span class="nv">value</span><span class="p">))</span> </pre></div> <p>A further option invokes <code>with-hash-table-iterator</code>, an iterator-creating macro, the processing of which is intended to be driven by the caller. </p> <div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="nb">with-hash-table-iterator</span><span class="w"> </span><span class="p">(</span><span class="nv">entry-generator</span><span class="w"> </span><span class="nv">phone-book</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">loop</span><span class="w"> </span><span class="nb">do</span> <span class="w"> </span><span class="p">(</span><span class="nb">multiple-value-bind</span><span class="w"> </span><span class="p">(</span><span class="nv">has-entry</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="nv">entry-generator</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="k">if</span><span class="w"> </span><span class="nv">has-entry</span> <span class="w"> </span><span class="p">(</span><span class="nb">format</span><span class="w"> </span><span class="no">T</span><span class="w"> </span><span class="s">&quot;~&amp;~s =&gt; ~s&quot;</span><span class="w"> </span><span class="nv">key</span><span class="w"> </span><span class="nv">value</span><span class="p">)</span> <span class="w"> </span><span class="p">(</span><span class="nb">loop-finish</span><span class="p">)))))</span> </pre></div> <p>It is easy to construct composite abstract data types in Lisp, using structures or object-oriented programming features, in conjunction with lists, arrays, and hash tables. </p> <div class="mw-heading mw-heading3"><h3 id="LPC">LPC</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=38" title="Edit section: LPC"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/LPC_(programming_language)" class="mw-redirect" title="LPC (programming language)">LPC</a> implements associative arrays as a fundamental type known as either "map" or "mapping", depending on the driver. The keys and values can be of any type. A mapping literal is written as <code>([ key_1&#160;: value_1, key_2&#160;: value_2 ])</code>. Procedural code looks like: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="n">mapping</span><span class="w"> </span><span class="n">phone_book</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">([]);</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">;</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;John Doe&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">;</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span><span class="p">;</span> </pre></div> <p>Mappings are accessed for reading using the indexing operator in the same way as they are for writing, as shown above. So phone_book["Sally Smart"] would return the string "555-9999", and phone_book["John Smith"] would return 0. Testing for presence is done using the function member(), e.g. <code>if(member(phone_book, "John Smith")) write("John Smith is listed.\n");</code> </p><p>Deletion is accomplished using a function called either m_delete() or map_delete(), depending on the driver: <code>m_delete(phone_book, "Sally Smart");</code> </p><p>LPC drivers of the <a href="/wiki/LPMud#Amylaar" title="LPMud">Amylaar</a> family implement multivalued mappings using a secondary, numeric index (other drivers of the <a href="/wiki/MudOS" class="mw-redirect" title="MudOS">MudOS</a> family do not support multivalued mappings.) Example syntax: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="n">mapping</span><span class="w"> </span><span class="n">phone_book</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">([</span><span class="o">:</span><span class="mi">2</span><span class="p">]);</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">;</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;99 Sharp Way&quot;</span><span class="p">;</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">;</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;3 Nigma Drive&quot;</span><span class="p">;</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span><span class="p">;</span> <span class="n">phone_book</span><span class="p">[</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;77 Massachusetts Avenue&quot;</span><span class="p">;</span> </pre></div> <p>LPC drivers modern enough to support a foreach() construct use it to iterate through their mapping types. </p> <div class="mw-heading mw-heading3"><h3 id="Lua">Lua</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=39" title="Edit section: Lua"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Lua_programming_language" class="mw-redirect" title="Lua programming language">Lua</a>, "table" is a fundamental type that can be used either as an array (numerical index, fast) or as an associative array. </p><p>The keys and values can be of any type, except nil. The following focuses on non-numerical indexes. </p><p>A table literal is written as <code>{ value, key = value, [index] = value, ["non id string"] = value }</code>. For example: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phone_book</span> <span class="o">=</span> <span class="p">{</span> <span class="p">[</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;555-9999&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;John Doe&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;555-1212&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;553-1337&quot;</span><span class="p">,</span> <span class="c1">-- Trailing comma is OK</span> <span class="p">}</span> <span class="n">aTable</span> <span class="o">=</span> <span class="p">{</span> <span class="c1">-- Table as value</span> <span class="n">subTable</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">5</span><span class="p">,</span> <span class="mf">7.5</span><span class="p">,</span> <span class="n">k</span> <span class="o">=</span> <span class="kc">true</span> <span class="p">},</span> <span class="c1">-- key is &quot;subTable&quot;</span> <span class="c1">-- Function as value</span> <span class="p">[</span><span class="s1">&#39;John Doe&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span><span class="n">age</span><span class="p">)</span> <span class="kr">if</span> <span class="n">age</span> <span class="o">&lt;</span> <span class="mi">18</span> <span class="kr">then</span> <span class="kr">return</span> <span class="s2">&quot;Young&quot;</span> <span class="kr">else</span> <span class="kr">return</span> <span class="s2">&quot;Old!&quot;</span> <span class="kr">end</span> <span class="kr">end</span><span class="p">,</span> <span class="c1">-- Table and function (and other types) can also be used as keys</span> <span class="p">}</span> </pre></div> <p>If the key is a valid identifier (not a reserved word), the quotes can be omitted. Identifiers are case sensitive. </p><p>Lookup is written using either square brackets, which always works, or dot notation, which only works for identifier keys: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">aTable</span><span class="p">[</span><span class="s2">&quot;John Doe&quot;</span><span class="p">](</span><span class="mi">45</span><span class="p">))</span> <span class="n">x</span> <span class="o">=</span> <span class="n">aTable</span><span class="p">.</span><span class="n">subTable</span><span class="p">.</span><span class="n">k</span> </pre></div> <p>You can also loop through all keys and associated values with iterators or for-loops: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="n">simple</span> <span class="o">=</span> <span class="p">{</span> <span class="p">[</span><span class="kc">true</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="p">[</span><span class="kc">false</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="mf">3.14</span><span class="p">]</span> <span class="o">=</span> <span class="nb">math.pi</span><span class="p">,</span> <span class="n">x</span> <span class="o">=</span> <span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;!&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">42</span> <span class="p">}</span> <span class="kr">function</span> <span class="nf">FormatElement</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="kr">return</span> <span class="s2">&quot;[&quot;</span> <span class="o">..</span> <span class="nb">tostring</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="o">..</span> <span class="s2">&quot;] = &quot;</span> <span class="o">..</span> <span class="n">value</span> <span class="o">..</span> <span class="s2">&quot;, &quot;</span> <span class="kr">end</span> <span class="c1">-- Iterate on all keys</span> <span class="n">table</span><span class="p">.</span><span class="n">foreach</span><span class="p">(</span><span class="n">simple</span><span class="p">,</span> <span class="kr">function</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span> <span class="nb">io.write</span><span class="p">(</span><span class="n">FormatElement</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span> <span class="kr">end</span><span class="p">)</span> <span class="nb">print</span><span class="s2">&quot;&quot;</span> <span class="kr">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="kr">in</span> <span class="nb">pairs</span><span class="p">(</span><span class="n">simple</span><span class="p">)</span> <span class="kr">do</span> <span class="nb">io.write</span><span class="p">(</span><span class="n">FormatElement</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span> <span class="kr">end</span> <span class="nb">print</span><span class="s2">&quot;&quot;</span> <span class="n">k</span><span class="o">=</span> <span class="kc">nil</span> <span class="kr">repeat</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="n">simple</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="kr">if</span> <span class="n">k</span> <span class="o">~=</span> <span class="kc">nil</span> <span class="kr">then</span> <span class="nb">io.write</span><span class="p">(</span><span class="n">FormatElement</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span> <span class="kr">end</span> <span class="kr">until</span> <span class="n">k</span> <span class="o">==</span> <span class="kc">nil</span> <span class="nb">print</span><span class="s2">&quot;&quot;</span> </pre></div> <p>An entry can be removed by setting it to nil: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="n">simple</span><span class="p">.</span><span class="n">x</span> <span class="o">=</span> <span class="kc">nil</span> </pre></div> <p>Likewise, you can overwrite values or add them: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="n">simple</span><span class="p">[</span><span class="s1">&#39;%&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;percent&quot;</span> <span class="n">simple</span><span class="p">[</span><span class="s1">&#39;!&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">111</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Mathematica_and_Wolfram_Language">Mathematica and Wolfram Language</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=40" title="Edit section: Mathematica and Wolfram Language"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Mathematica" class="mw-redirect" title="Mathematica">Mathematica</a> and <a href="/wiki/Wolfram_Language" title="Wolfram Language">Wolfram Language</a> use the Association expression to represent associative arrays.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-highlight mw-highlight-lang-mathematica mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&lt;|</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span><span class="w"> </span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="w"> </span><span class="o">|&gt;</span><span class="p">;</span> </pre></div> <p>To access:<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-highlight mw-highlight-lang-mathematica mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="p">[[</span><span class="n">Key</span><span class="p">[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">]]]</span> </pre></div> <p>If the keys are strings, the Key keyword is not necessary, so: </p> <div class="mw-highlight mw-highlight-lang-mathematica mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="p">[[</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">]]</span> </pre></div> <p>To list keys:<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> and values<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">&#91;</span>10<span class="cite-bracket">&#93;</span></a></sup> </p> <pre>Keys[phonebook] Values[phonebook] </pre> <div class="mw-heading mw-heading3"><h3 id="MUMPS">MUMPS</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=41" title="Edit section: MUMPS"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/MUMPS" title="MUMPS">MUMPS</a> every array is an associative array. The built-in, language-level, direct support for associative arrays applies to private, process-specific arrays stored in memory called "locals" as well as to the permanent, shared, global arrays stored on disk which are available concurrently to multiple jobs. The name for globals is preceded by the circumflex "^" to distinguish them from local variables. </p> <pre>SET ^phonebook("Sally Smart")="555-9999" &#160;;; storing permanent data SET phonebook("John Doe")="555-1212" &#160;;; storing temporary data SET phonebook("J. Random Hacker")="553-1337" &#160;;; storing temporary data MERGE ^phonebook=phonebook &#160;;; copying temporary data into permanent data </pre> <p>Accessing the value of an element simply requires using the name with the subscript: </p> <pre>WRITE "Phone Number&#160;:",^phonebook("Sally Smart"),! </pre> <p>You can also loop through an associated array as follows: </p> <pre>SET NAME="" FOR S NAME=$ORDER(^phonebook(NAME)) QUIT:NAME="" WRITE NAME," Phone Number&#160;:",^phonebook(NAME),! </pre> <div class="mw-heading mw-heading3"><h3 id="Objective-C_(Cocoa/GNUstep)"><span id="Objective-C_.28Cocoa.2FGNUstep.29"></span>Objective-C (Cocoa/GNUstep)</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=42" title="Edit section: Objective-C (Cocoa/GNUstep)"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Cocoa_(API)" title="Cocoa (API)">Cocoa</a> and <a href="/wiki/GNUstep" title="GNUstep">GNUstep</a>, written in <a href="/wiki/Objective-C" title="Objective-C">Objective-C</a>, handle associative arrays using <code>NSMutableDictionary</code> (a mutable version of <code>NSDictionary</code>) class cluster. This class allows assignments between any two objects. A copy of the key object is made before it is inserted into <code>NSMutableDictionary</code>, therefore the keys must conform to the <code>NSCopying</code> protocol. When being inserted to a dictionary, the value object receives a retain message to increase its reference count. The value object will receive the release message when it will be deleted from the dictionary (either explicitly or by adding to the dictionary a different object with the same key). </p> <div class="mw-highlight mw-highlight-lang-objc mw-content-ltr" dir="ltr"><pre><span></span><span class="bp">NSMutableDictionary</span><span class="w"> </span><span class="o">*</span><span class="n">aDictionary</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[[</span><span class="bp">NSMutableDictionary</span><span class="w"> </span><span class="n">alloc</span><span class="p">]</span><span class="w"> </span><span class="n">init</span><span class="p">];</span> <span class="p">[</span><span class="n">aDictionary</span><span class="w"> </span><span class="n">setObject</span><span class="o">:</span><span class="s">@&quot;555-9999&quot;</span><span class="w"> </span><span class="n">forKey</span><span class="o">:</span><span class="s">@&quot;Sally Smart&quot;</span><span class="p">];</span><span class="w"> </span> <span class="p">[</span><span class="n">aDictionary</span><span class="w"> </span><span class="n">setObject</span><span class="o">:</span><span class="s">@&quot;555-1212&quot;</span><span class="w"> </span><span class="n">forKey</span><span class="o">:</span><span class="s">@&quot;John Doe&quot;</span><span class="p">];</span><span class="w"> </span> <span class="p">[</span><span class="n">aDictionary</span><span class="w"> </span><span class="n">setObject</span><span class="o">:</span><span class="s">@&quot;553-1337&quot;</span><span class="w"> </span><span class="n">forKey</span><span class="o">:</span><span class="s">@&quot;Random Hacker&quot;</span><span class="p">];</span> </pre></div> <p>To access assigned objects, this command may be used: </p> <div class="mw-highlight mw-highlight-lang-objc mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">id</span><span class="w"> </span><span class="n">anObject</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">aDictionary</span><span class="w"> </span><span class="n">objectForKey</span><span class="o">:</span><span class="s">@&quot;Sally Smart&quot;</span><span class="p">];</span> </pre></div> <p>All keys or values can be enumerated using <code>NSEnumerator</code>: </p> <div class="mw-highlight mw-highlight-lang-objc mw-content-ltr" dir="ltr"><pre><span></span><span class="bp">NSEnumerator</span><span class="w"> </span><span class="o">*</span><span class="n">keyEnumerator</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">aDictionary</span><span class="w"> </span><span class="n">keyEnumerator</span><span class="p">];</span> <span class="kt">id</span><span class="w"> </span><span class="n">key</span><span class="p">;</span> <span class="k">while</span><span class="w"> </span><span class="p">((</span><span class="n">key</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">keyEnumerator</span><span class="w"> </span><span class="n">nextObject</span><span class="p">]))</span> <span class="p">{</span> <span class="w"> </span><span class="c1">// ... process it here ...</span> <span class="p">}</span> </pre></div> <p>In Mac OS X 10.5+ and iPhone OS, dictionary keys can be enumerated more concisely using the <code>NSFastEnumeration</code> construct:<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">&#91;</span>11<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-highlight mw-highlight-lang-objc mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">id</span><span class="w"> </span><span class="n">key</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">aDictionary</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="c1">// ... process it here ...</span> <span class="p">}</span> </pre></div> <p>What is even more practical, structured data graphs may be easily created using <a href="/wiki/Cocoa_(API)" title="Cocoa (API)">Cocoa</a>, especially <code>NSDictionary</code> (<code>NSMutableDictionary</code>). This can be illustrated with this compact example: </p> <div class="mw-highlight mw-highlight-lang-objc mw-content-ltr" dir="ltr"><pre><span></span><span class="bp">NSDictionary</span><span class="w"> </span><span class="o">*</span><span class="n">aDictionary</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="p">[</span><span class="bp">NSDictionary</span><span class="w"> </span><span class="n">dictionaryWithObjectsAndKeys</span><span class="o">:</span> <span class="w"> </span><span class="p">[</span><span class="bp">NSDictionary</span><span class="w"> </span><span class="n">dictionaryWithObjectsAndKeys</span><span class="o">:</span> <span class="w"> </span><span class="s">@&quot;555-9999&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">@&quot;Sally Smart&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">@&quot;555-1212&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">@&quot;John Doe&quot;</span><span class="p">,</span> <span class="w"> </span><span class="nb">nil</span><span class="p">],</span><span class="w"> </span><span class="s">@&quot;students&quot;</span><span class="p">,</span> <span class="w"> </span><span class="p">[</span><span class="bp">NSDictionary</span><span class="w"> </span><span class="n">dictionaryWithObjectsAndKeys</span><span class="o">:</span> <span class="w"> </span><span class="s">@&quot;553-1337&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">@&quot;Random Hacker&quot;</span><span class="p">,</span> <span class="w"> </span><span class="nb">nil</span><span class="p">],</span><span class="w"> </span><span class="s">@&quot;hackers&quot;</span><span class="p">,</span> <span class="w"> </span><span class="nb">nil</span><span class="p">];</span> </pre></div> <p>Relevant fields can be quickly accessed using key paths: </p> <div class="mw-highlight mw-highlight-lang-objc mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">id</span><span class="w"> </span><span class="n">anObject</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">aDictionary</span><span class="w"> </span><span class="n">valueForKeyPath</span><span class="o">:</span><span class="s">@&quot;students.Sally Smart&quot;</span><span class="p">];</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="OCaml">OCaml</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=43" title="Edit section: OCaml"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The <a href="/wiki/OCaml" title="OCaml">OCaml</a> programming language provides three different associative containers. The simplest is a list of pairs: </p> <div class="mw-highlight mw-highlight-lang-ocaml mw-content-ltr" dir="ltr"><pre><span></span><span class="o">#</span> <span class="k">let</span> <span class="n">m</span> <span class="o">=</span> <span class="o">[</span> <span class="s2">&quot;Sally Smart&quot;</span><span class="o">,</span> <span class="s2">&quot;555-9999&quot;</span><span class="o">;</span> <span class="s2">&quot;John Doe&quot;</span><span class="o">,</span> <span class="s2">&quot;555-1212&quot;</span><span class="o">;</span> <span class="s2">&quot;J. Random Hacker&quot;</span><span class="o">,</span> <span class="s2">&quot;553-1337&quot;</span><span class="o">];;</span> <span class="k">val</span> <span class="n">m</span> <span class="o">:</span> <span class="o">(</span><span class="kt">string</span> <span class="o">*</span> <span class="kt">string</span><span class="o">)</span> <span class="kt">list</span> <span class="o">=</span> <span class="o">[</span> <span class="o">(</span><span class="s2">&quot;Sally Smart&quot;</span><span class="o">,</span> <span class="s2">&quot;555-9999&quot;</span><span class="o">);</span> <span class="o">(</span><span class="s2">&quot;John Doe&quot;</span><span class="o">,</span> <span class="s2">&quot;555-1212&quot;</span><span class="o">);</span> <span class="o">(</span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="o">,</span> <span class="s2">&quot;553-1337&quot;</span><span class="o">)</span> <span class="o">]</span> <span class="o">#</span> <span class="nn">List</span><span class="p">.</span><span class="n">assoc</span> <span class="s2">&quot;John Doe&quot;</span> <span class="n">m</span><span class="o">;;</span> <span class="o">-</span> <span class="o">:</span> <span class="kt">string</span> <span class="o">=</span> <span class="s2">&quot;555-1212&quot;</span> </pre></div> <p>The second is a polymorphic hash table: </p> <div class="mw-highlight mw-highlight-lang-ocaml mw-content-ltr" dir="ltr"><pre><span></span><span class="o">#</span> <span class="k">let</span> <span class="n">m</span> <span class="o">=</span> <span class="nn">Hashtbl</span><span class="p">.</span><span class="n">create</span> <span class="mi">3</span><span class="o">;;</span> <span class="k">val</span> <span class="n">m</span> <span class="o">:</span> <span class="o">(</span><span class="k">&#39;</span><span class="o">_</span><span class="n">a</span><span class="o">,</span> <span class="k">&#39;</span><span class="o">_</span><span class="n">b</span><span class="o">)</span> <span class="nn">Hashtbl</span><span class="p">.</span><span class="n">t</span> <span class="o">=</span> <span class="o">&lt;</span><span class="n">abstr</span><span class="o">&gt;</span> <span class="o">#</span> <span class="nn">Hashtbl</span><span class="p">.</span><span class="n">add</span> <span class="n">m</span> <span class="s2">&quot;Sally Smart&quot;</span> <span class="s2">&quot;555-9999&quot;</span><span class="o">;</span> <span class="nn">Hashtbl</span><span class="p">.</span><span class="n">add</span> <span class="n">m</span> <span class="s2">&quot;John Doe&quot;</span> <span class="s2">&quot;555-1212&quot;</span><span class="o">;</span> <span class="nn">Hashtbl</span><span class="p">.</span><span class="n">add</span> <span class="n">m</span> <span class="s2">&quot;J. Random Hacker&quot;</span> <span class="s2">&quot;553-1337&quot;</span><span class="o">;;</span> <span class="o">-</span> <span class="o">:</span> <span class="kt">unit</span> <span class="o">=</span> <span class="bp">()</span> <span class="o">#</span> <span class="nn">Hashtbl</span><span class="p">.</span><span class="n">find</span> <span class="n">m</span> <span class="s2">&quot;John Doe&quot;</span><span class="o">;;</span> <span class="o">-</span> <span class="o">:</span> <span class="kt">string</span> <span class="o">=</span> <span class="s2">&quot;555-1212&quot;</span> </pre></div> <p>The code above uses OCaml's default hash function <code>Hashtbl.hash</code>, which is defined automatically for all types. To use a modified hash function, use the functor interface <code>Hashtbl.Make</code> to create a module, such as with <code>Map</code>. </p><p>Finally, functional maps (represented as immutable balanced binary trees): </p> <div class="mw-highlight mw-highlight-lang-ocaml mw-content-ltr" dir="ltr"><pre><span></span><span class="o">#</span> <span class="k">module</span> <span class="nc">StringMap</span> <span class="o">=</span> <span class="nn">Map</span><span class="p">.</span><span class="nc">Make</span><span class="o">(</span><span class="nc">String</span><span class="o">);;</span> <span class="o">...</span> <span class="o">#</span> <span class="k">let</span> <span class="n">m</span> <span class="o">=</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">add</span> <span class="s2">&quot;Sally Smart&quot;</span> <span class="s2">&quot;555-9999&quot;</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">empty</span> <span class="k">let</span> <span class="n">m</span> <span class="o">=</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">add</span> <span class="s2">&quot;John Doe&quot;</span> <span class="s2">&quot;555-1212&quot;</span> <span class="n">m</span> <span class="k">let</span> <span class="n">m</span> <span class="o">=</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">add</span> <span class="s2">&quot;J. Random Hacker&quot;</span> <span class="s2">&quot;553-1337&quot;</span> <span class="n">m</span><span class="o">;;</span> <span class="k">val</span> <span class="n">m</span> <span class="o">:</span> <span class="kt">string</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">t</span> <span class="o">=</span> <span class="o">&lt;</span><span class="n">abstr</span><span class="o">&gt;</span> <span class="o">#</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">find</span> <span class="s2">&quot;John Doe&quot;</span> <span class="n">m</span><span class="o">;;</span> <span class="o">-</span> <span class="o">:</span> <span class="kt">string</span> <span class="o">=</span> <span class="s2">&quot;555-1212&quot;</span> </pre></div> <p>Note that in order to use <code>Map</code>, you have to provide the functor <code>Map.Make</code> with a module which defines the key type and the comparison function. The third-party library ExtLib provides a polymorphic version of functional maps, called <code>PMap</code>,<sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">&#91;</span>12<span class="cite-bracket">&#93;</span></a></sup> which is given a comparison function upon creation. </p><p>Lists of pairs and functional maps both provide a purely functional interface. By contrast, hash tables provide an imperative interface. For many operations, hash tables are significantly faster than lists of pairs and functional maps. </p> <div class="mw-heading mw-heading3"><h3 id="OptimJ">OptimJ</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=44" title="Edit section: OptimJ"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1251242444">.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}</style><table class="box-More_citations_needed_section plainlinks metadata ambox ambox-content ambox-Refimprove" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span typeof="mw:File"><a href="/wiki/File:Question_book-new.svg" class="mw-file-description"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/50px-Question_book-new.svg.png" decoding="async" width="50" height="39" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/75px-Question_book-new.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/100px-Question_book-new.svg.png 2x" data-file-width="512" data-file-height="399" /></a></span></div></td><td class="mbox-text"><div class="mbox-text-span">This section <b>needs additional citations for <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">verification</a></b>.<span class="hide-when-compact"> Please help <a href="/wiki/Special:EditPage/Comparison_of_programming_languages_(associative_array)" title="Special:EditPage/Comparison of programming languages (associative array)">improve this article</a> by <a href="/wiki/Help:Referencing_for_beginners" title="Help:Referencing for beginners">adding citations to reliable sources</a>&#32;in this section. Unsourced material may be challenged and removed.</span> <span class="date-container"><i>(<span class="date">February 2011</span>)</i></span><span class="hide-when-compact"><i> (<small><a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove this message</a></small>)</i></span></div></td></tr></tbody></table> <p>The <a href="/wiki/OptimJ" title="OptimJ">OptimJ</a> programming language is an extension of Java 5. As does Java, Optimj provides maps; but OptimJ also provides true associative arrays. Java arrays are indexed with non-negative integers; associative arrays are indexed with any type of key. </p> <div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">String</span><span class="o">[</span><span class="n">String</span><span class="o">]</span><span class="w"> </span><span class="n">phoneBook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span> <span class="p">};</span> <span class="c1">// String[String] is not a java type but an optimj type:</span> <span class="c1">// associative array of strings indexed by strings.</span> <span class="c1">// iterate over the values</span> <span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">number</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">phoneBook</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">number</span><span class="p">);</span> <span class="p">}</span> <span class="c1">// The previous statement prints: &quot;555-9999&quot; &quot;555-1212&quot; &quot;553-1337&quot;</span> <span class="c1">// iterate over the keys</span> <span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">phoneBook</span><span class="p">.</span><span class="na">keys</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">name</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot; -&gt; &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">phoneBook</span><span class="o">[</span><span class="n">name</span><span class="o">]</span><span class="p">);</span> <span class="p">}</span> <span class="c1">// phoneBook[name] access a value by a key (it looks like java array access)</span> <span class="c1">// i.e. phoneBook[&quot;John Doe&quot;] returns &quot;555-1212&quot;</span> </pre></div> <p>Of course, it is possible to define multi-dimensional arrays, to mix Java arrays and associative arrays, to mix maps and associative arrays. </p> <div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="o">[</span><span class="n">String</span><span class="o">][][</span><span class="kt">double</span><span class="o">]</span><span class="w"> </span><span class="n">a</span><span class="p">;</span> <span class="n">java</span><span class="p">.</span><span class="na">util</span><span class="p">.</span><span class="na">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">[</span><span class="n">Object</span><span class="o">]</span><span class="p">,</span><span class="w"> </span><span class="n">Integer</span><span class="o">&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Perl_5">Perl 5</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=45" title="Edit section: Perl 5"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Perl_5" class="mw-redirect" title="Perl 5">Perl 5</a> has built-in, language-level support for associative arrays. Modern Perl refers to associative arrays as <i>hashes</i>; the term <i>associative array</i> is found in older documentation but is considered somewhat archaic. Perl 5 hashes are flat: keys are strings and values are scalars. However, values may be <a href="/wiki/Reference_(computer_science)" title="Reference (computer science)">references</a> to arrays or other hashes, and the standard Perl 5 module Tie::RefHash enables hashes to be used with reference keys. </p><p>A hash variable is marked by a <code>%</code> <a href="/wiki/Sigil_(computer_programming)" title="Sigil (computer programming)">sigil</a>, to distinguish it from scalar, array, and other data types. A hash literal is a key-value list, with the preferred form using Perl's <code>=&gt;</code> token, which is semantically mostly identical to the comma and makes the key-value association clearer: </p> <div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">my</span><span class="w"> </span><span class="nv">%phone_book</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span> <span class="w"> </span><span class="s">&#39;Sally Smart&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&#39;555-9999&#39;</span><span class="p">,</span> <span class="w"> </span><span class="s">&#39;John Doe&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&#39;555-1212&#39;</span><span class="p">,</span> <span class="w"> </span><span class="s">&#39;J. Random Hacker&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&#39;553-1337&#39;</span><span class="p">,</span> <span class="p">);</span> </pre></div> <p>Accessing a hash element uses the syntax <code>$hash_name{$key}</code> – the key is surrounded by <a href="/wiki/Bracket#Curly_bracket" title="Bracket">curly braces</a> and the hash name is prefixed by a <code>$</code>, indicating that the hash element itself is a scalar value, even though it is part of a hash. The value of <code>$phone_book{'John Doe'}</code> is <code>'555-1212'</code>. The <code>%</code> sigil is only used when referring to the hash as a whole, such as when asking for <code>keys %phone_book</code>. </p><p>The list of keys and values can be extracted using the built-in functions <code>keys</code> and <code>values</code>, respectively. So, for example, to print all the keys of a hash: </p> <div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">foreach</span><span class="w"> </span><span class="nv">$name</span><span class="w"> </span><span class="p">(</span><span class="nb">keys</span><span class="w"> </span><span class="nv">%phone_book</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">print</span><span class="w"> </span><span class="nv">$name</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;\n&quot;</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>One can iterate through (key, value) pairs using the <code>each</code> function: </p> <div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">while</span><span class="w"> </span><span class="p">((</span><span class="nv">$name</span><span class="p">,</span><span class="w"> </span><span class="nv">$number</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">each</span><span class="w"> </span><span class="nv">%phone_book</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">print</span><span class="w"> </span><span class="s">&#39;Number for &#39;</span><span class="p">,</span><span class="w"> </span><span class="nv">$name</span><span class="p">,</span><span class="w"> </span><span class="s">&#39;: &#39;</span><span class="p">,</span><span class="w"> </span><span class="nv">$number</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;\n&quot;</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>A hash "reference", which is a scalar value that points to a hash, is specified in literal form using curly braces as delimiters, with syntax otherwise similar to specifying a hash literal: </p> <div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">my</span><span class="w"> </span><span class="nv">$phone_book</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="s">&#39;Sally Smart&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&#39;555-9999&#39;</span><span class="p">,</span> <span class="w"> </span><span class="s">&#39;John Doe&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&#39;555-1212&#39;</span><span class="p">,</span> <span class="w"> </span><span class="s">&#39;J. Random Hacker&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">&#39;553-1337&#39;</span><span class="p">,</span> <span class="p">};</span> </pre></div> <p>Values in a hash reference are accessed using the dereferencing operator: </p> <div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">print</span><span class="w"> </span><span class="nv">$phone_book</span><span class="o">-&gt;</span><span class="p">{</span><span class="s">&#39;Sally Smart&#39;</span><span class="p">};</span> </pre></div> <p>When the hash contained in the hash reference needs to be referred to as a whole, as with the <code>keys</code> function, the syntax is as follows: </p> <div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">foreach</span><span class="w"> </span><span class="nv">$name</span><span class="w"> </span><span class="p">(</span><span class="nb">keys</span><span class="w"> </span><span class="nv">%</span><span class="p">{</span><span class="nv">$phone_book</span><span class="p">})</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">print</span><span class="w"> </span><span class="s">&#39;Number for &#39;</span><span class="p">,</span><span class="w"> </span><span class="nv">$name</span><span class="p">,</span><span class="w"> </span><span class="s">&#39;: &#39;</span><span class="p">,</span><span class="w"> </span><span class="nv">$phone_book</span><span class="o">-&gt;</span><span class="p">{</span><span class="nv">$name</span><span class="p">},</span><span class="w"> </span><span class="s">&quot;\n&quot;</span><span class="p">;</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Perl_6_(Raku)"><span id="Perl_6_.28Raku.29"></span>Perl 6 (Raku)</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=46" title="Edit section: Perl 6 (Raku)"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Raku_(programming_language)" title="Raku (programming language)">Perl 6</a>, renamed as "Raku", also has built-in, language-level support for associative arrays, which are referred to as <i>hashes</i> or as objects performing the "associative" role. As in Perl 5, Perl 6 default hashes are flat: keys are strings and values are scalars. One can define a hash to not coerce all keys to strings automatically: these are referred to as "object hashes", because the keys of such hashes remain the original object rather than a stringification thereof. </p><p>A hash variable is typically marked by a <code>%</code> <a href="/wiki/Sigil_(computer_programming)" title="Sigil (computer programming)">sigil</a>, to visually distinguish it from scalar, array, and other data types, and to define its behaviour towards iteration. A hash literal is a key-value list, with the preferred form using Perl's <code>=&gt;</code> token, which makes the key-value association clearer: </p> <div class="mw-highlight mw-highlight-lang-perl6 mw-content-ltr" dir="ltr"><pre><span></span><span class="k">my</span> <span class="nv">%phone-book</span> = <span class="s">&#39;Sally Smart&#39;</span> =&gt; <span class="s">&#39;555-9999&#39;</span>, <span class="s">&#39;John Doe&#39;</span> =&gt; <span class="s">&#39;555-1212&#39;</span>, <span class="s">&#39;J. Random Hacker&#39;</span> =&gt; <span class="s">&#39;553-1337&#39;</span>, ; </pre></div> <p>Accessing a hash element uses the syntax <code>%hash_name{$key}</code> – the key is surrounded by curly braces and the hash name (note that the sigil does <b>not</b> change, contrary to Perl 5). The value of <code>%phone-book{'John Doe'}</code> is <code>'555-1212'</code>. </p><p>The list of keys and values can be extracted using the built-in functions <code>keys</code> and <code>values</code>, respectively. So, for example, to print all the keys of a hash: </p> <div class="mw-highlight mw-highlight-lang-perl6 mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span> <span class="nv">%phone-book</span>.<span class="nb">keys</span> -&gt; <span class="nv">$name</span> { <span class="nb">say</span> <span class="nv">$name</span>; } </pre></div> <p>By default, when iterating through a hash, one gets key–value pairs. </p> <div class="mw-highlight mw-highlight-lang-perl6 mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span> <span class="nv">%phone-book</span> -&gt; <span class="nv">$entry</span> { <span class="nb">say</span> <span class="s">&quot;Number for $entry.key(): $entry.value()&quot;</span>; <span class="c1"># using extended interpolation features</span> } </pre></div> <p>It is also possible to get alternating key values and value values by using the <code>kv</code> method: </p> <div class="mw-highlight mw-highlight-lang-perl6 mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span> <span class="nv">%phone-book</span>.<span class="nb">kv</span> -&gt; <span class="nv">$name</span>, <span class="nv">$number</span> { <span class="nb">say</span> <span class="s">&quot;Number for $name: $number&quot;</span>; } </pre></div> <p>Raku doesn't have any references. Hashes can be passed as single parameters that are not flattened. If you want to make sure that a subroutine only accepts hashes, use the <i>%</i> sigil in the Signature. </p> <div class="mw-highlight mw-highlight-lang-perl6 mw-content-ltr" dir="ltr"><pre><span></span><span class="k">sub</span> <span class="n">list-phone-book</span>(<span class="nv">%pb</span>) { <span class="k">for</span> <span class="nv">%pb</span>.<span class="nb">kv</span> -&gt; <span class="nv">$name</span>, <span class="nv">$number</span> { <span class="nb">say</span> <span class="s">&quot;Number for $name: $number&quot;</span>; } } <span class="n">list-phone-book</span>(<span class="nv">%phone-book</span>); </pre></div> <p>In compliance with <a href="/wiki/Gradual_typing" title="Gradual typing">gradual typing</a>, hashes may be subjected to type constraints, confining a set of valid keys to a certain type. </p> <div class="mw-highlight mw-highlight-lang-perl6 mw-content-ltr" dir="ltr"><pre><span></span><span class="c1"># Define a hash whose keys may only be integer numbers (&quot;Int&quot; type).</span> <span class="k">my</span> <span class="nv">%numbersWithNames</span>{<span class="nb">Int</span>}; <span class="c1"># Keys must be integer numbers, as in this case.</span> <span class="nv">%numbersWithNames</span>.<span class="nb">push</span>(<span class="mi">1</span> =&gt; <span class="s">&quot;one&quot;</span>); <span class="c1"># This will cause an error, as strings as keys are invalid.</span> <span class="nv">%numbersWithNames</span>.<span class="nb">push</span>(<span class="s">&quot;key&quot;</span> =&gt; <span class="s">&quot;two&quot;</span>); </pre></div> <div class="mw-heading mw-heading3"><h3 id="PHP">PHP</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=47" title="Edit section: PHP"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/PHP" title="PHP">PHP</a>'s built-in array type is, in reality, an associative array. Even when using numerical indexes, PHP internally stores arrays as associative arrays.<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">&#91;</span>13<span class="cite-bracket">&#93;</span></a></sup> So, PHP can have non-consecutively numerically indexed arrays. The keys have to be of integer (floating point numbers are truncated to integer) or string type, while values can be of arbitrary types, including other arrays and objects. The arrays are heterogeneous: a single array can have keys of different types. PHP's associative arrays can be used to represent trees, lists, stacks, queues, and other common data structures not built into PHP. </p><p>An associative array can be declared using the following syntax: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$phonebook</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span> <span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;Sally Smart&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;555-9999&#39;</span><span class="p">;</span> <span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;John Doe&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">;</span> <span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;555-1337&#39;</span><span class="p">;</span> <span class="c1">// or</span> <span class="nv">$phonebook</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;Sally Smart&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;555-9999&#39;</span><span class="p">,</span> <span class="s1">&#39;John Doe&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">,</span> <span class="s1">&#39;J. Random Hacker&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;555-1337&#39;</span><span class="p">,</span> <span class="p">);</span> <span class="c1">// or, as of PHP 5.4</span> <span class="nv">$phonebook</span> <span class="o">=</span> <span class="p">[</span> <span class="s1">&#39;Sally Smart&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;555-9999&#39;</span><span class="p">,</span> <span class="s1">&#39;John Doe&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">,</span> <span class="s1">&#39;J. Random Hacker&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;555-1337&#39;</span><span class="p">,</span> <span class="p">];</span> <span class="c1">// or</span> <span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;contacts&#39;</span><span class="p">][</span><span class="s1">&#39;Sally Smart&#39;</span><span class="p">][</span><span class="s1">&#39;number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;555-9999&#39;</span><span class="p">;</span> <span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;contacts&#39;</span><span class="p">][</span><span class="s1">&#39;John Doe&#39;</span><span class="p">][</span><span class="s1">&#39;number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">;</span> <span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;contacts&#39;</span><span class="p">][</span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">][</span><span class="s1">&#39;number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;555-1337&#39;</span><span class="p">;</span> </pre></div> <p>PHP can loop through an associative array as follows: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">foreach</span> <span class="p">(</span><span class="nv">$phonebook</span> <span class="k">as</span> <span class="nv">$name</span> <span class="o">=&gt;</span> <span class="nv">$number</span><span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Number for &#39;</span><span class="p">,</span> <span class="nv">$name</span><span class="p">,</span> <span class="s1">&#39;: &#39;</span><span class="p">,</span> <span class="nv">$number</span><span class="p">,</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// For the last array example it is used like this</span> <span class="k">foreach</span> <span class="p">(</span><span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;contacts&#39;</span><span class="p">]</span> <span class="k">as</span> <span class="nv">$name</span> <span class="o">=&gt;</span> <span class="nv">$num</span><span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Name: &#39;</span><span class="p">,</span> <span class="nv">$name</span><span class="p">,</span> <span class="s1">&#39;, number: &#39;</span><span class="p">,</span> <span class="nv">$num</span><span class="p">[</span><span class="s1">&#39;number&#39;</span><span class="p">],</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>PHP has an extensive set of functions to operate on arrays.<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p>Associative arrays that can use objects as keys, instead of strings and integers, can be implemented with the <code>SplObjectStorage</code> class from the Standard PHP Library (SPL).<sup id="cite_ref-15" class="reference"><a href="#cite_note-15"><span class="cite-bracket">&#91;</span>15<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Pike">Pike</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=48" title="Edit section: Pike"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Pike_(programming_language)" title="Pike (programming language)">Pike</a> has built-in support for associative arrays, which are referred to as mappings. Mappings are created as follows: </p> <div class="mw-highlight mw-highlight-lang-pike mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">mapping</span><span class="p">(</span><span class="kt">string</span><span class="o">:</span><span class="kt">string</span><span class="p">)</span><span class="w"> </span><span class="n">phonebook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">([</span> <span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="o">:</span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="o">:</span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="o">:</span><span class="s">&quot;555-1337&quot;</span> <span class="p">]);</span> </pre></div> <p>Accessing and testing for presence in mappings is done using the indexing operator. So <code>phonebook["Sally Smart"]</code> would return the string <code>"555-9999"</code>, and <code>phonebook["John Smith"]</code> would return 0. </p><p>Iterating through a mapping can be done using <code>foreach</code>: </p> <div class="mw-highlight mw-highlight-lang-pike mw-content-ltr" dir="ltr"><pre><span></span><span class="n">foreach</span><span class="p">(</span><span class="n">phonebook</span><span class="p">;</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="n">key</span><span class="p">;</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="n">value</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">write</span><span class="p">(</span><span class="s">&quot;%s:%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">key</span><span class="p">,</span><span class="w"> </span><span class="n">value</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p>Or using an iterator object: </p> <div class="mw-highlight mw-highlight-lang-pike mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Mapping</span><span class="p">.</span><span class="n">Iterator</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get_iterator</span><span class="p">(</span><span class="n">phonebook</span><span class="p">);</span> <span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="o">-&gt;</span><span class="n">index</span><span class="p">())</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">write</span><span class="p">(</span><span class="s">&quot;%s:%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="o">-&gt;</span><span class="n">index</span><span class="p">(),</span><span class="w"> </span><span class="n">i</span><span class="o">-&gt;</span><span class="n">value</span><span class="p">());</span> <span class="w"> </span><span class="n">i</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">();</span> <span class="p">}</span> </pre></div> <p>Elements of a mapping can be removed using <code>m_delete</code>, which returns the value of the removed index: </p> <div class="mw-highlight mw-highlight-lang-pike mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">string</span><span class="w"> </span><span class="n">sallys_number</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">m_delete</span><span class="p">(</span><span class="n">phonebook</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="p">);</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="PostScript">PostScript</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=49" title="Edit section: PostScript"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/PostScript" title="PostScript">PostScript</a>, associative arrays are called dictionaries. In Level 1 PostScript they must be created explicitly, but Level 2 introduced direct declaration using a double-angled-bracket syntax: </p> <div class="mw-highlight mw-highlight-lang-postscript mw-content-ltr" dir="ltr"><pre><span></span><span class="w"> </span><span class="c1">% Level 1 declaration</span> <span class="w"> </span><span class="mf">3</span><span class="w"> </span><span class="nf">dict</span><span class="w"> </span><span class="nf">dup</span><span class="w"> </span><span class="nf">begin</span> <span class="w"> </span><span class="nv">/red</span><span class="w"> </span><span class="s">(rouge)</span><span class="w"> </span><span class="nf">def</span> <span class="w"> </span><span class="nv">/green</span><span class="w"> </span><span class="s">(vert)</span><span class="w"> </span><span class="nf">def</span> <span class="w"> </span><span class="nv">/blue</span><span class="w"> </span><span class="s">(bleu)</span><span class="w"> </span><span class="nf">def</span> <span class="w"> </span><span class="nf">end</span> <span class="w"> </span><span class="c1">% Level 2 declaration</span> <span class="w"> </span><span class="p">&lt;&lt;</span> <span class="w"> </span><span class="nv">/red</span><span class="w"> </span><span class="s">(rot)</span> <span class="w"> </span><span class="nv">/green</span><span class="w"> </span><span class="s">(gruen)</span> <span class="w"> </span><span class="nv">/blue</span><span class="w"> </span><span class="s">(blau)</span> <span class="w"> </span><span class="p">&gt;&gt;</span> <span class="w"> </span><span class="c1">% Both methods leave the dictionary on the operand stack</span> </pre></div> <p>Dictionaries can be accessed directly, using <code>get</code>, or implicitly, by placing the dictionary on the dictionary stack using <code>begin</code>: </p> <div class="mw-highlight mw-highlight-lang-postscript mw-content-ltr" dir="ltr"><pre><span></span><span class="w"> </span><span class="c1">% With the previous two dictionaries still on the operand stack</span> <span class="w"> </span><span class="nv">/red</span><span class="w"> </span><span class="nf">get</span><span class="w"> </span><span class="nf">print</span><span class="w"> </span><span class="c1">% outputs &#39;rot&#39;</span> <span class="w"> </span><span class="nf">begin</span> <span class="w"> </span><span class="nf">green</span><span class="w"> </span><span class="nf">print</span><span class="w"> </span><span class="c1">% outputs &#39;vert&#39;</span> <span class="w"> </span><span class="nf">end</span> </pre></div> <p>Dictionary contents can be iterated through using <code>forall</code>, though not in any particular order: </p> <div class="mw-highlight mw-highlight-lang-postscript mw-content-ltr" dir="ltr"><pre><span></span><span class="w"> </span><span class="c1">% Level 2 example</span> <span class="w"> </span><span class="p">&lt;&lt;</span> <span class="w"> </span><span class="nv">/This</span><span class="w"> </span><span class="mf">1</span> <span class="w"> </span><span class="nv">/That</span><span class="w"> </span><span class="mf">2</span> <span class="w"> </span><span class="nv">/Other</span><span class="w"> </span><span class="mf">3</span> <span class="w"> </span><span class="p">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="nf">exch</span><span class="w"> </span><span class="nf">=print</span><span class="w"> </span><span class="s">( is )</span><span class="w"> </span><span class="nf">print</span><span class="w"> </span><span class="nf">==</span><span class="p">}</span><span class="w"> </span><span class="nf">forall</span> </pre></div> <p>Which may output: </p> <div class="mw-highlight mw-highlight-lang-postscript mw-content-ltr" dir="ltr"><pre><span></span><span class="w"> </span><span class="nf">That</span><span class="w"> </span><span class="nf">is</span><span class="w"> </span><span class="mf">2</span> <span class="w"> </span><span class="nf">This</span><span class="w"> </span><span class="nf">is</span><span class="w"> </span><span class="mf">1</span> <span class="w"> </span><span class="nf">Other</span><span class="w"> </span><span class="nf">is</span><span class="w"> </span><span class="mf">3</span> </pre></div> <p>Dictionaries can be augmented (up to their defined size only in Level 1) or altered using <code>put</code>, and entries can be removed using <code>undef</code>: </p> <div class="mw-highlight mw-highlight-lang-postscript mw-content-ltr" dir="ltr"><pre><span></span><span class="w"> </span><span class="c1">% define a dictionary for easy reuse:</span> <span class="w"> </span><span class="nv">/MyDict</span><span class="w"> </span><span class="p">&lt;&lt;</span> <span class="w"> </span><span class="nv">/rouge</span><span class="w"> </span><span class="s">(red)</span> <span class="w"> </span><span class="nv">/vert</span><span class="w"> </span><span class="s">(gruen)</span> <span class="w"> </span><span class="p">&gt;&gt;</span><span class="w"> </span><span class="nf">def</span> <span class="w"> </span><span class="c1">% add to it</span> <span class="w"> </span><span class="nf">MyDict</span><span class="w"> </span><span class="nv">/bleu</span><span class="w"> </span><span class="s">(blue)</span><span class="w"> </span><span class="nf">put</span> <span class="w"> </span><span class="c1">% change it</span> <span class="w"> </span><span class="nf">MyDict</span><span class="w"> </span><span class="nv">/vert</span><span class="w"> </span><span class="s">(green)</span><span class="w"> </span><span class="nf">put</span> <span class="w"> </span><span class="c1">% remove something</span> <span class="w"> </span><span class="nf">MyDict</span><span class="w"> </span><span class="nv">/rouge</span><span class="w"> </span><span class="nf">undef</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Prolog">Prolog</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=50" title="Edit section: Prolog"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Some versions of <a href="/wiki/Prolog" title="Prolog">Prolog</a> include dictionary ("dict") utilities.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">&#91;</span>16<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Python">Python</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=51" title="Edit section: Python"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Python_(programming_language)" title="Python (programming language)">Python</a>, associative arrays are called "<a href="/wiki/Python_syntax_and_semantics#Collection_types" title="Python syntax and semantics">dictionaries</a>". Dictionary literals are delimited by curly braces: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">&quot;Sally Smart&quot;</span><span class="p">:</span> <span class="s2">&quot;555-9999&quot;</span><span class="p">,</span> <span class="s2">&quot;John Doe&quot;</span><span class="p">:</span> <span class="s2">&quot;555-1212&quot;</span><span class="p">,</span> <span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">:</span> <span class="s2">&quot;553-1337&quot;</span><span class="p">,</span> <span class="p">}</span> </pre></div> <p>Dictionary items can be accessed using the array indexing operator: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="n">phonebook</span><span class="p">[</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">]</span> <span class="s1">&#39;555-9999&#39;</span> </pre></div> <p>Loop <a href="/wiki/Iterator#Python" title="Iterator">iterating</a> through all the keys of the dictionary: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">phonebook</span><span class="p">:</span> <span class="o">...</span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">phonebook</span><span class="p">[</span><span class="n">key</span><span class="p">])</span> <span class="n">Sally</span> <span class="n">Smart</span> <span class="mi">555</span><span class="o">-</span><span class="mi">9999</span> <span class="n">J</span><span class="o">.</span> <span class="n">Random</span> <span class="n">Hacker</span> <span class="mi">553</span><span class="o">-</span><span class="mi">1337</span> <span class="n">John</span> <span class="n">Doe</span> <span class="mi">555</span><span class="o">-</span><span class="mi">1212</span> </pre></div> <p>Iterating through (key, value) tuples: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">phonebook</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> <span class="o">...</span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="n">Sally</span> <span class="n">Smart</span> <span class="mi">555</span><span class="o">-</span><span class="mi">9999</span> <span class="n">J</span><span class="o">.</span> <span class="n">Random</span> <span class="n">Hacker</span> <span class="mi">553</span><span class="o">-</span><span class="mi">1337</span> <span class="n">John</span> <span class="n">Doe</span> <span class="mi">555</span><span class="o">-</span><span class="mi">1212</span> </pre></div> <p>Dictionary keys can be individually deleted using the <code>del</code> statement. The corresponding value can be returned before the key-value pair is deleted using the "pop" method of "dict" type: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="k">del</span> <span class="n">phonebook</span><span class="p">[</span><span class="s2">&quot;John Doe&quot;</span><span class="p">]</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">val</span> <span class="o">=</span> <span class="n">phonebook</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">)</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">phonebook</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> <span class="c1"># Only one key left</span> <span class="p">[</span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">]</span> </pre></div> <p>Python 2.7 and 3.x also support <a rel="nofollow" class="external text" href="https://peps.python.org/pep-0274/">dict comprehensions</a> (similar to <a href="/wiki/List_comprehension" title="List comprehension">list comprehensions</a>), a compact syntax for generating a dictionary from any iterator: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="n">square_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">i</span><span class="p">:</span> <span class="n">i</span><span class="o">*</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)}</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">square_dict</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">:</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">4</span><span class="p">:</span> <span class="mi">16</span><span class="p">}</span> <span class="o">&gt;&gt;&gt;</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="n">value</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">phonebook</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="s2">&quot;J&quot;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">}</span> <span class="p">{</span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">:</span> <span class="s1">&#39;553-1337&#39;</span><span class="p">,</span> <span class="s1">&#39;John Doe&#39;</span><span class="p">:</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">}</span> </pre></div> <p>Strictly speaking, a dictionary is a super-set of an associative array, since neither the keys or values are limited to a single datatype. One could think of a dictionary as an "associative list" using the nomenclature of Python. For example, the following is also legitimate: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">&quot;Sally Smart&quot;</span><span class="p">:</span> <span class="s2">&quot;555-9999&quot;</span><span class="p">,</span> <span class="s2">&quot;John Doe&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">:</span> <span class="o">-</span><span class="mf">3.32</span><span class="p">,</span> <span class="mi">14</span><span class="p">:</span> <span class="s2">&quot;555-3322&quot;</span><span class="p">,</span> <span class="p">}</span> </pre></div> <p>The dictionary keys must be of an <a href="/wiki/Immutable_object" title="Immutable object">immutable</a> data type. In Python, strings are immutable due to their method of implementation. </p> <div class="mw-heading mw-heading3"><h3 id="Red">Red</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=52" title="Edit section: Red"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Red_(programming_language)" title="Red (programming language)">Red</a> the built-in <code>map!</code><sup id="cite_ref-17" class="reference"><a href="#cite_note-17"><span class="cite-bracket">&#91;</span>17<span class="cite-bracket">&#93;</span></a></sup> datatype provides an associative array that maps values of word, string, and scalar key types to values of any type. A hash table is used internally for lookup. </p><p>A map can be written as a literal, such as <code>#(key1 value1 key2 value2 ...)</code>, or can be created using <code>make map! [key1 value1 key2 value2 ...]</code>: </p> <div class="mw-highlight mw-highlight-lang-red mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">Red</span> <span class="gs">[</span><span class="gu">Title:</span><span class="s">&quot;My map&quot;</span><span class="gs">]</span> <span class="gu">my-map:</span> <span class="nf">make</span> <span class="kt">map!</span> <span class="gs">[</span> <span class="s">&quot;Sally Smart&quot;</span> <span class="s">&quot;555-9999&quot;</span> <span class="s">&quot;John Doe&quot;</span> <span class="s">&quot;555-1212&quot;</span> <span class="s">&quot;J. Random Hacker&quot;</span> <span class="s">&quot;553-1337&quot;</span> <span class="gs">]</span> <span class="c">; Red preserves case for both keys and values, however lookups are case insensitive by default; it is possible to force case sensitivity using the &lt;code&gt;/case&lt;/code&gt; refinement for &lt;code&gt;select&lt;/code&gt; and &lt;code&gt;put&lt;/code&gt;.</span> <span class="c">; It is of course possible to use &lt;code&gt;word!&lt;/code&gt; values as keys, in which case it is generally preferred to use &lt;code&gt;set-word!&lt;/code&gt; values when creating the map, but any word type can be used for lookup or creation.</span> <span class="gu">my-other-map:</span> <span class="nf">make</span> <span class="kt">map!</span> <span class="gs">[</span><span class="gu">foo:</span> <span class="m">42</span> <span class="gu">bar:</span> <span class="bp">false</span><span class="gs">]</span> <span class="c">; Notice that the block is not reduced or evaluated in any way, therefore in the above example the key &lt;code&gt;bar&lt;/code&gt; is associated with the &lt;code&gt;word!&lt;/code&gt; &lt;code&gt;false&lt;/code&gt; rather than the &lt;code&gt;logic!&lt;/code&gt; value false; literal syntax can be used if the latter is desired:</span> <span class="gu">my-other-map:</span> <span class="nf">make</span> <span class="kt">map!</span> <span class="gs">[</span><span class="gu">foo:</span> <span class="m">42</span> <span class="gu">bar:</span> <span class="nl">#</span><span class="gs">[</span><span class="bp">false</span><span class="gs">]]</span> <span class="c">; or keys can be added after creation:</span> <span class="gu">my-other-map:</span> <span class="nf">make</span> <span class="kt">map!</span> <span class="gs">[</span><span class="gu">foo:</span> <span class="m">42</span><span class="gs">]</span> <span class="nv">my-other-map</span><span class="na">/bar:</span> <span class="bp">false</span> <span class="c">; Lookup can be written using &lt;code&gt;path!&lt;/code&gt; notation or using the &lt;code&gt;select&lt;/code&gt; action:</span> <span class="nf">select</span> <span class="nv">my-map</span> <span class="s">&quot;Sally Smart&quot;</span> <span class="nv">my-other-map</span><span class="na">/foo</span> <span class="c">; You can also loop through all keys and values with &lt;code&gt;foreach&lt;/code&gt;:</span> <span class="nb">foreach</span> <span class="gs">[</span><span class="nv">key</span> <span class="nv">value</span><span class="gs">]</span> <span class="nv">my-map</span> <span class="gs">[</span> <span class="nb">print</span> <span class="gs">[</span><span class="nv">key</span> <span class="s">&quot;is associated to&quot;</span> <span class="nv">value</span><span class="gs">]</span> <span class="gs">]</span> <span class="c">; A key can be removed using &lt;code&gt;remove/key&lt;/code&gt;:</span> <span class="nf">remove</span><span class="na">/key</span> <span class="nv">my-map</span> <span class="s">&quot;Sally Smart&quot;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="REXX">REXX</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=53" title="Edit section: REXX"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/REXX" class="mw-redirect" title="REXX">REXX</a>, associative arrays are called "stem variables" or "Compound variables". </p> <div class="mw-highlight mw-highlight-lang-rexx mw-content-ltr" dir="ltr"><pre><span></span>KEY<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;Sally Smart&#39;</span> PHONEBOOK<span class="o">.</span>KEY<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;555-9999&#39;</span> KEY<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;John Doe&#39;</span> PHONEBOOK<span class="o">.</span>KEY<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;555-1212&#39;</span> KEY<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;J. Random Hacker&#39;</span> PHONEBOOK<span class="o">.</span>KEY<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;553-1337&#39;</span> </pre></div> <p>Stem variables with numeric keys typically start at 1 and go up from there. The 0-key stem variable by convention contains the total number of items in the stem: </p> <div class="mw-highlight mw-highlight-lang-rexx mw-content-ltr" dir="ltr"><pre><span></span>NAME<span class="o">.</span><span class="m">1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;Sally Smart&#39;</span> NAME<span class="o">.</span><span class="m">2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;John Doe&#39;</span> NAME<span class="o">.</span><span class="m">3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&#39;J. Random Hacker&#39;</span> NAME<span class="o">.</span><span class="m">0</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">3</span> </pre></div> <p>REXX has no easy way of automatically accessing the keys of a stem variable; and typically the keys are stored in a separate associative array, with numeric keys. </p> <div class="mw-heading mw-heading3"><h3 id="Ruby">Ruby</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=54" title="Edit section: Ruby"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Ruby_programming_language" class="mw-redirect" title="Ruby programming language">Ruby</a> a hash table is used as follows: </p> <div class="mw-highlight mw-highlight-lang-rb mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="s1">&#39;Sally Smart&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s1">&#39;555-9999&#39;</span><span class="p">,</span> <span class="w"> </span><span class="s1">&#39;John Doe&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s1">&#39;555-1212&#39;</span><span class="p">,</span> <span class="w"> </span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s1">&#39;553-1337&#39;</span> <span class="p">}</span> <span class="n">phonebook</span><span class="o">[</span><span class="s1">&#39;John Doe&#39;</span><span class="o">]</span> </pre></div> <p>Ruby supports hash looping and iteration with the following syntax: </p> <div class="mw-highlight mw-highlight-lang-irb mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">irb(main):007:0&gt; </span><span class="c1">### iterate over keys and values</span> <span class="gp">irb(main):008:0* </span><span class="n">phonebook</span><span class="o">.</span><span class="n">each</span><span class="w"> </span><span class="p">{</span><span class="o">|</span><span class="n">key</span><span class="p">,</span><span class="w"> </span><span class="n">value</span><span class="o">|</span><span class="w"> </span><span class="nb">puts</span><span class="w"> </span><span class="n">key</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">&quot; =&gt; &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">value</span><span class="p">}</span> <span class="go">Sally Smart =&gt; 555-9999</span> <span class="go">John Doe =&gt; 555-1212</span> <span class="go">J. Random Hacker =&gt; 553-1337</span> <span class="go">=&gt; {&quot;Sally Smart&quot;=&gt;&quot;555-9999&quot;, &quot;John Doe&quot;=&gt;&quot;555-1212&quot;, &quot;J. Random Hacker&quot;=&gt;&quot;553-1337&quot;}</span> <span class="gp">irb(main):009:0&gt; </span><span class="c1">### iterate keys only</span> <span class="gp">irb(main):010:0* </span><span class="n">phonebook</span><span class="o">.</span><span class="n">each_key</span><span class="w"> </span><span class="p">{</span><span class="o">|</span><span class="n">key</span><span class="o">|</span><span class="w"> </span><span class="nb">puts</span><span class="w"> </span><span class="n">key</span><span class="p">}</span> <span class="go">Sally Smart</span> <span class="go">John Doe</span> <span class="go">J. Random Hacker</span> <span class="go">=&gt; {&quot;Sally Smart&quot;=&gt;&quot;555-9999&quot;, &quot;John Doe&quot;=&gt;&quot;555-1212&quot;, &quot;J. Random Hacker&quot;=&gt;&quot;553-1337&quot;}</span> <span class="gp">irb(main):011:0&gt; </span><span class="c1">### iterate values only</span> <span class="gp">irb(main):012:0* </span><span class="n">phonebook</span><span class="o">.</span><span class="n">each_value</span><span class="w"> </span><span class="p">{</span><span class="o">|</span><span class="n">value</span><span class="o">|</span><span class="w"> </span><span class="nb">puts</span><span class="w"> </span><span class="n">value</span><span class="p">}</span> <span class="go">555-9999</span> <span class="go">555-1212</span> <span class="go">553-1337</span> <span class="go">=&gt; {&quot;Sally Smart&quot;=&gt;&quot;555-9999&quot;, &quot;John Doe&quot;=&gt;&quot;555-1212&quot;, &quot;J. Random Hacker&quot;=&gt;&quot;553-1337&quot;}</span> </pre></div> <p>Ruby also supports many other useful operations on hashes, such as merging hashes, selecting or rejecting elements that meet some criteria, inverting (swapping the keys and values), and flattening a hash into an array. </p> <div class="mw-heading mw-heading3"><h3 id="Rust">Rust</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=55" title="Edit section: Rust"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The <a href="/wiki/Rust_(programming_language)" title="Rust (programming language)">Rust</a> standard library provides a hash map (<code>std::collections::HashMap</code>) and a <a href="/wiki/B-tree" title="B-tree">B-tree</a> map (<code>std::collections::BTreeMap</code>). They share several methods with the same names, but have different requirements for the types of keys that can be inserted. The <code>HashMap</code> requires keys to implement the <code>Eq</code> (<a href="/wiki/Equivalence_relation" title="Equivalence relation">equivalence relation</a>) and <code>Hash</code> (hashability) traits and it stores entries in an unspecified order, and the <code>BTreeMap</code> requires the <code>Ord</code> (<a href="/wiki/Total_order" title="Total order">total order</a>) trait for its keys and it stores entries in an order defined by the key type. The order is reflected by the default iterators. </p> <div class="mw-highlight mw-highlight-lang-rust mw-content-ltr" dir="ltr"><pre><span></span><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">collections</span>::<span class="n">HashMap</span><span class="p">;</span> <span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">phone_book</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">HashMap</span>::<span class="n">new</span><span class="p">();</span> <span class="n">phone_book</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">);</span> <span class="n">phone_book</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">);</span> <span class="n">phone_book</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1337&quot;</span><span class="p">);</span> </pre></div> <p>The default iterators visit all entries as tuples. The <code>HashMap</code> iterators visit entries in an unspecified order and the <code>BTreeMap</code> iterator visits entries in the order defined by the key type. </p> <div class="mw-highlight mw-highlight-lang-rust mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">number</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">&amp;</span><span class="n">phone_book</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">&quot;{} {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">number</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p>There is also an iterator for keys: </p> <div class="mw-highlight mw-highlight-lang-rust mw-content-ltr" dir="ltr"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">phone_book</span><span class="p">.</span><span class="n">keys</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">name</span><span class="p">);</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="S-Lang">S-Lang</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=56" title="Edit section: S-Lang"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/S-Lang" title="S-Lang">S-Lang</a> has an associative array type: </p> <div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre><span></span>phonebook = Assoc_Type[]; phonebook[&quot;Sally Smart&quot;] = &quot;555-9999&quot; phonebook[&quot;John Doe&quot;] = &quot;555-1212&quot; phonebook[&quot;J. Random Hacker&quot;] = &quot;555-1337&quot; </pre></div> <p>You can also loop through an associated array in a number of ways: </p> <div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre><span></span>foreach name (phonebook) { vmessage (&quot;%s %s&quot;, name, phonebook[name]); } </pre></div> <p>To print a sorted-list, it is better to take advantage of S-lang's strong support for standard arrays: </p> <div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre><span></span>keys = assoc_get_keys(phonebook); i = array_sort(keys); vals = assoc_get_values(phonebook); array_map (Void_Type, &amp;vmessage, &quot;%s %s&quot;, keys[i], vals[i]); </pre></div> <div class="mw-heading mw-heading3"><h3 id="Scala">Scala</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=57" title="Edit section: Scala"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Scala_(programming_language)" title="Scala (programming language)">Scala</a> provides an immutable <code>Map</code> class as part of the <code>scala.collection</code> framework: </p> <div class="mw-highlight mw-highlight-lang-scala mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">val</span><span class="w"> </span><span class="n">phonebook</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Map</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;John Doe&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s">&quot;J. Random Hacker&quot;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">)</span> </pre></div> <p>Scala's <a href="/wiki/Type_inference" title="Type inference">type inference</a> will decide that this is a <code>Map[String, String]</code>. To access the array: </p> <div class="mw-highlight mw-highlight-lang-scala mw-content-ltr" dir="ltr"><pre><span></span><span class="n">phonebook</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">)</span> </pre></div> <p>This returns an <code>Option</code> type, Scala's equivalent of the <a href="/wiki/Monad_(functional_programming)#The_Maybe_monad" title="Monad (functional programming)">Maybe monad</a> in Haskell. </p> <div class="mw-heading mw-heading3"><h3 id="Smalltalk">Smalltalk</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=58" title="Edit section: Smalltalk"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/Smalltalk" title="Smalltalk">Smalltalk</a> a <code>Dictionary</code> is used: </p> <div class="mw-highlight mw-highlight-lang-smalltalk mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">phonebook</span> <span class="o">:=</span> <span class="nc">Dictionary</span> <span class="nb">new</span><span class="p">.</span> <span class="nv">phonebook</span> <span class="nf">at:</span> <span class="s">&#39;Sally Smart&#39;</span> <span class="nf">put:</span> <span class="s">&#39;555-9999&#39;</span><span class="p">.</span> <span class="nv">phonebook</span> <span class="nf">at:</span> <span class="s">&#39;John Doe&#39;</span> <span class="nf">put:</span> <span class="s">&#39;555-1212&#39;</span><span class="p">.</span> <span class="nv">phonebook</span> <span class="nf">at:</span> <span class="s">&#39;J. Random Hacker&#39;</span> <span class="nf">put:</span> <span class="s">&#39;553-1337&#39;</span><span class="p">.</span> </pre></div> <p>To access an entry the message <code>#at:</code> is sent to the dictionary object: </p> <div class="mw-highlight mw-highlight-lang-smalltalk mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">phonebook</span> <span class="nf">at:</span> <span class="s">&#39;Sally Smart&#39;</span> </pre></div> <p>Which gives: </p> <div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre><span></span> &#39;555-9999&#39; </pre></div> <p>A dictionary hashes, or compares, based on equality and marks both key and value as <a href="/wiki/Garbage_collection_(computer_science)#Strong_and_weak_references" title="Garbage collection (computer science)">strong references</a>. Variants exist in which hash/compare on identity (IdentityDictionary) or keep <a href="/wiki/Garbage_collection_(computer_science)#Strong_and_weak_references" title="Garbage collection (computer science)">weak references</a> (WeakKeyDictionary / WeakValueDictionary). Because every object implements #hash, any object can be used as key (and of course also as value). </p> <div class="mw-heading mw-heading3"><h3 id="SNOBOL">SNOBOL</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=59" title="Edit section: SNOBOL"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/SNOBOL" title="SNOBOL">SNOBOL</a> is one of the first (if not the first) programming languages to use associative arrays. Associative arrays in SNOBOL are called Tables. </p> <div class="mw-highlight mw-highlight-lang-snobol mw-content-ltr" dir="ltr"><pre><span></span><span class="nl">PHONEBOOK</span> <span class="o">=</span> <span class="n">TABLE</span><span class="p">()</span> <span class="nl">PHONEBOOK</span><span class="err">[</span><span class="s">&#39;Sally Smart&#39;</span><span class="err">]</span> <span class="o">=</span> <span class="s">&#39;555-9999&#39;</span> <span class="nl">PHONEBOOK</span><span class="err">[</span><span class="s">&#39;John Doe&#39;</span><span class="err">]</span> <span class="o">=</span> <span class="s">&#39;555-1212&#39;</span> <span class="nl">PHONEBOOK</span><span class="err">[</span><span class="s">&#39;J. Random Hacker&#39;</span><span class="err">]</span> <span class="o">=</span> <span class="s">&#39;553-1337&#39;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Standard_ML">Standard ML</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=60" title="Edit section: Standard ML"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The SML'97 standard of the <a href="/wiki/Standard_ML" title="Standard ML">Standard ML</a> programming language does not provide any associative containers. However, various implementations of Standard ML do provide associative containers. </p><p>The library of the popular <a href="/wiki/Standard_ML_of_New_Jersey" title="Standard ML of New Jersey">Standard ML of New Jersey</a> (SML/NJ) implementation provides a signature (somewhat like an "interface"), <code>ORD_MAP</code>, which defines a common interface for ordered functional (immutable) associative arrays. There are several general functors—<code>BinaryMapFn</code>, <code>ListMapFn</code>, <code>RedBlackMapFn</code>, and <code>SplayMapFn</code>—that allow you to create the corresponding type of ordered map (the types are a <a href="/wiki/Self-balancing_binary_search_tree" title="Self-balancing binary search tree">self-balancing binary search tree</a>, sorted <a href="/wiki/Association_list" title="Association list">association list</a>, <a href="/wiki/Red%E2%80%93black_tree" title="Red–black tree">red–black tree</a>, and <a href="/wiki/Splay_tree" title="Splay tree">splay tree</a>, respectively) using a user-provided structure to describe the key type and comparator. The functor returns a structure in accordance with the <code>ORD_MAP</code> interface. In addition, there are two pre-defined modules for associative arrays that employ integer keys: <code>IntBinaryMap</code> and <code>IntListMap</code>. </p> <div class="mw-highlight mw-highlight-lang-sml mw-content-ltr" dir="ltr"><pre><span></span><span class="n">-</span> <span class="kr">structure</span> <span class="nn">StringMap</span> <span class="p">=</span> <span class="n">BinaryMapFn</span> <span class="p">(</span><span class="kr">struct</span> <span class="kr">type</span> <span class="kt">ord_key</span> <span class="p">=</span> <span class="n">string</span> <span class="kr">val</span> <span class="nv">compare</span> <span class="p">=</span> <span class="nn">String</span><span class="p">.</span><span class="n">compare</span> <span class="kr">end</span><span class="p">);</span> <span class="kr">structure</span> <span class="nn">StringMap</span> <span class="p">:</span> <span class="n">ORD_MAP</span> <span class="n">-</span> <span class="kr">val</span> <span class="nv">m</span> <span class="p">=</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">insert</span> <span class="p">(</span><span class="nn">StringMap</span><span class="p">.</span><span class="n">empty</span><span class="p">,</span> <span class="s2">&quot;Sally Smart&quot;</span><span class="p">,</span> <span class="s2">&quot;555-9999&quot;</span><span class="p">)</span> <span class="kr">val</span> <span class="nv">m</span> <span class="p">=</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">insert</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="s2">&quot;John Doe&quot;</span><span class="p">,</span> <span class="s2">&quot;555-1212&quot;</span><span class="p">)</span> <span class="kr">val</span> <span class="nv">m</span> <span class="p">=</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">insert</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">,</span> <span class="s2">&quot;553-1337&quot;</span><span class="p">);</span> <span class="kr">val</span> <span class="nv">m</span> <span class="p">=</span> <span class="n">T</span> <span class="p">{</span><span class="n">cnt</span><span class="p">=</span><span class="mi">3</span><span class="p">,</span><span class="n">key</span><span class="p">=</span><span class="s2">&quot;John Doe&quot;</span><span class="p">,</span> <span class="n">left</span><span class="p">=</span><span class="n">T</span> <span class="p">{</span><span class="n">cnt</span><span class="p">=</span><span class="mi">1</span><span class="p">,</span><span class="n">key</span><span class="p">=</span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="n">left</span><span class="p">=</span><span class="n">E</span><span class="p">,</span><span class="n">right</span><span class="p">=</span><span class="n">E</span><span class="p">,</span><span class="n">value</span><span class="p">=</span><span class="s2">&quot;553-1337&quot;</span><span class="p">},</span> <span class="n">right</span><span class="p">=</span><span class="n">T</span> <span class="p">{</span><span class="n">cnt</span><span class="p">=</span><span class="mi">1</span><span class="p">,</span><span class="n">key</span><span class="p">=</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="n">left</span><span class="p">=</span><span class="n">E</span><span class="p">,</span><span class="n">right</span><span class="p">=</span><span class="n">E</span><span class="p">,</span><span class="n">value</span><span class="p">=</span><span class="s2">&quot;555-9999&quot;</span><span class="p">},</span> <span class="n">value</span><span class="p">=</span><span class="s2">&quot;555-1212&quot;</span><span class="p">}</span> <span class="p">:</span> <span class="n">string</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">map</span> <span class="n">-</span> <span class="nn">StringMap</span><span class="p">.</span><span class="n">find</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="s2">&quot;John Doe&quot;</span><span class="p">);</span> <span class="kr">val</span> <span class="nv">it</span> <span class="p">=</span> <span class="n">SOME</span> <span class="s2">&quot;555-1212&quot;</span> <span class="p">:</span> <span class="n">string</span> <span class="n">option</span> </pre></div> <p>SML/NJ also provides a polymorphic hash table: </p> <div class="mw-highlight mw-highlight-lang-sml mw-content-ltr" dir="ltr"><pre><span></span><span class="n">-</span> <span class="kr">exception</span> <span class="nc">NotFound</span><span class="p">;</span> <span class="kr">exception</span> <span class="nc">NotFound</span> <span class="nc">-</span> <span class="nc">val</span> <span class="nc">m</span> <span class="nc">:</span> <span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="n">string</span><span class="p">)</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">hash_table</span> <span class="p">=</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">mkTable</span> <span class="p">(</span><span class="nn">HashString</span><span class="p">.</span><span class="n">hashString</span><span class="p">,</span> <span class="kr">op</span><span class="p">=)</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">NotFound</span><span class="p">);</span> <span class="kr">val</span> <span class="nv">m</span> <span class="p">=</span> <span class="n">HT</span> <span class="p">{</span><span class="n">eq_pred</span><span class="p">=</span><span class="kr">fn</span><span class="p">,</span><span class="n">hash_fn</span><span class="p">=</span><span class="kr">fn</span><span class="p">,</span><span class="n">n_items</span><span class="p">=</span><span class="n">ref</span> <span class="mi">0</span><span class="p">,</span><span class="n">not_found</span><span class="p">=</span><span class="n">NotFound</span><span class="p">(</span><span class="n">-</span><span class="p">),</span> <span class="n">table</span><span class="p">=</span><span class="n">ref</span> <span class="p">[</span><span class="n">|NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,</span><span class="n">NIL</span><span class="p">,...</span><span class="n">|</span><span class="p">]}</span> <span class="p">:</span> <span class="p">(</span><span class="n">string</span><span class="p">,</span><span class="n">string</span><span class="p">)</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">hash_table</span> <span class="n">-</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">insert</span> <span class="n">m</span> <span class="p">(</span><span class="s2">&quot;Sally Smart&quot;</span><span class="p">,</span> <span class="s2">&quot;555-9999&quot;</span><span class="p">);</span> <span class="kr">val</span> <span class="nv">it</span> <span class="p">=</span> <span class="p">()</span> <span class="p">:</span> <span class="n">unit</span> <span class="n">-</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">insert</span> <span class="n">m</span> <span class="p">(</span><span class="s2">&quot;John Doe&quot;</span><span class="p">,</span> <span class="s2">&quot;555-1212&quot;</span><span class="p">);</span> <span class="kr">val</span> <span class="nv">it</span> <span class="p">=</span> <span class="p">()</span> <span class="p">:</span> <span class="n">unit</span> <span class="n">-</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">insert</span> <span class="n">m</span> <span class="p">(</span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="p">,</span> <span class="s2">&quot;553-1337&quot;</span><span class="p">);</span> <span class="kr">val</span> <span class="nv">it</span> <span class="p">=</span> <span class="p">()</span> <span class="p">:</span> <span class="n">unit</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">find</span> <span class="n">m</span> <span class="s2">&quot;John Doe&quot;</span><span class="p">;</span> <span class="cm">(* returns NONE if not found *)</span> <span class="kr">val</span> <span class="nv">it</span> <span class="p">=</span> <span class="n">SOME</span> <span class="s2">&quot;555-1212&quot;</span> <span class="p">:</span> <span class="n">string</span> <span class="n">option</span> <span class="n">-</span> <span class="nn">HashTable</span><span class="p">.</span><span class="n">lookup</span> <span class="n">m</span> <span class="s2">&quot;John Doe&quot;</span><span class="p">;</span> <span class="cm">(* raises the exception if not found *)</span> <span class="kr">val</span> <span class="nv">it</span> <span class="p">=</span> <span class="s2">&quot;555-1212&quot;</span> <span class="p">:</span> <span class="n">string</span> </pre></div> <p>Monomorphic hash tables are also supported, using the <code>HashTableFn</code> functor. </p><p>Another Standard ML implementation, <a href="/wiki/Moscow_ML" class="mw-redirect" title="Moscow ML">Moscow ML</a>, also provides some associative containers. First, it provides polymorphic hash tables in the <code>Polyhash</code> structure. Also, some functional maps from the SML/NJ library above are available as <code>Binarymap</code>, <code>Splaymap</code>, and <code>Intmap</code> structures. </p> <div class="mw-heading mw-heading3"><h3 id="Tcl">Tcl</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=61" title="Edit section: Tcl"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>There are two <a href="/wiki/Tcl" title="Tcl">Tcl</a> facilities that support associative-array semantics. An "array" is a collection of variables. A "dict" is a full implementation of associative arrays. </p> <div class="mw-heading mw-heading4"><h4 id="array">array</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=62" title="Edit section: array"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">set</span><span class="w"> </span><span class="k">{</span><span class="nv">phonebook</span><span class="k">(</span><span class="nv">Sally</span><span class="w"> </span>Smart<span class="k">)}</span><span class="w"> </span><span class="mi">555</span><span class="o">-</span><span class="mi">9999</span> <span class="k">set</span><span class="w"> </span>john<span class="w"> </span><span class="k">{</span><span class="nv">John</span><span class="w"> </span>Doe<span class="k">}</span> <span class="k">set</span><span class="w"> </span>phonebook<span class="k">(</span><span class="nv">$john</span><span class="k">)</span><span class="w"> </span><span class="mi">555</span><span class="o">-</span><span class="mi">1212</span> <span class="k">set</span><span class="w"> </span><span class="k">{</span><span class="nv">phonebook</span><span class="k">(</span><span class="nv">J.</span><span class="w"> </span>Random<span class="w"> </span>Hacker<span class="k">)}</span><span class="w"> </span><span class="mi">553</span><span class="o">-</span><span class="mi">1337</span> </pre></div> <p>If there is a space character in the variable name, the name must be grouped using either curly brackets (no substitution performed) or double quotes (substitution is performed). </p><p>Alternatively, several array elements can be set by a single command, by presenting their mappings as a list (words containing whitespace are braced): </p> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">array</span><span class="w"> </span>set<span class="w"> </span>phonebook<span class="w"> </span><span class="k">[</span><span class="nb">list</span><span class="w"> </span><span class="k">{</span><span class="nv">Sally</span><span class="w"> </span>Smart<span class="k">}</span><span class="w"> </span><span class="mi">555</span><span class="o">-</span><span class="mi">9999</span><span class="w"> </span><span class="k">{</span><span class="nv">John</span><span class="w"> </span>Doe<span class="k">}</span><span class="w"> </span><span class="mi">555</span><span class="o">-</span><span class="mi">1212</span><span class="w"> </span><span class="k">{</span><span class="nv">J.</span><span class="w"> </span>Random<span class="w"> </span>Hacker<span class="k">}</span><span class="w"> </span><span class="mi">553</span><span class="o">-</span><span class="mi">1337</span><span class="k">]</span> </pre></div> <p>To access one array entry and put it to standard output: </p> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">puts</span><span class="w"> </span><span class="nv">$phonebook</span><span class="k">(</span><span class="nv">Sally</span><span class="err">\</span><span class="w"> </span>Smart<span class="k">)</span> </pre></div> <p>Which returns this result: </p> <div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre><span></span>555-9999 </pre></div> <p>To retrieve the entire array as a dictionary: </p> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">array</span><span class="w"> </span>get<span class="w"> </span>phonebook </pre></div> <p>The result can be (order of keys is unspecified, not because the dictionary is unordered, but because the array is): </p> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">{</span><span class="nv">Sally</span><span class="w"> </span>Smart<span class="k">}</span><span class="w"> </span><span class="nv">555-9999</span><span class="w"> </span><span class="k">{</span><span class="nv">J.</span><span class="w"> </span>Random<span class="w"> </span>Hacker<span class="k">}</span><span class="w"> </span><span class="mi">553</span><span class="o">-</span><span class="mi">1337</span><span class="w"> </span><span class="k">{</span><span class="nv">John</span><span class="w"> </span>Doe<span class="k">}</span><span class="w"> </span><span class="mi">555</span><span class="o">-</span><span class="mi">1212</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="dict">dict</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=63" title="Edit section: dict"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">set</span><span class="w"> </span>phonebook<span class="w"> </span><span class="k">[</span><span class="nb">dict</span><span class="w"> </span>create<span class="w"> </span><span class="k">{</span><span class="nv">Sally</span><span class="w"> </span>Smart<span class="k">}</span><span class="w"> </span><span class="mi">555</span><span class="o">-</span><span class="mi">9999</span><span class="w"> </span><span class="k">{</span><span class="nv">John</span><span class="w"> </span>Doe<span class="k">}</span><span class="w"> </span><span class="mi">555</span><span class="o">-</span><span class="mi">1212</span><span class="w"> </span><span class="k">{</span><span class="nv">J.</span><span class="w"> </span>Random<span class="w"> </span>Hacker<span class="k">}</span><span class="w"> </span><span class="mi">553</span><span class="o">-</span><span class="mi">1337</span><span class="k">]</span> </pre></div> <p>To look up an item: </p> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">dict</span><span class="w"> </span>get<span class="w"> </span><span class="nv">$phonebook</span><span class="w"> </span><span class="k">{</span><span class="nv">John</span><span class="w"> </span>Doe<span class="k">}</span> </pre></div> <p>To iterate through a dict: </p> <div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">foreach</span><span class="w"> </span><span class="k">{</span><span class="nv">name</span><span class="w"> </span>number<span class="k">}</span><span class="w"> </span><span class="nv">$phonebook</span><span class="w"> </span><span class="k">{</span> <span class="w"> </span><span class="nb">puts</span><span class="w"> </span><span class="s2">&quot;name: $name\nnumber: $number&quot;</span> <span class="k">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Visual_Basic">Visual Basic</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=64" title="Edit section: Visual Basic"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Visual_Basic" title="Visual Basic">Visual Basic</a> can use the Dictionary class from the <a href="/wiki/Windows_Scripting_Host" class="mw-redirect" title="Windows Scripting Host">Microsoft Scripting Runtime</a> (which is shipped with Visual Basic 6). There is no standard implementation common to all versions: </p> <div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span></span><span class="c">&#39; Requires a reference to SCRRUN.DLL in Project Properties</span> <span class="k">Dim</span><span class="w"> </span><span class="n">phoneBook</span><span class="w"> </span><span class="ow">As</span><span class="w"> </span><span class="k">New</span><span class="w"> </span><span class="n">Dictionary</span> <span class="n">phoneBook</span><span class="p">.</span><span class="n">Add</span><span class="w"> </span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span> <span class="n">phoneBook</span><span class="p">.</span><span class="n">Item</span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span> <span class="n">phoneBook</span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span> <span class="k">For</span><span class="w"> </span><span class="k">Each</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="ow">In</span><span class="w"> </span><span class="n">phoneBook</span> <span class="w"> </span><span class="n">MsgBox</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="s">&quot; = &quot;</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="n">phoneBook</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="k">Next</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Visual_Basic_.NET">Visual Basic .NET</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=65" title="Edit section: Visual Basic .NET"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Visual_Basic_.NET" class="mw-redirect" title="Visual Basic .NET">Visual Basic .NET</a> uses the collection classes provided by the <a href="/wiki/.NET_Framework" title=".NET Framework">.NET Framework</a>. </p> <div class="mw-heading mw-heading4"><h4 id="Creation_5">Creation</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=66" title="Edit section: Creation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The following code demonstrates the creation and population of a dictionary (see <a href="#C#">the C# example on this page</a> for additional information): </p> <div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span></span><span class="k">Dim</span><span class="w"> </span><span class="n">dic</span><span class="w"> </span><span class="ow">As</span><span class="w"> </span><span class="k">New</span><span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="n">Collections</span><span class="p">.</span><span class="n">Generic</span><span class="p">.</span><span class="n">Dictionary</span><span class="p">(</span><span class="k">Of</span><span class="w"> </span><span class="kt">String</span><span class="p">,</span><span class="w"> </span><span class="kt">String</span><span class="p">)</span> <span class="n">dic</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">)</span> <span class="n">dic</span><span class="p">(</span><span class="s">&quot;John Doe&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span> <span class="n">dic</span><span class="p">.</span><span class="n">Item</span><span class="p">(</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span> </pre></div> <p>An alternate syntax would be to use a <i>collection initializer</i>, which compiles down to individual calls to <code>Add</code>: </p> <div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span></span><span class="k">Dim</span><span class="w"> </span><span class="n">dic</span><span class="w"> </span><span class="ow">As</span><span class="w"> </span><span class="k">New</span><span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="n">Collections</span><span class="p">.</span><span class="n">Dictionary</span><span class="p">(</span><span class="k">Of</span><span class="w"> </span><span class="kt">String</span><span class="p">,</span><span class="w"> </span><span class="kt">String</span><span class="p">)</span><span class="w"> </span><span class="n">From</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-9999&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;John Doe&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;555-1212&quot;</span><span class="p">},</span> <span class="w"> </span><span class="p">{</span><span class="s">&quot;J. Random Hacker&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;553-1337&quot;</span><span class="p">}</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Access_by_key_5">Access by key</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=67" title="Edit section: Access by key"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Example demonstrating access (see <a href="#C#_access">C# access</a>): </p> <div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span></span><span class="k">Dim</span><span class="w"> </span><span class="n">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dic</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">)</span> <span class="c">&#39; or</span> <span class="k">Dim</span><span class="w"> </span><span class="n">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dic</span><span class="p">.</span><span class="n">Item</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">)</span> </pre></div> <div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span></span><span class="k">Dim</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="ow">As</span><span class="w"> </span><span class="kt">String</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">Nothing</span> <span class="k">Dim</span><span class="w"> </span><span class="n">sallyNumber</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">If</span><span class="p">(</span><span class="n">dic</span><span class="p">.</span><span class="n">TryGetValue</span><span class="p">(</span><span class="s">&quot;Sally Smart&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">result</span><span class="p">),</span><span class="w"> </span><span class="n">result</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;n/a&quot;</span><span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Enumeration_4">Enumeration</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=68" title="Edit section: Enumeration"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Example demonstrating enumeration (see <a href="#C#_enumeration">#C# enumeration</a>): </p> <div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span></span><span class="c">&#39; loop through the collection and display each entry.</span> <span class="k">For</span><span class="w"> </span><span class="k">Each</span><span class="w"> </span><span class="n">kvp</span><span class="w"> </span><span class="ow">As</span><span class="w"> </span><span class="n">KeyValuePair</span><span class="p">(</span><span class="k">Of</span><span class="w"> </span><span class="kt">String</span><span class="p">,</span><span class="w"> </span><span class="kt">String</span><span class="p">)</span><span class="w"> </span><span class="ow">In</span><span class="w"> </span><span class="n">dic</span> <span class="w"> </span><span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">&quot;Phone number for {0} is {1}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">kvp</span><span class="p">.</span><span class="n">Key</span><span class="p">,</span><span class="w"> </span><span class="n">kvp</span><span class="p">.</span><span class="n">Value</span><span class="p">)</span> <span class="k">Next</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Windows_PowerShell">Windows PowerShell</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=69" title="Edit section: Windows PowerShell"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Unlike many other <a href="/wiki/Command_line_interpreter" class="mw-redirect" title="Command line interpreter">command line interpreters</a>, <a href="/wiki/Windows_PowerShell" class="mw-redirect" title="Windows PowerShell">Windows PowerShell</a> has built-in, language-level support for defining associative arrays: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$phonebook</span> <span class="p">=</span> <span class="p">@{</span> <span class="s1">&#39;Sally Smart&#39;</span> <span class="p">=</span> <span class="s1">&#39;555-9999&#39;</span><span class="p">;</span> <span class="s1">&#39;John Doe&#39;</span> <span class="p">=</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">;</span> <span class="s1">&#39;J. Random Hacker&#39;</span> <span class="p">=</span> <span class="s1">&#39;553-1337&#39;</span> <span class="p">}</span> </pre></div> <p>As in JavaScript, if the property name is a valid identifier, the quotes can be omitted: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$myOtherObject</span> <span class="p">=</span> <span class="p">@{</span> <span class="n">foo</span> <span class="p">=</span> <span class="n">42</span><span class="p">;</span> <span class="n">bar</span> <span class="p">=</span> <span class="nv">$false</span> <span class="p">}</span> </pre></div> <p>Entries can be separated by either a semicolon or a newline: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$myOtherObject</span> <span class="p">=</span> <span class="p">@{</span> <span class="n">foo</span> <span class="p">=</span> <span class="n">42</span> <span class="n">bar</span> <span class="p">=</span> <span class="nv">$false</span> <span class="p">;</span> <span class="n">zaz</span> <span class="p">=</span> <span class="n">3</span> <span class="p">}</span> </pre></div> <p>Keys and values can be any <a href="/wiki/.NET_Framework" title=".NET Framework">.NET</a> object type: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$now</span> <span class="p">=</span> <span class="no">[DateTime]</span><span class="p">::</span><span class="n">Now</span> <span class="nv">$tomorrow</span> <span class="p">=</span> <span class="nv">$now</span><span class="p">.</span><span class="n">AddDays</span><span class="p">(</span><span class="n">1</span><span class="p">)</span> <span class="nv">$ProcessDeletionSchedule</span> <span class="p">=</span> <span class="p">@{</span> <span class="p">(</span><span class="nb">Get-Process</span> <span class="n">notepad</span><span class="p">)</span> <span class="p">=</span> <span class="nv">$now</span> <span class="p">(</span><span class="nb">Get-Process</span> <span class="n">calc</span><span class="p">)</span> <span class="p">=</span> <span class="nv">$tomorrow</span> <span class="p">}</span> </pre></div> <p>It is also possible to create an empty associative array and add single entries, or even other associative arrays, to it later on: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$phonebook</span> <span class="p">=</span> <span class="p">@{}</span> <span class="nv">$phonebook</span> <span class="p">+=</span> <span class="p">@{</span> <span class="s1">&#39;Sally Smart&#39;</span> <span class="p">=</span> <span class="s1">&#39;555-9999&#39;</span> <span class="p">}</span> <span class="nv">$phonebook</span> <span class="p">+=</span> <span class="p">@{</span> <span class="s1">&#39;John Doe&#39;</span> <span class="p">=</span> <span class="s1">&#39;555-1212&#39;</span><span class="p">;</span> <span class="s1">&#39;J. Random Hacker&#39;</span> <span class="p">=</span> <span class="s1">&#39;553-1337&#39;</span> <span class="p">}</span> </pre></div> <p>New entries can also be added by using the array index operator, the property operator, or the <code>Add()</code> method of the underlying .NET object: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$phonebook</span> <span class="p">=</span> <span class="p">@{}</span> <span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;Sally Smart&#39;</span><span class="p">]</span> <span class="p">=</span> <span class="s1">&#39;555-9999&#39;</span> <span class="nv">$phonebook</span><span class="p">.</span><span class="s1">&#39;John Doe&#39;</span> <span class="p">=</span> <span class="s1">&#39;555-1212&#39;</span> <span class="nv">$phonebook</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">,</span> <span class="s1">&#39;553-1337&#39;</span><span class="p">)</span> </pre></div> <p>To dereference assigned objects, the array index operator, the property operator, or the parameterized property <code>Item()</code> of the .NET object can be used: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$phonebook</span><span class="p">[</span><span class="s1">&#39;Sally Smart&#39;</span><span class="p">]</span> <span class="nv">$phonebook</span><span class="p">.</span><span class="s1">&#39;John Doe&#39;</span> <span class="nv">$phonebook</span><span class="p">.</span><span class="n">Item</span><span class="p">(</span><span class="s1">&#39;J. Random Hacker&#39;</span><span class="p">)</span> </pre></div> <p>You can loop through an associative array as follows: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$phonebook</span><span class="p">.</span><span class="n">Keys</span> <span class="p">|</span> <span class="k">foreach</span> <span class="p">{</span> <span class="s2">&quot;Number for {0}: {1}&quot;</span> <span class="o">-f</span> <span class="nv">$_</span><span class="p">,</span><span class="nv">$phonebook</span><span class="p">.</span><span class="nv">$_</span> <span class="p">}</span> </pre></div> <p>An entry can be removed using the <code>Remove()</code> method of the underlying .NET object: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$phonebook</span><span class="p">.</span><span class="n">Remove</span><span class="p">(</span><span class="s1">&#39;Sally Smart&#39;</span><span class="p">)</span> </pre></div> <p>Hash tables can be added: </p> <div class="mw-highlight mw-highlight-lang-powershell mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$hash1</span> <span class="p">=</span> <span class="p">@{</span> <span class="n">a</span><span class="p">=</span><span class="n">1</span><span class="p">;</span> <span class="n">b</span><span class="p">=</span><span class="n">2</span> <span class="p">}</span> <span class="nv">$hash2</span> <span class="p">=</span> <span class="p">@{</span> <span class="n">c</span><span class="p">=</span><span class="n">3</span><span class="p">;</span> <span class="n">d</span><span class="p">=</span><span class="n">4</span> <span class="p">}</span> <span class="nv">$hash3</span> <span class="p">=</span> <span class="nv">$hash1</span> <span class="p">+</span> <span class="nv">$hash2</span> </pre></div> <div class="mw-heading mw-heading2"><h2 id="Data_serialization_formats_support">Data serialization formats support</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=70" title="Edit section: Data serialization formats support"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1251242444"><table class="box-Expand_section plainlinks metadata ambox mbox-small-left ambox-content" role="presentation"><tbody><tr><td class="mbox-image"><span typeof="mw:File"><a href="/wiki/File:Wiki_letter_w_cropped.svg" class="mw-file-description"><img alt="[icon]" src="//upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Wiki_letter_w_cropped.svg/20px-Wiki_letter_w_cropped.svg.png" decoding="async" width="20" height="14" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Wiki_letter_w_cropped.svg/30px-Wiki_letter_w_cropped.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Wiki_letter_w_cropped.svg/40px-Wiki_letter_w_cropped.svg.png 2x" data-file-width="44" data-file-height="31" /></a></span></td><td class="mbox-text"><div class="mbox-text-span">This section <b>needs expansion</b>. You can help by <a class="external text" href="https://en.wikipedia.org/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=">adding to it</a>. <span class="date-container"><i>(<span class="date">September 2010</span>)</i></span></div></td></tr></tbody></table> <p>Many data serialization formats also support associative arrays (see <a href="/wiki/Comparison_of_data_serialization_formats#Syntax_comparison_of_human-readable_formats" class="mw-redirect" title="Comparison of data serialization formats">this table</a>) </p> <div class="mw-heading mw-heading3"><h3 id="JSON">JSON</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=71" title="Edit section: JSON"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/JSON" title="JSON">JSON</a>, associative arrays are also referred to as objects. Keys can only be strings. </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="p">{</span> <span class="w"> </span><span class="s2">&quot;Sally Smart&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;555-9999&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s2">&quot;John Doe&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;555-1212&quot;</span><span class="p">,</span> <span class="w"> </span><span class="s2">&quot;J. Random Hacker&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;555-1337&quot;</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="YAML">YAML</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=72" title="Edit section: YAML"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/YAML" title="YAML">YAML</a> associative arrays are also called map elements or key-value pairs. YAML places no restrictions on the types of keys; in particular, they are not restricted to being scalar or string values. </p> <div class="mw-highlight mw-highlight-lang-yaml mw-content-ltr" dir="ltr"><pre><span></span><span class="nt">Sally Smart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">555-9999</span> <span class="nt">John Doe</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">555-1212</span> <span class="nt">J. Random Hacker</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">555-1337</span> </pre></div> <div class="mw-heading mw-heading2"><h2 id="References">References</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;action=edit&amp;section=73" title="Edit section: References"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1239543626">.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}</style><div class="reflist reflist-columns references-column-width reflist-columns-2"> <ol class="references"> <li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20071015024120/http://www.cl.cam.ac.uk/~cwc22/hashtable/">here</a>, archived <a rel="nofollow" class="external text" href="https://web.archive.org/web/20040902160534/http://www.cl.cam.ac.uk/~cwc22/hashtable/">here</a>, with the source code available <a rel="nofollow" class="external text" href="https://github.com/davidar/c-hashtable/">here</a>. <a href="/wiki/POSIX" title="POSIX">POSIX</a> 1003.1-2001 describes the functions <code>hcreate()</code>, <code>hdestroy()</code> and <code>hsearch()</code></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://uthash.sourceforge.net/">"uthash: a hash table for C structures"</a>. <i>Github</i><span class="reference-accessdate">. Retrieved <span class="nowrap">3 August</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Github&amp;rft.atitle=uthash%3A+a+hash+table+for+C+structures&amp;rft_id=http%3A%2F%2Futhash.sourceforge.net%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://developer.gnome.org/glib/stable/glib-Hash-Tables.html">"Hash Tables"</a>. <i>Gnome Developer</i><span class="reference-accessdate">. Retrieved <span class="nowrap">3 August</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Gnome+Developer&amp;rft.atitle=Hash+Tables&amp;rft_id=https%3A%2F%2Fdeveloper.gnome.org%2Fglib%2Fstable%2Fglib-Hash-Tables.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://dlang.org/spec/hash-map.html">"Associative Arrays - D Programming Language"</a>. <i>dlang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-05-07</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=dlang.org&amp;rft.atitle=Associative+Arrays+-+D+Programming+Language&amp;rft_id=https%3A%2F%2Fdlang.org%2Fspec%2Fhash-map.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://erlang.org/doc/man/maps.html">"Erlang -- maps"</a>. <i>erlang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-03-07</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=erlang.org&amp;rft.atitle=Erlang+--+maps&amp;rft_id=https%3A%2F%2Ferlang.org%2Fdoc%2Fman%2Fmaps.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node153.html">"Common Lisp the Language, 2nd Edition: 15.6. Association Lists"</a>. <i>Carnegie Mellon University</i><span class="reference-accessdate">. Retrieved <span class="nowrap">3 August</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Carnegie+Mellon+University&amp;rft.atitle=Common+Lisp+the+Language%2C+2nd+Edition%3A+15.6.+Association+Lists&amp;rft_id=https%3A%2F%2Fwww.cs.cmu.edu%2FGroups%2FAI%2Fhtml%2Fcltl%2Fclm%2Fnode153.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://reference.wolfram.com/language/ref/Association.html">"Association (&lt;-...-&gt;)—Wolfram Language Documentation"</a>. <i>reference.wolfram.com</i>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=reference.wolfram.com&amp;rft.atitle=Association+%28%3C-...-%3E%29%E2%80%94Wolfram+Language+Documentation&amp;rft_id=https%3A%2F%2Freference.wolfram.com%2Flanguage%2Fref%2FAssociation.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://reference.wolfram.com/language/ref/Key.html">"Key—Wolfram Language Documentation"</a>. <i>reference.wolfram.com</i>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=reference.wolfram.com&amp;rft.atitle=Key%E2%80%94Wolfram+Language+Documentation&amp;rft_id=https%3A%2F%2Freference.wolfram.com%2Flanguage%2Fref%2FKey.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://reference.wolfram.com/language/ref/Keys.html">"Keys—Wolfram Language Documentation"</a>. <i>reference.wolfram.com</i>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=reference.wolfram.com&amp;rft.atitle=Keys%E2%80%94Wolfram+Language+Documentation&amp;rft_id=https%3A%2F%2Freference.wolfram.com%2Flanguage%2Fref%2FKeys.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://reference.wolfram.com/language/ref/Values.html">"Values—Wolfram Language Documentation"</a>. <i>reference.wolfram.com</i>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=reference.wolfram.com&amp;rft.atitle=Values%E2%80%94Wolfram+Language+Documentation&amp;rft_id=https%3A%2F%2Freference.wolfram.com%2Flanguage%2Fref%2FValues.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20160313082808/https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSFastEnumeration_protocol/">"NSFastEnumeration Protocol Reference"</a>. <i>Mac Developer Library</i>. 2011. Archived from <a rel="nofollow" class="external text" href="https://developer.apple.com/documentation/Cocoa/Reference/NSFastEnumeration_protocol/">the original</a> on 13 March 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">3 August</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Mac+Developer+Library&amp;rft.atitle=NSFastEnumeration+Protocol+Reference&amp;rft.date=2011&amp;rft_id=https%3A%2F%2Fdeveloper.apple.com%2Fdocumentation%2FCocoa%2FReference%2FNSFastEnumeration_protocol%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20081211233540/http://ocaml-extlib.googlecode.com/svn/doc/apiref/PMap.html">"Module PMap"</a>. <i>Ocaml-extlib</i>. 2008. Archived from <a rel="nofollow" class="external text" href="http://ocaml-extlib.googlecode.com/svn/doc/apiref/PMap.html">the original</a> on 11 December 2008<span class="reference-accessdate">. Retrieved <span class="nowrap">3 August</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Ocaml-extlib&amp;rft.atitle=Module+PMap&amp;rft.date=2008&amp;rft_id=http%3A%2F%2Focaml-extlib.googlecode.com%2Fsvn%2Fdoc%2Fapiref%2FPMap.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text">About the implementation of <a rel="nofollow" class="external text" href="http://se.php.net/manual/en/language.types.array.php">Arrays</a> in PHP</span> </li> <li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.php.net/manual/en/language.types.array.php">"Arrays"</a>. <i>PHP.net</i><span class="reference-accessdate">. Retrieved <span class="nowrap">3 August</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=PHP.net&amp;rft.atitle=Arrays&amp;rft_id=https%3A%2F%2Fwww.php.net%2Fmanual%2Fen%2Flanguage.types.array.php&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-15">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://php.net/SplObjectStorage">"The SplObjectStorage class"</a>. <i>PHP.net</i><span class="reference-accessdate">. Retrieved <span class="nowrap">3 August</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=PHP.net&amp;rft.atitle=The+SplObjectStorage+class&amp;rft_id=http%3A%2F%2Fphp.net%2FSplObjectStorage&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> <li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.swi-prolog.org/pldoc/man?section=dicts">"Dicts: structures with named arguments"</a></span> </li> <li id="cite_note-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-17">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://doc.red-lang.org/en/datatypes/map.html">"Map! datatype"</a>. <i>doc.red-lang.org</i>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=doc.red-lang.org&amp;rft.atitle=Map%21+datatype&amp;rft_id=https%3A%2F%2Fdoc.red-lang.org%2Fen%2Fdatatypes%2Fmap.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+programming+languages+%28associative+array%29" class="Z3988"></span></span> </li> </ol></div> <!-- NewPP limit report Parsed by mw‐web.codfw.main‐6b7f745dd4‐5d84k Cached time: 20241125132945 Cache expiry: 2592000 Reduced expiry: false Complications: [vary‐revision‐sha1, show‐toc] CPU time usage: 1.057 seconds Real time usage: 17.138 seconds Preprocessor visited node count: 2615/1000000 Post‐expand include size: 52864/2097152 bytes Template argument size: 1526/2097152 bytes Highest expansion depth: 12/100 Expensive parser function count: 193/500 Unstrip recursion depth: 1/20 Unstrip post‐expand size: 272320/5000000 bytes Lua time usage: 0.273/10.000 seconds Lua memory usage: 4975926/52428800 bytes Number of Wikibase entities loaded: 0/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 16861.781 1 -total 1.99% 335.502 3 Template:Sxhl 1.11% 187.222 1 Template:Reflist 0.91% 152.862 14 Template:Cite_web 0.79% 133.685 1 Template:ProgLangCompare 0.74% 125.000 1 Template:Sidebar 0.34% 57.028 1 Template:More_citations_needed_section 0.32% 54.270 2 Template:Ambox 0.31% 51.779 1 Template:More_citations_needed 0.29% 49.152 10 Template:Javadoc:SE --> <!-- Saved in parser cache with key enwiki:pcache:idhash:13941848-0!canonical and timestamp 20241125132945 and revision id 1241597169. Rendering was triggered because: page-view --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://en.wikipedia.org/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;oldid=1241597169">https://en.wikipedia.org/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;oldid=1241597169</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Help:Category" title="Help:Category">Categories</a>: <ul><li><a href="/wiki/Category:Associative_arrays" title="Category:Associative arrays">Associative arrays</a></li><li><a href="/wiki/Category:Programming_language_comparisons" title="Category:Programming language comparisons">Programming language comparisons</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Hidden categories: <ul><li><a href="/wiki/Category:Dynamic_lists" title="Category:Dynamic lists">Dynamic lists</a></li><li><a href="/wiki/Category:Articles_needing_additional_references_from_February_2011" title="Category:Articles needing additional references from February 2011">Articles needing additional references from February 2011</a></li><li><a href="/wiki/Category:All_articles_needing_additional_references" title="Category:All articles needing additional references">All articles needing additional references</a></li><li><a href="/wiki/Category:Articles_to_be_expanded_from_September_2010" title="Category:Articles to be expanded from September 2010">Articles to be expanded from September 2010</a></li><li><a href="/wiki/Category:All_articles_to_be_expanded" title="Category:All articles to be expanded">All articles to be expanded</a></li><li><a href="/wiki/Category:Articles_with_example_Julia_code" title="Category:Articles with example Julia code">Articles with example Julia code</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 22 August 2024, at 02:54<span class="anonymous-show">&#160;(UTC)</span>.</li> <li id="footer-info-copyright">Text is available under the <a href="/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License" title="Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use" class="extiw" title="foundation:Special:MyLanguage/Policy:Terms of Use">Terms of Use</a> and <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy" class="extiw" title="foundation:Special:MyLanguage/Policy:Privacy policy">Privacy Policy</a>. Wikipedia® is a registered trademark of the <a rel="nofollow" class="external text" href="https://wikimediafoundation.org/">Wikimedia Foundation, Inc.</a>, a non-profit organization.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Wikipedia:About">About Wikipedia</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Wikipedia:General_disclaimer">Disclaimers</a></li> <li id="footer-places-contact"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us">Contact Wikipedia</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=Comparison_of_programming_languages_(associative_array)&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-669b4ddb54-2w5qb","wgBackendResponseTime":158,"wgPageParseReport":{"limitreport":{"cputime":"1.057","walltime":"17.138","ppvisitednodes":{"value":2615,"limit":1000000},"postexpandincludesize":{"value":52864,"limit":2097152},"templateargumentsize":{"value":1526,"limit":2097152},"expansiondepth":{"value":12,"limit":100},"expensivefunctioncount":{"value":193,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":272320,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 16861.781 1 -total"," 1.99% 335.502 3 Template:Sxhl"," 1.11% 187.222 1 Template:Reflist"," 0.91% 152.862 14 Template:Cite_web"," 0.79% 133.685 1 Template:ProgLangCompare"," 0.74% 125.000 1 Template:Sidebar"," 0.34% 57.028 1 Template:More_citations_needed_section"," 0.32% 54.270 2 Template:Ambox"," 0.31% 51.779 1 Template:More_citations_needed"," 0.29% 49.152 10 Template:Javadoc:SE"]},"scribunto":{"limitreport-timeusage":{"value":"0.273","limit":"10.000"},"limitreport-memusage":{"value":4975926,"limit":52428800}},"cachereport":{"origin":"mw-web.codfw.main-6b7f745dd4-5d84k","timestamp":"20241125132945","ttl":2592000,"transientcontent":false}}});});</script> <script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"Comparison of programming languages (associative array)","url":"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_programming_languages_(associative_array)","sameAs":"http:\/\/www.wikidata.org\/entity\/Q5155960","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q5155960","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2007-10-27T17:07:53Z","dateModified":"2024-08-22T02:54:39Z","headline":"wikimedia list article"}</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10