Mercurial > hg > xemacs-beta
comparison lisp/alist.el @ 219:262b8bb4a523 r20-4b8
Import from CVS: tag r20-4b8
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:09:35 +0200 |
parents | |
children | fbbf69b4e8a7 |
comparison
equal
deleted
inserted
replaced
218:c9f226976f56 | 219:262b8bb4a523 |
---|---|
1 ;;; alist.el --- utility functions about assoc-list | |
2 | |
3 ;; Copyright (C) 1993,1994,1995,1996 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> | |
6 ;; Version: | |
7 ;; $Id: alist.el,v 1.1 1997/11/29 20:37:43 steve Exp $ | |
8 ;; Keywords: alist | |
9 | |
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces). | |
11 | |
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. | |
16 | |
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. | |
21 | |
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. | |
26 | |
27 ;;; Code: | |
28 | |
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))) | |
36 (if pair | |
37 (progn | |
38 (setcdr pair value) | |
39 alist) | |
40 (cons (cons item value) alist) | |
41 ))) | |
42 | |
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 (defun set-alist (symbol item value) | |
63 "Modify a alist indicated by SYMBOL to set VALUE to ITEM." | |
64 (or (boundp symbol) | |
65 (set symbol nil) | |
66 ) | |
67 (set symbol (put-alist item value (symbol-value symbol))) | |
68 ) | |
69 | |
70 (defun remove-alist (symbol item) | |
71 "Remove ITEM from the alist indicated by SYMBOL." | |
72 (and (boundp symbol) | |
73 (set symbol (del-alist item (symbol-value symbol))) | |
74 )) | |
75 | |
76 (defun modify-alist (modifier default) | |
77 "Modify alist DEFAULT into alist MODIFIER." | |
78 (mapcar (function | |
79 (lambda (as) | |
80 (setq default (put-alist (car as)(cdr as) default)) | |
81 )) | |
82 modifier) | |
83 default) | |
84 | |
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)) | |
90 (set sym nil) | |
91 ) | |
92 (set sym (modify-alist modifier (eval sym))) | |
93 ) | |
94 | |
95 | |
96 ;;; @ end | |
97 ;;; | |
98 | |
99 (provide 'alist) | |
100 | |
101 ;;; alist.el ends here |