emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Update assq-delete-all to support keys of string type


From: Kaushal
Subject: Update assq-delete-all to support keys of string type
Date: Tue, 12 May 2015 10:57:51 -0400

Hi,

I wanted to use assq-delete-all to remove all elements in an alist whose car matched a string.

Example alist:

(setq temp-alist '(("a" . 1) ("b" . 2)))

Currently I cannot do

(setq temp-alist (assq-delete-all "a" temp-alist))

Is there a right way to do this?

For now, I just created a new function by simply replacing eq with string=

(defun assq-delete-all-string (key-str alist)
  "Delete from ALIST all elements whose car is a string and matches KEY-STR.
Return the modified alist.
Elements of ALIST that are not conses are ignored."
  (while (and (consp (car alist))
     (string= (car (car alist)) key-str))
    (setq alist (cdr alist)))
  (let ((tail alist) tail-cdr)
    (while (setq tail-cdr (cdr tail))
      (if (and (consp (car tail-cdr))
      (string= (car (car tail-cdr)) key-str))
 (setcdr tail (cdr tail-cdr))
(setq tail tail-cdr))))
  alist)

Can the assq-delete-all be updated to use string= when the KEY type is string and eq otherwise (if those two cases cover everything?)

In general I am requesting assq-delete-all to use

- `string=` if KEY is string
- `SOME-OTHER-FN` if KEY is SOME-OTHER-TYPE
- `eq` otherwise

--
Kaushal Modi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]