1 ;;; alist.el --- utility functions for association list
3 ;; Copyright (C) 1993,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
8 ;; This file is part of GNU Emacs.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
28 (defun put-alist (key value alist)
29 "Set cdr of an element (KEY . ...) in ALIST to VALUE and return ALIST.
30 If there is no such element, create a new pair (KEY . VALUE) and
31 return a new alist whose car is the new pair and cdr is ALIST."
32 (let ((elm (assoc key alist)))
37 (cons (cons key value) alist))))
40 (defun del-alist (key alist)
41 "Delete an element whose car equals KEY from ALIST.
42 Return the modified ALIST."
43 (let ((pair (assoc key alist)))
49 (defun set-alist (symbol key value)
50 "Set cdr of an element (KEY . ...) in the alist bound to SYMBOL to VALUE."
53 (set symbol (put-alist key value (symbol-value symbol))))
56 (defun remove-alist (symbol key)
57 "Delete an element whose car equals KEY from the alist bound to SYMBOL."
59 (set symbol (del-alist key (symbol-value symbol)))))
62 (defun modify-alist (modifier default)
63 "Store elements in the alist MODIFIER in the alist DEFAULT.
64 Return the modified alist."
67 (setq default (put-alist (car as)(cdr as) default))))
72 (defun set-modified-alist (symbol modifier)
73 "Store elements in the alist MODIFIER in an alist bound to SYMBOL.
74 If SYMBOL is not bound, set it to nil at first."
75 (if (not (boundp symbol))
77 (set symbol (modify-alist modifier (eval symbol))))
80 ;;; @ association-vector-list
84 (defun vassoc (key avlist)
85 "Search AVLIST for an element whose first element equals KEY.
86 AVLIST is a list of vectors.
89 (not (equal key (aref (car avlist) 0))))
90 (setq avlist (cdr avlist)))
99 (product-provide (provide 'alist) (require 'apel-ver))
101 ;;; alist.el ends here