1 ;;; alist.el --- utility functions for association list
3 ;; Copyright (C) 1993,1994,1995,1996,1998,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Maintainer: The SXEmacs Development Team <sxemacs-devel@sxemacs.org>
9 ;; This file is part of SXEmacs.
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.
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.
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/>.
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)))
36 (cons (cons key value) alist))))
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)))
48 (defun set-alist (symbol key value)
49 "Set cdr of an element (KEY . ...) in the alist bound to SYMBOL to VALUE."
52 (set symbol (put-alist key value (symbol-value symbol))))
55 (defun remove-alist (symbol key)
56 "Delete an element whose car equals KEY from the alist bound to SYMBOL."
58 (set symbol (del-alist key (symbol-value symbol)))))
61 (defun modify-alist (modifier default)
62 "Store elements in the alist MODIFIER in the alist DEFAULT.
63 Return the modified alist."
66 (setq default (put-alist (car as)(cdr as) default))))
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))
76 (set symbol (modify-alist modifier (eval symbol))))
79 ;;; @ association-vector-list
83 (defun vassoc (key avlist)
84 "Search AVLIST for an element whose first element equals KEY.
85 AVLIST is a list of vectors.
88 (not (equal key (aref (car avlist) 0))))
89 (setq avlist (cdr avlist)))
99 ;;; alist.el ends here