Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== alist-lib SRFI-69-like library for alists [[toc:]] === {{alist-values}} <procedure>(alist-values alist) → list</procedure> Extract the associations from an alist. ; {{alist}} : The alist from which to extract <enscript highlight="scheme">(define (alist-values alist) (map cdr alist)) </enscript> === {{alist-keys}} <procedure>(alist-keys alist) → list</procedure> Extract the keys from an alist. ; {{alist}} : The alist from which to extract <enscript highlight="scheme">(define (alist-keys alist) (map car alist)) </enscript> === {{alist-map}} <procedure>(alist-map f alist) → list</procedure> Map across an alist; {{f}} takes two parameters: {{key}} and {{values}}. ; {{f}} : The function to apply to each key-value association ; {{alist}} : The alist to apply to <enscript highlight="scheme">(define (alist-map f alist) (map (match-lambda ((key . values) (f key values))) alist)) </enscript> === {{alist-set!}} <syntax>(alist-set! alist key value) → unspecified</syntax> Destructively set a key-value association. ; {{alist}} : The alist in which to set ; {{key}} : The key to set ; {{value}} : The value to associate with the key <enscript highlight="scheme">(define-syntax alist-set! (lambda (expression rename compare) (match expression ((_ variable key value) (let ((%if (rename 'if)) (%null? (rename 'null?)) (%set! (rename 'set!)) (%list (rename 'list)) (%cons (rename 'cons)) (%alist-prepend! (rename 'alist-prepend!))) `(,%if (,%null? ,variable) (,%set! ,variable (,%list (,%cons ,key ,value))) (,%alist-prepend! ,variable ,key ,value))))))) </enscript> === {{alist-update!}} <procedure>(alist-update! alist key function) → unspecified</procedure> <procedure>(alist-update! alist key function thunk) → unspecified</procedure> <procedure>(alist-update! alist key function thunk =) → unspecified</procedure> On analogy with hash-table-update!, descructively update an association. ; {{alist}} : The alist to update ; {{key}} : The key associated with the update ; {{f}} : A monadic function taking the preëxisting key ; {{thunk}} : The thunk to apply if no association exists ; {{=}} : The equality predicate for keys <enscript highlight="scheme">(define alist-update! (case-lambda ((alist key function) (alist-update! alist key function (lambda () (error "Key not found -- ALIST-UPDATE!" key)))) ((alist key function thunk) (alist-update! alist key function thunk eqv?)) ((alist key function thunk =) (let ((pair (assoc key alist =))) (if pair (set-cdr! pair (function (cdr pair))) (alist-set! alist key (function (thunk)))))))) </enscript> === {{alist-update!/default}} <procedure>(alist-update!/default alist key function default) → unspecified</procedure> <procedure>(alist-update!/default alist key function default =) → unspecified</procedure> On analogy with hash-table-update!, descructively update an association. ; {{alist}} : The alist to update ; {{key}} : The key associated with the update ; {{f}} : A monadic function taking the preëxisting key ; {{default}} : The default value if no association exists ; {{=}} : The equality predicate for keys <enscript highlight="scheme">(define alist-update!/default (case-lambda ((alist key function default) (alist-update!/default alist key function default eqv?)) ((alist key function default =) (alist-update! alist key function (lambda () default))))) </enscript> === {{alist-ref}} <procedure>(alist-ref alist key) → object</procedure> <procedure>(alist-ref alist key thunk) → object</procedure> <procedure>(alist-ref alist key thunk =) → object</procedure> Return a value associated with its key or apply {{thunk}}. ; {{alist}} : The alist to search in ; {{key}} : The key whose value to return ; {{thunk}} : The thunk to apply when association doesn't exist (default is to err) ; {{=}} : The equality predicate to apply to keys <enscript highlight="scheme">(define alist-ref (case-lambda ((alist key) (alist-ref alist key (lambda () (error "Key not found -- ALIST-REF" key)))) ((alist key thunk) (alist-ref alist key thunk eqv?)) ((alist key thunk =) (let ((value (assoc key alist =))) (if value (cdr value) (thunk)))))) </enscript> === {{alist-ref/default}} <procedure>(alist-ref/default alist key default) → object</procedure> <procedure>(alist-ref/default alist key default =) → object</procedure> Return a value associated with its key or {{default}}. ; {{alist}} : The alist to search in ; {{key}} : The key whose value to return ; {{default}} : The default to return when association doesn't exist ; {{=}} : The equality predicate to apply to keys <enscript highlight="scheme">(define alist-ref/default (case-lambda ((alist key default) (alist-ref alist key (lambda () default))) ((alist key default =) (alist-ref alist key (lambda () default) =)))) </enscript> === {{alist-size}} <procedure>(alist-size alist) → integer</procedure> Calculate size of alist. ; {{alist}} : The alist whose size to calculate <enscript highlight="scheme">(define alist-size length) </enscript> === {{alist-fold}} <procedure>(alist-fold alist f init) → object</procedure> Fold an alist; whose {{f}} takes key, value, accumulatum. ; {{alist}} : The alist to fold ; {{f}} : The function to apply to key, value, accumulatum ; {{init}} : The seed of the fold <enscript highlight="scheme">(define (alist-fold alist f init) (fold (lambda (association accumulatum) (match association ((key . value) (f key value accumulatum)))) init alist)) </enscript> === {{alist-set}} <procedure>(alist-set alist key value) → alist</procedure> Non-destructively associate a key and value in the alist. ; {{alist}} : Alist in which to set ; {{key}} : The key to set ; {{value}} : The value to associate with key <enscript highlight="scheme">(define (alist-set alist key value) (alist-cons key value alist)) </enscript> === About this egg ==== Author [[/users/klutometis|Peter Danenberg]] ==== Repository [[https://github.com/klutometis/alist-lib]] ==== License BSD ==== Dependencies * [[hahn]] * [[matchable]] * [[setup-helper]] ==== Versions ; [[https://github.com/klutometis/alist-lib/releases/tag/0.1|0.1]] : Version 0.1 ; [[https://github.com/klutometis/alist-lib/releases/tag/0.1.1|0.1.1]] : Version 0.1.1 ; [[https://github.com/klutometis/alist-lib/releases/tag/0.1.2|0.1.2]] : Meta fixes ; [[https://github.com/klutometis/alist-lib/releases/tag/0.1.3|0.1.3]] : More meta ; [[https://github.com/klutometis/alist-lib/releases/tag/0.1.4|0.1.4]] : Housekeeping ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.1|0.2.1]] : Change to BSD. ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.2|0.2.2]] : Remove debug ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.3|0.2.3]] : Add docs. ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.4|0.2.4]] : Failure condition ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.5|0.2.5]] : With a note about cock-utils ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.6|0.2.6]] : Add test-exit. ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.7|0.2.7]] : alist-set! should work on empty lists. ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.8|0.2.8]] : Remove the dependency on setup-helper-cock. ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.9|0.2.9]] : Remove the dependency on debug. ; [[https://github.com/klutometis/alist-lib/releases/tag/0.2.10|0.2.10]] : Use hahn. ==== Colophon Documented by [[/egg/hahn|hahn]].
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 7 to 20?