Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for [[/eggref/4/kvlists|the CHICKEN 4 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-4.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: eggs kvlists alists plists]] [[toc:]] == K/V-lists This egg provides keyword/value list (or key-value list, for short) operations. Key-value lists are a restricted 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). Here's a run-down of the different ways to use Scheme lists for directly storing mappings/bindings: ; Association lists : {{((k1 . v1) (k2 . v2) (k3 . v3) ...)}} ; Property lists : {{(k1 v1 k2 v2 k3 v3 ...)}} ; Key-value lists : {{(k1: v1 k2: v2 k3: v3 ...)}} (Self-evaluating keyword symbols are defined in [[http://srfi.schemers.org/srfi-88/|SRFI-88: Keyword objects]]). === Examples ==== Using key-value lists These examples assume Chicken is being run with {{-keyword-style suffix}}, which is the default mode. See the manual section [[/man/3/Using the interpreter|Using the interpreter]] in case you wish to use prefix-style keywords as in Common Lisp. <enscript highlight=scheme> #;1> (use kvlists) #;2> (define lst '(foo: 1 bar: 2 baz: 3)) #;3> (kvlist? lst) #t #;4> (kvlist-ref lst baz:) 3 #;5> (kvlist-ref lst abc:) #f #;6> (kvlist-ref lst abc: 123) 123 #;7> (kvlist->alist lst) ((foo . 1) (bar . 2) (baz . 3)) #;8> (kvlist->plist lst) (foo 1 bar 2 baz 3) </enscript> ==== A 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 straightforward {{let/kv}} macro which uses {{let}} to introduce lexically scoped variable bindings but without one layer of enclosing parentheses in the defining form: <enscript highlight=scheme> (use kvlists) (define-macro (let/kv head . body) `(let ,(kvlist-map (lambda (k v) (list (keyword->symbol k) v)) head) ,@body)) (let/kv (x: 123 y: 456 z: 789) (printf "x + y + z = ~A\n" (+ x y z))) </enscript> === Author [[/users/arto-bendiken|Arto Bendiken]] === Constructors ==== kvlist-cons* <procedure>(kvlist-cons* KEY VALUE KVLIST)</procedure> === Predicates ==== kvlist? <procedure>(kvlist? X)</procedure> ==== alist? <procedure>(alist? X)</procedure> ==== plist? <procedure>(plist? X)</procedure> === Selectors ==== kvlist-key? <procedure>(kvlist-key? KVLIST KEY)</procedure> ==== kvlist-ref <procedure>(kvlist-ref KVLIST KEY)</procedure> ==== kvlist-assoc <procedure>(kvlist-assoc KEY KVLIST)</procedure> === Iteration ==== kvlist-map <procedure>(kvlist-map PROC KVLIST)</procedure> ==== kvlist-for-each <procedure>(kvlist-for-each PROC KVLIST)</procedure> === Filtering ==== kvlist-delete <procedure>(kvlist-delete KEY KVLIST)</procedure> === Mutators ==== kvlist-set! <procedure>(kvlist-set! KVLIST KEY VALUE)</procedure> === Conversions ==== kvlist->alist <procedure>(kvlist->alist KVLIST)</procedure> ==== kvlist->plist <procedure>(kvlist->plist KVLIST)</procedure> ==== alist->kvlist <procedure>(alist->kvlist ALIST)</procedure> ==== alist->plist <procedure>(alist->plist ALIST)</procedure> ==== plist->kvlist <procedure>(plist->kvlist PLIST)</procedure> === plist->alist <procedure>(plist->alist PLIST)</procedure> === Miscellaneous ==== keyword->symbol <procedure>(keyword->symbol KEYWORD)</procedure> ==== symbol->keyword <procedure>(symbol->keyword SYMBOL)</procedure> === 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 ;1.0.0 : Initial release of the {{kvlists}} egg.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 8 by 9?