1 ;;; alist.el --- utility functions about assoc-list
3 ;; Copyright (C) 1993,1994,1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; $Id: alist.el,v 0.0 1997-02-28 02:18:23 tmorioka Exp $
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 (defun put-alist (item value alist)
30 "Modify ALIST to set VALUE to ITEM.
31 If there is a pair whose car is ITEM, replace its cdr by VALUE.
32 If there is not such pair, create new pair (ITEM . VALUE) and
33 return new alist whose car is the new pair and cdr is ALIST.
34 \[tomo's ELIS like function]"
35 (let ((pair (assoc item alist)))
40 (cons (cons item value) alist)
43 (defun del-alist (item alist)
44 "If there is a pair whose key is ITEM, delete it from ALIST.
45 \[tomo's ELIS emulating function]"
46 (if (equal item (car (car alist)))
53 (if (equal item (car (car r)))
62 (defun set-alist (symbol item value)
63 "Modify a alist indicated by SYMBOL to set VALUE to ITEM."
67 (set symbol (put-alist item value (symbol-value symbol)))
70 (defun remove-alist (symbol item)
71 "Remove ITEM from the alist indicated by SYMBOL."
73 (set symbol (del-alist item (symbol-value symbol)))
76 (defun modify-alist (modifier default)
77 "Modify alist DEFAULT into alist MODIFIER."
80 (setq default (put-alist (car as)(cdr as) default))
85 (defun set-modified-alist (sym modifier)
86 "Modify a value of a symbol SYM into alist MODIFIER.
87 The symbol SYM should be alist. If it is not bound,
88 its value regard as nil."
89 (if (not (boundp sym))
92 (set sym (modify-alist modifier (eval sym)))
101 ;;; alist.el ends here