Elisp: How to delete an element from an association list with string key

后端 未结 4 1341
执念已碎
执念已碎 2021-02-07 06:54

Now this works just fine:

(setq al \'((a . \"1\") (b . \"2\")))
(assq-delete-all \'a al)

But I\'m using strings as keys in my app:



        
4条回答
  •  佛祖请我去吃肉
    2021-02-07 07:00

    If you know there can only be a single matching entry in your list, you can also use the following form:

    (setq al (delq (assoc  al) al)
    

    Notice that the setq (which was missing from your sample code) is very important for `delete' operations on lists, otherwise the operation fails when the deleted element happens to be the first on the list.

提交回复
热议问题