~ubuntu-branches/ubuntu/karmic/emacs-snapshot/karmic

« back to all changes in this revision

Viewing changes to lisp/emacs-lisp/assoc.el

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-04-05 09:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090405091430-nw07lynn2arotjbe
Tags: upstream-20090320
ImportĀ upstreamĀ versionĀ 20090320

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;;; assoc.el --- insert/delete/sort functions on association lists
2
2
 
3
3
;; Copyright (C) 1996, 2001, 2002, 2003, 2004, 2005,
4
 
;;   2006, 2007, 2008 Free Software Foundation, Inc.
 
4
;;   2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5
5
 
6
6
;; Author: Barry A. Warsaw <bwarsaw@cen.com>
7
7
;; Keywords: extensions
30
30
 
31
31
(defun asort (alist-symbol key)
32
32
  "Move a specified key-value pair to the head of an alist.
33
 
The alist is referenced by ALIST-SYMBOL. Key-value pair to move to
 
33
The alist is referenced by ALIST-SYMBOL.  Key-value pair to move to
34
34
head is one matching KEY.  Returns the sorted list and doesn't affect
35
35
the order of any other key-value pair.  Side effect sets alist to new
36
36
sorted list."
40
40
 
41
41
 
42
42
(defun aelement (key value)
43
 
  "Makes a list of a cons cell containing car of KEY and cdr of VALUE.
 
43
  "Make a list of a cons cell containing car of KEY and cdr of VALUE.
44
44
The returned list is suitable as an element of an alist."
45
45
  (list (cons key value)))
46
46
 
61
61
 
62
62
(defun aput (alist-symbol key &optional value)
63
63
  "Inserts a key-value pair into an alist.
64
 
The alist is referenced by ALIST-SYMBOL. The key-value pair is made
65
 
from KEY and optionally, VALUE. Returns the altered alist or nil if
 
64
The alist is referenced by ALIST-SYMBOL.  The key-value pair is made
 
65
from KEY and optionally, VALUE.  Returns the altered alist or nil if
66
66
ALIST is nil.
67
67
 
68
68
If the key-value pair referenced by KEY can be found in the alist, and
69
69
VALUE is supplied non-nil, then the value of KEY will be set to VALUE.
70
70
If VALUE is not supplied, or is nil, the key-value pair will not be
71
 
modified, but will be moved to the head of the alist. If the key-value
 
71
modified, but will be moved to the head of the alist.  If the key-value
72
72
pair cannot be found in the alist, it will be inserted into the head
73
73
of the alist (with value nil if VALUE is nil or not supplied)."
74
74
  (let ((elem (aelement key value))
93
93
 
94
94
 
95
95
(defun aget (alist key &optional keynil-p)
96
 
  "Returns the value in ALIST that is associated with KEY.
 
96
  "Return the value in ALIST that is associated with KEY.
97
97
Optional KEYNIL-P describes what to do if the value associated with
98
98
KEY is nil.  If KEYNIL-P is not supplied or is nil, and the value is
99
99
nil, then KEY is returned.  If KEYNIL-P is non-nil, then nil would be
100
100
returned.
101
101
 
102
102
If no key-value pair matching KEY could be found in ALIST, or ALIST is
103
 
nil then nil is returned. ALIST is not altered."
 
103
nil then nil is returned.  ALIST is not altered."
104
104
  (let ((copy (copy-alist alist)))
105
105
    (cond ((null alist) nil)
106
106
          ((progn (asort 'copy key)
114
114
(defun amake (alist-symbol keylist &optional valuelist)
115
115
  "Make an association list.
116
116
The association list is attached to the alist referenced by
117
 
ALIST-SYMBOL. Each element in the KEYLIST becomes a key and is
118
 
associated with the value in VALUELIST with the same index. If
 
117
ALIST-SYMBOL.  Each element in the KEYLIST becomes a key and is
 
118
associated with the value in VALUELIST with the same index.  If
119
119
VALUELIST is not supplied or is nil, then each key in KEYLIST is
120
120
associated with nil.
121
121