2017-09-29

(sph list one)

additional list processing bindings that depend on libraries that depend on (sph list). to avoid circular dependencies

import name

(sph list one)

exports

group

procedure

signature

a [accessor] ->

list [procedure:{any -> any}] -> ((any:group-key any:group-value ...):group ...)

description

groups entries by unique result values of accessor.

by default accessor is identity and groups equal elements.

returns an association list with one entry for each group with the value as key and related values as value

group-recursively

procedure

signature

a [accessor] ->

((any ...) ...) [procedure] -> list

description

group lists and the elements of groups until no further sub-groups are possible.

example

(group-recursively (list (list 1 2 3) (list 1 2 6) (list 1 3 7) (list 8 9)) first)

-> ((1 (2 3 6) (3 7)) (8 9))

list-ref-random

procedure

signature

a ->

list -> any

description

retrieve a random element of a list. uses the default random-state of (sph random-data) which changes with every interpreter start

list-ref-randomise-cycle

procedure

signature

a ->

list -> procedure:{ -> any}

description

gives a procedure that when called gives the next element from a randomised version of "a"

when the end of the list has been reached, the list is reset to a newly randomised version of "a"

list-replace-from-hashtable

procedure

signature

a ht ->

list rnrs-hashtable -> list

description

replaces elements in list that exist as key in a hashtable with the associated value.

if the value is a list, the element is either removed (empty list) or replaced with multiple elements

randomise

procedure

signature

a ->

list -> list

description

return a new list with the elements of list in random order.

algorithm: connect a random number to each element, re-sort list corresponding to the random numbers.


tags: guile documentation library scheme sph-lib computer sph-list-one