You are looking at historical revision 4788 of this page. It may differ significantly from its current revision.
Introduction
This egg provides keyword/value list (or key-value list, for short) operations. Key-value lists are a subset of property lists wherein the key is always a self-evaluating keyword symbol.
In addition to key-value list manipulators, the egg also provides facilities for conversions between kvlists (key-value lists) and both plists (property lists) and alists (association lists)
Examples
Using key-value lists
#;1> (use kvlists) #;2> (define lst '(x: 1 y: 2 z: 3)) #;3> (kvlist? lst) #t #;4> (kvlist-ref lst z:) 3 #;5> (kvlist-ref lst abc:) #f #;6> (kvlist-ref lst abc: 123) 123 #;7> (kvlist->alist lst) ((x . 1) (y . 2) (z . 3)) #;8> (kvlist->plist lst) (x 1 y 2 z 3)
The let/kv convenience macro
There are many opportunities to use key-value lists to cut down on the proliferation of parentheses in syntactic forms. While this may arguably be against the Lisp ethos, here's a macro let/kv which uses let to introduce lexically scoped variable bindings but without one layer of enclosing parentheses:
(use kvlists) (define-macro (let/kv head . body) `(let ,(map (lambda (kv) (list (car kv) (cdr kv))) (kvlist->alist head)) ,@body)) (let/kv (x: 123 y: 456 z: 789) (printf "x + y + z = ~A" (+ x y z)))
Author
Predicates
kvlist?
[procedure] (kvlist? X)
alist?
[procedure] (alist? X)
plist?
[procedure] (plist? X)
Constructors
kvlist-cons
[procedure] (kvlist-cons KEY VALUE KVLIST)
Accessors
kvlist-key?
[procedure] (kvlist-key? KVLIST KEY)
kvlist-ref
[procedure] (kvlist-ref KVLIST KEY)
kvlist-assoc
[procedure] (kvlist-assoc KEY KVLIST)
Mutators
kvlist-set!
[procedure] (kvlist-set! KVLIST KEY VALUE)
Conversions
kvlist->alist
[procedure] (kvlist->alist KVLIST)
kvlist->plist
[procedure] (kvlist->plist KVLIST)
alist->kvlist
[procedure] (alist->kvlist ALIST)
alist->plist
[procedure] (alist->plist ALIST)
plist->kvlist
[procedure] (plist->kvlist PLIST)
plist->alist
[procedure] (plist->alist PLIST)
License
Copyright (c) 2006-2007 Arto Bendiken. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Version history
Not released yed, but available from SVN.