help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: best way to get the list of unique keys from 2 alists


From: Kevin Rodgers
Subject: Re: best way to get the list of unique keys from 2 alists
Date: Fri, 16 Dec 2005 17:36:39 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Kevin Rodgers wrote:
I've got 2 alists of (SYMBOL . "STRING") pairs, and I need to get the
list of unique symbol names to pass to completing-read as its TABLE
argument: (("SYMBOL-NAME") ...)

I know about remove-duplicates and union, but I'd like to avoid using
cl*.el functions.

Since completing-read seems to ignore nil entries in TABLE, this is what
I've got now:

(nconc (mapcar (lambda (assoc)
                 (list (symbol-name (car assoc))))
               alist-1)
       (mapcar (lambda (assoc)
                 (or (assq (car assoc) alist-1)
                     (list (symbol-name (car assoc)))))
               alist-2))

Is there a cleaner way?

Since completing-read also accepts an obarray for its TABLE, I think
this might be a little better:

(let ((table (make-vector 83 0))) ; 83 is a suitable prime
  (mapc (lambda (assoc)
          (intern (symbol-name (car assoc)) table))
        alist-1)
  (mapc (lambda (assoc)
          (intern (symbol-name (car assoc)) table))
        alist-2)
  table)

--
Kevin Rodgers





reply via email to

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