Mercurial > hg > xemacs-beta
comparison lisp/alist.el @ 428:3ecd8885ac67 r21-2-22
Import from CVS: tag r21-2-22
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:28:15 +0200 |
parents | |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
427:0a0253eac470 | 428:3ecd8885ac67 |
---|---|
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 | |
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. | |
14 | |
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. | |
19 | |
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. | |
24 | |
25 ;;; Code: | |
26 | |
27 ;;;###autoload | |
28 (defun put-alist (item value alist) | |
29 "Modify ALIST to set VALUE to ITEM. | |
30 If there is a pair whose car is ITEM, replace its cdr by VALUE. | |
31 If there is not such pair, create new pair (ITEM . VALUE) and | |
32 return new alist whose car is the new pair and cdr is ALIST. | |
33 \[tomo's ELIS like function]" | |
34 (let ((pair (assoc item alist))) | |
35 (if pair | |
36 (progn | |
37 (setcdr pair value) | |
38 alist) | |
39 (cons (cons item value) alist) | |
40 ))) | |
41 | |
42 ;;;###autoload | |
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))) | |
47 (cdr alist) | |
48 (let ((pr alist) | |
49 (r (cdr alist)) | |
50 ) | |
51 (catch 'tag | |
52 (while (not (null r)) | |
53 (if (equal item (car (car r))) | |
54 (progn | |
55 (rplacd pr (cdr r)) | |
56 (throw 'tag alist))) | |
57 (setq pr r) | |
58 (setq r (cdr r)) | |
59 ) | |
60 alist)))) | |
61 | |
62 ;;;###autoload | |
63 (defun set-alist (symbol item value) | |
64 "Modify a alist indicated by SYMBOL to set VALUE to ITEM." | |
65 (or (boundp symbol) | |
66 (set symbol nil) | |
67 ) | |
68 (set symbol (put-alist item value (symbol-value symbol))) | |
69 ) | |
70 | |
71 ;;;###autoload | |
72 (defun remove-alist (symbol item) | |
73 "Remove ITEM from the alist indicated by SYMBOL." | |
74 (and (boundp symbol) | |
75 (set symbol (del-alist item (symbol-value symbol))) | |
76 )) | |
77 | |
78 ;;;###autoload | |
79 (defun modify-alist (modifier default) | |
80 "Modify alist DEFAULT into alist MODIFIER." | |
81 (mapcar (function | |
82 (lambda (as) | |
83 (setq default (put-alist (car as)(cdr as) default)) | |
84 )) | |
85 modifier) | |
86 default) | |
87 | |
88 ;;;###autoload | |
89 (defun set-modified-alist (sym modifier) | |
90 "Modify a value of a symbol SYM into alist MODIFIER. | |
91 The symbol SYM should be alist. If it is not bound, | |
92 its value regard as nil." | |
93 (if (not (boundp sym)) | |
94 (set sym nil) | |
95 ) | |
96 (set sym (modify-alist modifier (eval sym))) | |
97 ) | |
98 | |
99 | |
100 ;;; @ end | |
101 ;;; | |
102 | |
103 (provide 'alist) | |
104 | |
105 ;;; alist.el ends here |