1 ;;; alist.el --- utility functions about association-list
3 ;; Copyright (C) 1993,1994,1995,1996,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; This file is part of APEL (A Portable Emacs Library).
9 ;; This file is part of SXEmacs.
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.
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.
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/>.
26 (defun vassoc (key valist)
27 "Search VALIST for a vector whose first element is equal to KEY.
29 ;; by Stig@hackvan.com
32 (while (setq el (pop valist))
33 (and (equal key (aref el 0))
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)))
49 (cons (cons item value) alist)
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)))
63 (if (equal item (car (car r)))
73 (defun set-alist (symbol item value)
74 "Modify a alist indicated by SYMBOL to set VALUE to ITEM."
78 (set symbol (put-alist item value (symbol-value symbol)))
82 (defun remove-alist (symbol item)
83 "Remove ITEM from the alist indicated by SYMBOL."
85 (set symbol (del-alist item (symbol-value symbol)))
89 (defun modify-alist (modifier default)
90 "Modify alist DEFAULT into alist MODIFIER."
93 (setq default (put-alist (car as)(cdr as) default))
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))
106 (set sym (modify-alist modifier (eval sym)))
115 ;;; alist.el ends here