Function: map-delete

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

Signature

(map-delete MAP KEY)

Documentation

Delete KEY in-place from MAP and return MAP.

Keys not present in MAP are ignored.

Note that if MAP is a list (either alist or plist), and you're deleting the final element in the list, the list isn't actually destructively modified (but the return value will reflect the deletion). So if you're using this method on a list, you have to say

  (setq map (map-delete map key))

for this to work reliably.

Other relevant functions are documented in the map group.

Probably introduced at or before Emacs version 28.1.

Shortdoc

;; map
(map-delete (list 'bar 1 'foo 2 'baz 3) 'foo)
    => (bar 1 baz 3)
  (map-delete (list '(bar . 1) '(foo . 2) '(baz . 3)) 'foo)
    => ((bar . 1) (baz . 3))
  (map-delete [bar foo baz] 1)
    => [bar nil baz]
  (map-delete #s(hash-table data (bar 1 foo 2 baz 3)) 'foo)
    => #s(hash-table data (bar 1 baz 3))

Implementations

(map-delete (MAP array) KEY) in `map.el'.

Implementation of `map-delete' for maps that are arrays. In a map that is an array, the keys are the slot indices, and slot contents are the values. Since array slots cannot be removed, this stores nil at index KEY.

(map-delete (MAP hash-table) KEY) in `map.el'.

Implementation of `map-delete' 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. Calls `remhash' to remove KEY.

(map-delete (MAP list) KEY) in `map.el'.

Implementation of `map-delete' 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; this function removes the pair whose property-name matches KEY. In a map that is an alist, the `car' of each cons cell is the key and the `cdr' is the value; this function removes the cons cell whose `car' equals KEY.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/map.el.gz
(cl-defgeneric map-delete (map key)
  "Delete KEY in-place from MAP and return MAP.
Keys not present in MAP are ignored.

Note that if MAP is a list (either alist or plist), and you're
deleting the final element in the list, the list isn't actually
destructively modified (but the return value will reflect the
deletion).  So if you're using this method on a list, you have to
say

  (setq map (map-delete map key))

for this to work reliably.")