Mercurial > hg > xemacs-beta
comparison lisp/alist.el @ 371:cc15677e0335 r21-2b1
Import from CVS: tag r21-2b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:03:08 +0200 |
parents | fbbf69b4e8a7 |
children | 6719134a07c2 |
comparison
equal
deleted
inserted
replaced
370:bd866891f083 | 371:cc15677e0335 |
---|---|
1 ;;; alist.el --- utility functions about association-list | 1 ;;; alist.el --- utility functions about assoc-list |
2 | 2 |
3 ;; Copyright (C) 1993,1994,1995,1996,1998 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1993,1994,1995,1996 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> | 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 $ | |
6 ;; Keywords: alist | 8 ;; Keywords: alist |
7 | 9 |
8 ;; This file is part of APEL (A Portable Emacs Library). | 10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces). |
9 | 11 |
10 ;; This program is free software; you can redistribute it and/or | 12 ;; This program is free software; you can redistribute it and/or |
11 ;; modify it under the terms of the GNU General Public License as | 13 ;; modify it under the terms of the GNU General Public License as |
12 ;; published by the Free Software Foundation; either version 2, or (at | 14 ;; published by the Free Software Foundation; either version 2, or (at |
13 ;; your option) any later version. | 15 ;; your option) any later version. |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
23 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02111-1307, USA. |
24 | 26 |
25 ;;; Code: | 27 ;;; Code: |
26 | 28 |
27 ;;;###autoload | |
28 (defun put-alist (item value alist) | 29 (defun put-alist (item value alist) |
29 "Modify ALIST to set VALUE to ITEM. | 30 "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 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 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 return new alist whose car is the new pair and cdr is ALIST. |
37 (setcdr pair value) | 38 (setcdr pair value) |
38 alist) | 39 alist) |
39 (cons (cons item value) alist) | 40 (cons (cons item value) alist) |
40 ))) | 41 ))) |
41 | 42 |
42 ;;;###autoload | |
43 (defun del-alist (item alist) | 43 (defun del-alist (item alist) |
44 "If there is a pair whose key is ITEM, delete it from ALIST. | 44 "If there is a pair whose key is ITEM, delete it from ALIST. |
45 \[tomo's ELIS emulating function]" | 45 \[tomo's ELIS emulating function]" |
46 (if (equal item (car (car alist))) | 46 (if (equal item (car (car alist))) |
47 (cdr alist) | 47 (cdr alist) |
57 (setq pr r) | 57 (setq pr r) |
58 (setq r (cdr r)) | 58 (setq r (cdr r)) |
59 ) | 59 ) |
60 alist)))) | 60 alist)))) |
61 | 61 |
62 ;;;###autoload | |
63 (defun set-alist (symbol item value) | 62 (defun set-alist (symbol item value) |
64 "Modify a alist indicated by SYMBOL to set VALUE to ITEM." | 63 "Modify a alist indicated by SYMBOL to set VALUE to ITEM." |
65 (or (boundp symbol) | 64 (or (boundp symbol) |
66 (set symbol nil) | 65 (set symbol nil) |
67 ) | 66 ) |
68 (set symbol (put-alist item value (symbol-value symbol))) | 67 (set symbol (put-alist item value (symbol-value symbol))) |
69 ) | 68 ) |
70 | 69 |
71 ;;;###autoload | |
72 (defun remove-alist (symbol item) | 70 (defun remove-alist (symbol item) |
73 "Remove ITEM from the alist indicated by SYMBOL." | 71 "Remove ITEM from the alist indicated by SYMBOL." |
74 (and (boundp symbol) | 72 (and (boundp symbol) |
75 (set symbol (del-alist item (symbol-value symbol))) | 73 (set symbol (del-alist item (symbol-value symbol))) |
76 )) | 74 )) |
77 | 75 |
78 ;;;###autoload | |
79 (defun modify-alist (modifier default) | 76 (defun modify-alist (modifier default) |
80 "Modify alist DEFAULT into alist MODIFIER." | 77 "Modify alist DEFAULT into alist MODIFIER." |
81 (mapcar (function | 78 (mapcar (function |
82 (lambda (as) | 79 (lambda (as) |
83 (setq default (put-alist (car as)(cdr as) default)) | 80 (setq default (put-alist (car as)(cdr as) default)) |
84 )) | 81 )) |
85 modifier) | 82 modifier) |
86 default) | 83 default) |
87 | 84 |
88 ;;;###autoload | |
89 (defun set-modified-alist (sym modifier) | 85 (defun set-modified-alist (sym modifier) |
90 "Modify a value of a symbol SYM into alist MODIFIER. | 86 "Modify a value of a symbol SYM into alist MODIFIER. |
91 The symbol SYM should be alist. If it is not bound, | 87 The symbol SYM should be alist. If it is not bound, |
92 its value regard as nil." | 88 its value regard as nil." |
93 (if (not (boundp sym)) | 89 (if (not (boundp sym)) |