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 a map-not-inplace error. To insert an element without modifying MAP, use map-insert.

Aliases

map--put (obsolete since 27.1)

Implementations

(map key value &optional testfn) in `map.el'.

Undocumented

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 a `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"))
  ;; Can't use `cl-defmethod' with `advertised-calling-convention'.
  (map--dispatch
   map
   :list
   (progn
     (if (map--plist-p map)
         (plist-put map key value)
       (let ((oldmap map))
         (setf (alist-get key map key nil (or testfn #'equal)) value)
         (unless (eq oldmap map)
           (signal 'map-not-inplace (list oldmap)))))
     ;; Always return the value.
     value)
   :hash-table (puthash key value map)
   ;; FIXME: If `key' is too large, should we signal `map-not-inplace'
   ;; and let `map-insert' grow the array?
   :array (aset map key value)))