Function: map-put!

map-put! is a byte-compiled function defined in map.el.gz.

Signature

(map-put! MAP KEY VALUE)

Documentation

Associate KEY with VALUE in MAP.

If KEY is already present in MAP, replace the associated value with VALUE. This operates by modifying MAP in place. If it cannot do that, it signals the map-not-inplace error. To insert an element without modifying MAP, use map-insert.

Other relevant functions are documented in the map group.

Probably introduced at or before Emacs version 27.1.

Shortdoc

;; map
(let ((map (list 'bar 1 'baz 3)))
    (map-put! map 'foo 2)
    map)
    => (bar 1 baz 3 foo 2)
  (let ((map [bar bot baz]))
    (map-put! map 1 'foo)
    map)
    => [bar foo baz]
  (let ((map #s(hash-table data (bar 1 baz 3))))
    (map-put! map 'foo 2)
    map)
    => #s(hash-table data (bar 1 baz 3 foo 2))

Aliases

map--put (obsolete since 27.1)

Implementations

(map-put! (MAP array) KEY VALUE &optional TESTFN) in `map.el'.

Implementation of `map-put!' for maps that are arrays. In a map that is an array, the keys are the slot indices, and slot contents are the values. Calls `aset'.

(map-put! (MAP hash-table) KEY VALUE &optional TESTFN) in `map.el'.

Implementation of `map-put!' for maps that are hash-tables. In a map that is a hash-table, the keys in the table serve as the map keys and the associated values are the key values.

(map-put! (MAP list) KEY VALUE &optional TESTFN) in `map.el'.

Implementation of `map-put!' for maps that are plists or alists. In a map that is a plist, property names are the keys, and the corresponding property values are the values of those keys. In a map that is an alist, the `car' of each cons cell is the key and the `cdr' is the value.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/map.el.gz
(cl-defgeneric map-put! (map key value &optional testfn)
  "Associate KEY with VALUE in MAP.
If KEY is already present in MAP, replace the associated value
with VALUE.
This operates by modifying MAP in place.  If it cannot do that,
it signals the `map-not-inplace' error.
To insert an element without modifying MAP, use `map-insert'."
  ;; `testfn' only exists for backward compatibility with `map-put'!
  (declare (advertised-calling-convention (map key value) "27.1")))