Task

The goal is to create an associative array (also known as a dictionary, map, or hash).



Related tasks:

 Associative arrays/Iteration
 Hash from two arrays


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


 
;;; empty associative array
#empty
; or short form
#e
 
;;; creating the new empty associative array
(define empty-map #empty)
 
;;; creating associative array with values
(define my-map (pairs->ff '(
   (1 . 100)
   (2 . 200)
   (7 . 777))))
;;; or in short form (available from Ol version 2.1)
(define my-map {
   1 100
   2 200
   7 777})
 
;;; add new key-value pair to the existing associative array
(define my-new-map (put my-map 'the-key 'the-value))
 
;;; print our arrays
(print empty-map)
; ==> #()
 
(print my-map)
; ==> #((1 . 100) (2 . 200) (7 . 777))
 
(print my-new-map)
; ==> #((1 . 100) (2 . 200) (7 . 777) (the-key . the-value))
 