annotate lisp/alist.el @ 441:72a7cfa4a488

Added tag r21-2-28 for changeset 8de8e3f6228a
author cvs
date Mon, 13 Aug 2007 11:33:40 +0200
parents 3ecd8885ac67
children abe6d1db359e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; alist.el --- utility functions about association-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993,1994,1995,1996,1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Keywords: alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; This file is part of APEL (A Portable Emacs Library).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; This program is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; modify it under the terms of the GNU General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; published by the Free Software Foundation; either version 2, or (at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 (defun put-alist (item value alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 "Modify ALIST to set VALUE to ITEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 If there is a pair whose car is ITEM, replace its cdr by VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 If there is not such pair, create new pair (ITEM . VALUE) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 return new alist whose car is the new pair and cdr is ALIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 \[tomo's ELIS like function]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 (let ((pair (assoc item alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 (if pair
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 (setcdr pair value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 (cons (cons item value) alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 (defun del-alist (item alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 "If there is a pair whose key is ITEM, delete it from ALIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 \[tomo's ELIS emulating function]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 (if (equal item (car (car alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 (cdr alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 (let ((pr alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 (r (cdr alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 (catch 'tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 (while (not (null r))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 (if (equal item (car (car r)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 (rplacd pr (cdr r))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 (throw 'tag alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 (setq pr r)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 (setq r (cdr r))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (defun set-alist (symbol item value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 "Modify a alist indicated by SYMBOL to set VALUE to ITEM."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (or (boundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (set symbol nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (set symbol (put-alist item value (symbol-value symbol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (defun remove-alist (symbol item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 "Remove ITEM from the alist indicated by SYMBOL."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (and (boundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (set symbol (del-alist item (symbol-value symbol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (defun modify-alist (modifier default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 "Modify alist DEFAULT into alist MODIFIER."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (mapcar (function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (lambda (as)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (setq default (put-alist (car as)(cdr as) default))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 modifier)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (defun set-modified-alist (sym modifier)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 "Modify a value of a symbol SYM into alist MODIFIER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 The symbol SYM should be alist. If it is not bound,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 its value regard as nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (if (not (boundp sym))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (set sym nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 (set sym (modify-alist modifier (eval sym)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;;; @ end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 (provide 'alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ;;; alist.el ends here