All of SXEmacs' http URLs are now https. WooHoo!
[sxemacs] / lisp / alist.el
1 ;;; alist.el --- utility functions about association-list
2
3 ;; Copyright (C) 1993,1994,1995,1996,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: alist
7
8 ;; This file is part of APEL (A Portable Emacs Library).
9 ;; This file is part of SXEmacs.
10
11 ;; SXEmacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; SXEmacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU 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 \f
25 ;;;###autoload
26 (defun vassoc (key valist)
27   "Search VALIST for a vector whose first element is equal to KEY.
28 See also `assoc'."
29   ;; by Stig@hackvan.com
30   (let (el)
31     (catch 'done
32       (while (setq el (pop valist))
33         (and (equal key (aref el 0))
34              (throw 'done el))))))
35 \f
36
37 ;;;###autoload
38 (defun put-alist (item value alist)
39   "Modify ALIST to set VALUE to ITEM.
40 If there is a pair whose car is ITEM, replace its cdr by VALUE.
41 If there is not such pair, create new pair (ITEM . VALUE) and
42 return new alist whose car is the new pair and cdr is ALIST.
43 \[tomo's ELIS like function]"
44   (let ((pair (assoc item alist)))
45     (if pair
46         (progn
47           (setcdr pair value)
48           alist)
49       (cons (cons item value) alist)
50       )))
51
52 ;;;###autoload
53 (defun del-alist (item alist)
54   "If there is a pair whose key is ITEM, delete it from ALIST.
55 \[tomo's ELIS emulating function]"
56   (if (equal item (car (car alist)))
57       (cdr alist)
58     (let ((pr alist)
59           (r (cdr alist))
60           )
61       (catch 'tag
62         (while (not (null r))
63           (if (equal item (car (car r)))
64               (progn
65                 (rplacd pr (cdr r))
66                 (throw 'tag alist)))
67           (setq pr r)
68           (setq r (cdr r))
69           )
70         alist))))
71
72 ;;;###autoload
73 (defun set-alist (symbol item value)
74   "Modify a alist indicated by SYMBOL to set VALUE to ITEM."
75   (or (boundp symbol)
76       (set symbol nil)
77       )
78   (set symbol (put-alist item value (symbol-value symbol)))
79   )
80
81 ;;;###autoload
82 (defun remove-alist (symbol item)
83   "Remove ITEM from the alist indicated by SYMBOL."
84   (and (boundp symbol)
85        (set symbol (del-alist item (symbol-value symbol)))
86        ))
87
88 ;;;###autoload
89 (defun modify-alist (modifier default)
90   "Modify alist DEFAULT into alist MODIFIER."
91   (mapcar (function
92            (lambda (as)
93              (setq default (put-alist (car as)(cdr as) default))
94              ))
95           modifier)
96   default)
97
98 ;;;###autoload
99 (defun set-modified-alist (sym modifier)
100   "Modify a value of a symbol SYM into alist MODIFIER.
101 The symbol SYM should be alist. If it is not bound,
102 its value regard as nil."
103   (if (not (boundp sym))
104       (set sym nil)
105     )
106   (set sym (modify-alist modifier (eval sym)))
107   )
108
109
110 ;;; @ end
111 ;;;
112
113 (provide 'alist)
114
115 ;;; alist.el ends here