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