function
(put ds key value)
Associate a key with a value in any mutable associative data
structure. Indexed data structures (arrays and buffers) only accept
non-negative integer keys, and will expand if an out of bounds
value is provided. In an array, extra space will be filled with
nils, and in a buffer, extra space will be filled with 0 bytes. In
a table, putting a key that is contained in the table prototype
will hide the association defined by the prototype, but will not
mutate the prototype table. Putting a value nil into a table will
remove the key from the table. Returns the data structure ds.
(put @{:a 4 :b 5} :c 6 ) # => @{:a 4 :b 5 :c 6}
(put @{:a 4 :b 5} :b nil ) # => @{:a 4}
(put @{:a 4 :b 5} :z nil ) # => @{:a 4 :b 5}
(put @[:a :b :c] 0 :z ) # => @[:z :b :c]
(put @[:a :b :c] 1 nil ) # => @[:a nil :c]
(put @[:a :b :c] 5 :d ) # => @[:a :b :c nil nil :d]
(put @"hello" 0 "z" ) # error: can only put integers in buffers
(defn ord [ch] (first (string/bytes ch)))
(ord "z") # => 122
(put @"hello" 0 122 ) # => @"zello"
(put @"hello" 0 (ord "z") ) # => @"zello"
(put @"hello" 8 (ord "y") ) # => @"hello\0\0\0y"
(put (table) :a 1) # => @{:a 1}