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.

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.

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))).

foldl

(foldl f iv . lsts) -> any

  f    := procedure
  iv   := any
  lsts := lists

Left fold.

foldr

(foldr f iv . lsts) -> any

  f    := procedure
  iv   := any
  lsts := lists

Right fold.

andmap

(andmap f . lsts) -> boolean

  f    := procedure
  lsts := lists

Boolean and fold.

ormap

(ormap f . lsts) -> any

  f    := procedure
  lsts := lists

Boolean or fold.

filter

(filter f lst) -> list

  f   := procedure
  lst := list

Returns a new list including only elements x for which (f x) is true.

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.

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.

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.

last

(last obj) -> any

  obj := pair

Returns the car of the last pair of obj. This is equivalent to (car (last-pair obj)).

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.

assgetv

(assgetv key alist [default = #f]) -> any

  key   := any
  alist := associative list

Like assgetq, but uses eqv? for the key comparison.

assget

(assget key alist [default = #f]) -> any

  key   := any
  alist := associative list

Like assgetq, but uses equal? for the key comparison.

pgetq

(pgetq key plist [default = #f]) -> any

  key   := any
  plist := property list

Like assgetq, but for plists.

pgetv

(pgetv key plist [default = #f]) -> any

  key   := any
  plist := property list

Like assgetv, but for plists.

pget

(pget key plist [default = #f]) -> any

  key   := any
  plist := property list

Like assget, but for plists.

find

(find pred lst) -> any

  pred := procedure
  lst  := list

Returns the first element in lst that satisfies pred.

memf

(memf pred lst) -> pair | #f

  pred := procedure
  lst  := list

Generalization of member; returns the first pair in lst whose car satisfies pred.

remove1

(remove1 el lst) -> list

  el  := any
  lst := list

Returns lst removing the first element x that satisfies (equal? el x).

remv

(remv el lst) -> list

  el  := any
  lst := list

Apply remove1 using eqv? as the comparator.

remq

(remq el lst) -> list

  el  := any
  lst := list

Apply remove1 using eq? as the comparator.

remf

(remf pred lst) -> list

  pred := procedure
  lst  := list

Like remove1, but removes the first element x that satisfies (pred x)