This is my first foray into emacs macros, so likely silly mistakes ahead: I'm trying to mimic the definition of pop
(see the manual here), but I want to remove an element of alist
indexed by key
, returning the value corresponding to key
from alist
while altering alist
in place. Here's my attempt:
(defun alist-remove (alist key)
(seq-filter
(lambda (pair) (not (eq key (car pair))))
alist))
(defmacro alist-pop (alist key)
`(prog1
(cdr (assq ,key ,alist))
(setq alist (alist-remove ,alist ,key))))
The function alist-remove
works just fine. The macro alist-pop
returns the value of the key correctly, but doesn't modify the value of alist
. What am I missing?