assq-delete-all
is close to what you want. It looks up elements by object identity (eq
), not by value equality (equal
). It removes all matching elements, not just the first. It returns the modified list. You can adapt the code of this function to do what you want. (But if you were going to call assoc-pop
in a loop, and all your keys are symbols, assq-delete-all
does all you need.)
Note that "a"
and 'a
are completely different objects: the first is a string, the second is a symbol. So your second line should have been (assoc-pop 'a alist)
.
But in fact, the call (assoc-pop 'a alist)
can't work (unless assoc-pop
is a macro), because it is incapable of removing the first element in a list. You can make a function that takes a symbol as argument and modifies the list that is the value of the symbol, following the model of add-to-list
. You would call it as (assoc-pop 'a 'alist)
.