Updates to my about.el bio.
[sxemacs] / lisp / alist.el
1 ;;; alist.el --- utility functions for association list
2
3 ;; Copyright (C) 1993,1994,1995,1996,1998,2000 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Maintainer: The SXEmacs Development Team <sxemacs-devel@sxemacs.org>
7 ;; Keywords: alist
8
9 ;; This file is part of SXEmacs.
10
11 ;; SXEmacs is free software: you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by the
13 ;; Free Software Foundation, either version 3 of the License, or (at your
14 ;; option) any later version.
15
16 ;; SXEmacs is distributed in the hope that it will be
17 ;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Code:
25
26 ;;;###autoload
27 (defun put-alist (key value alist)
28   "Set cdr of an element (KEY . ...) in ALIST to VALUE and return ALIST.
29 If there is no such element, create a new pair (KEY . VALUE) and
30 return a new alist whose car is the new pair and cdr is ALIST."
31   (let ((elm (assoc key alist)))
32     (if elm
33         (progn
34           (setcdr elm value)
35           alist)
36       (cons (cons key value) alist))))
37
38 ;;;###autoload
39 (defun del-alist (key alist)
40   "Delete an element whose car equals KEY from ALIST.
41 Return the modified ALIST."
42   (let ((pair (assoc key alist)))
43     (if pair
44         (delq pair alist)
45       alist)))
46
47 ;;;###autoload
48 (defun set-alist (symbol key value)
49   "Set cdr of an element (KEY . ...) in the alist bound to SYMBOL to VALUE."
50   (or (boundp symbol)
51       (set symbol nil))
52   (set symbol (put-alist key value (symbol-value symbol))))
53
54 ;;;###autoload
55 (defun remove-alist (symbol key)
56   "Delete an element whose car equals KEY from the alist bound to SYMBOL."
57   (and (boundp symbol)
58        (set symbol (del-alist key (symbol-value symbol)))))
59
60 ;;;###autoload
61 (defun modify-alist (modifier default)
62   "Store elements in the alist MODIFIER in the alist DEFAULT.
63 Return the modified alist."
64   (mapcar (function
65            (lambda (as)
66              (setq default (put-alist (car as)(cdr as) default))))
67           modifier)
68   default)
69
70 ;;;###autoload
71 (defun set-modified-alist (symbol modifier)
72   "Store elements in the alist MODIFIER in an alist bound to SYMBOL.
73 If SYMBOL is not bound, set it to nil at first."
74   (if (not (boundp symbol))
75       (set symbol nil))
76   (set symbol (modify-alist modifier (eval symbol))))
77
78
79 ;;; @ association-vector-list
80 ;;;
81
82 ;;;###autoload
83 (defun vassoc (key avlist)
84   "Search AVLIST for an element whose first element equals KEY.
85 AVLIST is a list of vectors.
86 See also `assoc'."
87   (while (and avlist
88               (not (equal key (aref (car avlist) 0))))
89     (setq avlist (cdr avlist)))
90   (and avlist
91        (car avlist)))
92
93
94 ;;; @ end
95 ;;;
96
97 (provide 'alist)
98
99 ;;; alist.el ends here