2.6 list-utils
This module contains functions that operate on list structures.
(require sicm/general/list-utils) | package: rktsicm |
2.6.1 list sections
procedure
(except-last-pair lst) → list?
lst : pair?
procedure
(split-list lst pred? receiver) → any/c
lst : list? pred? : predicate/c receiver : (-> any/c any/c any/c)
(let-values ([(yes no) (partition pred? lst)]) (receiver yes no))
procedure
(delete-nth lst n) → list?
lst : list? n : integer?
2.6.2 substitution
procedure
(substitute-multiple expression substitutions) → any/c expression : any/c substitutions : (listof (list/c any/c any/c))
2.6.3 Count and search
procedure
(count-elements pred? lst) → integer?
pred? : predicate/c lst : list?
procedure
(countsymbols expression) → integer?
expression : any/c
procedure
(find-first pred? lst) → any/c
pred? : predicate/c lst : list?
procedure
(list-index-of elmnt lst) → (or/c #f integer?)
elmnt : any/c lst : list?
2.6.4 map and fold
procedure
combine : (-> any/c any/c any/c) def : any/c lst : list?
procedure
(reduce-left combine def lst) → any/c
combine : (-> any/c any/c any/c) def : any/c lst : list?
procedure
(reduce-right combine def lst) → any/c
combine : (-> any/c any/c any/c) def : any/c lst : list?
> (reduce (λ (a b) `(fct ,a ,b)) 'nil '(1)) 1
> (reduce-left (λ (a b) `(fct ,a ,b)) 'nil '(1 2 3)) '(fct (fct 1 2) 3)
> (reduce-right (λ (a b) `(fct ,a ,b)) 'nil '(1 2 3)) '(fct 1 (fct 2 3))
procedure
((list:elementwise fct) lists ...) → list?
fct : procedure? lists : list?
procedure
(map&reduce fct combine init lsts ...) → an
fct : procedure? combine : (-> any/c any/c any/c) init : any/c lsts : list?
2.6.5 combinations of 2 elements
procedure
(map-distinct-pairs fct lst) → list?
fct : (-> any/c any/c any/c) lst : list?
procedure
(for-each-distinct-pair fct lst) → void?
fct : (-> any/c any/c any/c) lst : list?
(map (λ (p) (f (car p) (cdr p))) (distinct-pairs lst))
2.6.6 set operations on list
procedure
(lset-adjoin is-equal? e set1) → list?
is-equal? : (-> any/c any/c any/c) e : any/c set1 : list?
procedure
(lset-union is-equal? set1 set2) → list?
is-equal? : (-> any/c any/c any/c) set1 : list? set2 : list?
procedure
(lset-difference is-equal? set1 set2) → list?
is-equal? : (-> any/c any/c any/c) set1 : list? set2 : list?
procedure
(lset-intersection is-equal? set1 set2) → list?
is-equal? : (-> any/c any/c any/c) set1 : list? set2 : list?
2.6.7 other
procedure
((fringe-smaller-than? n) expression) → (or/c #f integer?)
n : integer? expression : any/c
procedure
(list-transpose lsts) → (listof list?)
lsts : (listof list?)
procedure
(cons-if-necessary a b c) → (cons/c any/c any/c)
a : any/c b : any/c c : (cons/c any/c any/c)
procedure
(variable<? a b) → boolean?
a : symbol? b : symbol?