unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Karl Chen" <quarl.newsgroup@REMOVE_ME_quarl.org>
Subject: Re: add-to-plist, add-plist-to-plist functions
Date: Sun, 28 Apr 2002 16:45:56 -0700	[thread overview]
Message-ID: <aai1jn$2d70$1@agate.berkeley.edu> (raw)
In-Reply-To: 877kmr2y2c.fsf@tc-1-100.kawasaki.gol.ne.jp

Oops! You're right, thanks. Here's the same code with names changed.

(defun add-to-alist (alist-var p)
  "Add an element to an alist symbol.

If the element is a cons:
  If there exists an element in the value of ALIST-VAR whose car matches the
new element's car, replace its cdr. Else prepend the whole element to the
list.

If the element is not a cons:
  If the element does not already exist, prepend it. (Equivalent to
`add-to-list' in this case.)"
  (if (consp p)
      (let ((alist (symbol-value alist-var))
            (pname (car p)))
        (when pname
          (while alist
            (let ((p0 (car alist)))
              (setq alist (cdr alist))
              (when (and (consp p0) (eq (car p0) pname))
                (setcdr p0 (cdr p))
            (setq alist nil)
            (setq pname nil))))
          (when pname
            (set alist-var (cons p (symbol-value alist-var)))
            )))
    (add-to-list alist-var p)))

(defun add-alist-to-alist (alist new-alist)
  "Apply NEW-ALIST on ALIST by calling `add-to-alist' on each entry."
  (while new-alist
    (add-to-alist 'alist (car new-alist))
    (setq new-alist (cdr new-alist))
    )
  alist)


"Miles Bader" <miles@gnu.org> wrote in message
news:877kmr2y2c.fsf@tc-1-100.kawasaki.gol.ne.jp...
> "Karl Chen" <quarl.newsgroup@REMOVE_ME_quarl.org> writes:
> > Hi, I wrote these two functions which may be useful to others:
>
> Your terminology is incorrect -- looking at your code, it seems to be
> manipulating `alists', not `plists'.
>
> [An alist is a list of cons cells, with the car of each being the key,
> and the cdr the value; a plist is a list of alternating keys and values.]
>
> -Miles
> --
> Run away!  Run away!

      reply	other threads:[~2002-04-28 23:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-28 23:26 add-to-plist, add-plist-to-plist functions Karl Chen
2002-04-28 23:38 ` Miles Bader
2002-04-28 23:45   ` Karl Chen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='aai1jn$2d70$1@agate.berkeley.edu' \
    --to=quarl.newsgroup@remove_me_quarl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).