2021-02-05

(sph alist)

association list processing

part of sph-lib

module name

(sph alist)

exported bindings

procedure: alist key/value ... ->
key/value ... -> alist
create an association list from the given arguments,
mapping each argument alternatingly to key and value.
(alist (quote a) 1 \"b\" 2 (quote c) 3)
procedure: alist->list a ->
list -> list
convert an alist to a list that contains every alist key and value alternatingly.
the inverse of list->alist.
example: ((a . 1) (b . 2)) -> (a 1 b 2)
syntax: alist-bind alist (key ...) body ...
could allow for custom variable names for key values as an extension
syntax: alist-bind-and* alist (key ...) body ...
alist values are bound in order of keys, and false is returned if any key value is false
procedure: alist-cond a alist ->
any ((procedure:{any -> any/false} alist-tail ...) ...) -> alist-tail/false
like a cond expression but with an alist for the test conditions where the tail of the alist is returned for which the test suceeds.
procedure: alist-contains a key ->
procedure: alist-containsq a key ->
procedure: alist-containsv a key ->
procedure: alist-delete key alist [k=] ->
procedure: alist-delete-multiple a keys ... ->
syntax: alist-keys alist
get all keys of an alist as a list
procedure: alist-keys-map proc a ->
procedure: alist-map proc a ->
procedure:{key value -> any} list -> list
procedure: alist-merge a b ->
list list -> list
create a new alist with the associations of both alists, preferring entries of
procedure: alist-prepend a b c ->
syntax: alist-q key/value ...
only the keys are quoted
syntax: alist-ref a k d
syntax: alist-ref-q a k d
procedure: alist-select alist keys ->
list list -> list
procedure: alist-select-apply a keys proc ->
list list procedure:{any:key-value ...} -> any
applies proc with all alist values for keys in order
syntax: alist-select-q a key ...
syntax: alist-select-q-apply a (key ...) proc
procedure: alist-set a key value ->
list any any -> list
add or update an entry in an association list
procedure: alist-set! a b c ->
procedure: alist-set-multiple a key/value ... ->
list [any:key any:value] ...
update or add values in alist for specific keys.
key and value are specified alternatingly
syntax: alist-set-multiple-q a key/value ...
list [any:unquoted-key any:value] ...
procedure: alist-update a b ->
list list -> list
update existing entries of a with corresponding entries of b
procedure: alist-update-multiple a key/value ... ->
list [any:key any:value] ...
update values in alist for specific keys.
key and value are specified alternatingly
syntax: alist-update-multiple-q a key/value ...
list [any:unquoted-key any:value] ...
syntax: alist-values alist
procedure: alist? a ->
any -> boolean
procedure: alistq-ref a b ->
procedure: alistq-select alist keys ->
syntax: alists-ref a k
procedure: alists-ref-p a keys ->
like alists-ref but as a procedure that accepts a list for keys
syntax: alists-ref-q a k
syntax: alists-set! a k v
procedure: alistv-ref a b ->
procedure: alistv-select alist keys ->
syntax: bindings->alist identifier ...
create an alist with keys named like the identifiers and values from identified variables
example: (let ((a 1) (b 2)) (bindings->alist a b)) -> (((quote a) . 1) ((quote b) . 2))
procedure: keyword-list->alist+keyless a ->
list -> (list:alist any ...)
parses a list with arguments similar to lambda* arguments. it creates alist entries for keywords (#: notation, #:example) and subsequently following values (#:example 3 other ...).
if no value follows: (#:example . #t).
all values that do not directly follow a keyword are collected in the tail of the result
procedure: list->alist lis ->
-> alist
create an association list from the given arguments,
mapping each list element alternating to a key and value.
procedure: list->group-alist lis [accessor] ->
group elements in list by an attribute of its elements.
this is the equality of (accessor list-element) between elements and stored under (accessor list-element) as keys.
example
(list->group-alist (1 2 2 3) identity) -> ((1 . (1)) (2 . (2 2)) (3 . (3)))
(list->group-alist ((1 3) (2 5) (2 6)) first) -> ((1 . 3) (2 . (5 6)))
procedure: list-alist? a ->
list -> boolean
return #t if list is an association list, #f otherwise. works only on lists
procedure: set-alist-bindings! alist ->
for each alist part, set a variable named like alist-part-key to alist-part-value
variable: sph-alist-description