2.2 Lists
Beyond the R5RS procedures pair?, cons, car, cdr, set-car!, set-cdr!, caar and cadr through cdddar and cddddr, null?, list?, list, length, append, reverse, list-tail, list-ref, memq, memv, member, assq, assv and assoc we have the following built into gerbil core.
2.2.1 make-list
(make-list len [val = #f]) -> list
len := fixnum
val := any value
Creates a new list of length len, with initial value of val.
2.2.2 cons*
(cons* x y ... tail) -> list
x := any
y := any
tail := list
Conses x, y, … to tail. This is equivalent to (cons x (cons y ... (cons ... tail))).
2.2.3 foldl
(foldl f iv . lsts) -> any
f := procedure
iv := any
lsts := lists
Left fold.
2.2.4 foldr
(foldr f iv . lsts) -> any
f := procedure
iv := any
lsts := lists
Right fold.
2.2.5 andmap
(andmap f . lsts) -> boolean
f := procedure
lsts := lists
Boolean and fold.
2.2.6 ormap
(ormap f . lsts) -> any
f := procedure
lsts := lists
Boolean or fold.
2.2.7 filter
(filter f lst) -> list
f := procedure
lst := list
Returns a new list including only elements x for which (f x) is true.
2.2.8 filter-map
(filter-map f . lsts) -> list
f := procedure
lsts := lists
Filter and map; returns a new list including the true results of (f x y ...),
where x, y, … are the elements of each list in lsts.
2.2.9 iota
(iota count [start = 0] [step = 1]) -> list
count := fixnum; elements in the list
start,step := number
Returns a list of count elements, iterating from start and adding step on each iteration.
2.2.10 last-pair
(last-pair obj) -> pair
obj := pair or
Returns the last pair in the tail of obj; ie the tail pair of a (possibly improper) list.
2.2.11 last
(last obj) -> any
obj := pair
Returns the car of the last pair of obj. This is equivalent to (car (last-pair obj)).
2.2.12 assgetq
(assgetq key alist [default = #f]) -> any
key := any
alist := associative list
Returns the value associated with key in alist, using eq? for
the key comparison. If the key is not found, then if default is a
procedure it is applied on the key. Otherwise returns default.
2.2.13 assgetv
(assgetv key alist [default = #f]) -> any
key := any
alist := associative list
Like assgetq, but uses eqv? for the key comparison.
2.2.14 assget
(assget key alist [default = #f]) -> any
key := any
alist := associative list
Like assgetq, but uses equal? for the key comparison.
2.2.15 pgetq
(pgetq key plist [default = #f]) -> any
key := any
plist := property list
Like assgetq, but for plists.
2.2.16 pgetv
(pgetv key plist [default = #f]) -> any
key := any
plist := property list
Like assgetv, but for plists.
2.2.17 pget
(pget key plist [default = #f]) -> any
key := any
plist := property list
Like assget, but for plists.
2.2.18 find
(find pred lst) -> any
pred := procedure
lst := list
Returns the first element in lst that satisfies pred.
2.2.19 memf
(memf pred lst) -> pair | #f
pred := procedure
lst := list
Generalization of member; returns the first pair in lst whose car satisfies pred.
2.2.20 remove1
(remove1 el lst) -> list
el := any
lst := list
Returns lst removing the first element x that satisfies (equal? el x).
2.2.21 remv
(remv el lst) -> list
el := any
lst := list
Apply remove1 using eqv? as the comparator.
2.2.22 remq
(remq el lst) -> list
el := any
lst := list
Apply remove1 using eq? as the comparator.
2.2.23 remf
(remf pred lst) -> list
pred := procedure
lst := list
Like remove1, but removes the first element x that satisfies (pred x)