From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Karl Chen" Newsgroups: gmane.emacs.bugs Subject: Re: add-to-plist, add-plist-to-plist functions Date: Sun, 28 Apr 2002 16:45:56 -0700 Organization: University of California, Berkeley Sender: bug-gnu-emacs-admin@gnu.org Message-ID: References: <877kmr2y2c.fsf@tc-1-100.kawasaki.gol.ne.jp> NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1020037726 22171 127.0.0.1 (28 Apr 2002 23:48:46 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 28 Apr 2002 23:48:46 +0000 (UTC) Return-path: Original-Received: from fencepost.gnu.org ([199.232.76.164]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 171yPN-0005lU-00 for ; Mon, 29 Apr 2002 01:48:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 171yPC-0006Nc-00; Sun, 28 Apr 2002 19:48:34 -0400 Original-Received: from agate.berkeley.edu ([128.32.206.40]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 171yMh-0006FF-00 for ; Sun, 28 Apr 2002 19:46:00 -0400 Original-Received: (from news@localhost) by agate.berkeley.edu (8.11.6/8.11.3) id g3SNjx079074 ; Sun, 28 Apr 2002 16:45:59 -0700 (PDT) (envelope-from news) Original-To: gnu-emacs-bug@prep.ai.mit.edu Original-Path: not-for-mail Original-Newsgroups: gnu.emacs.bug Original-Lines: 54 Original-NNTP-Posting-Host: star.cs.berkeley.edu Original-X-Trace: agate.berkeley.edu 1020037559 79072 128.32.42.27 (28 Apr 2002 23:45:59 GMT) Original-X-Complaints-To: usenet@agate.berkeley.edu Original-NNTP-Posting-Date: Sun, 28 Apr 2002 23:45:59 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:1014 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:1014 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" wrote in message news:877kmr2y2c.fsf@tc-1-100.kawasaki.gol.ne.jp... > "Karl Chen" 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!