Next: , Previous: , Up: API Reference   [Contents][Index]


3.4 Lists

Grip procedures to process lists. The module is loaded by entering the following:

(use-modules (grip list))

Procedures

list-pos
list-insert
list-replace-all
interleave
flatten

Procedures

Procedure: list-pos item lst [pred eq?]

Returns the index of the first element in lst which statisfies (pred element item). Otherwise, it returns #f.

Procedure: list-insert item lst pos

Returns a list.

Inserts item at the beginning of lst if pos is inferior or equal to zero, at the given position if pos is inferior to the length of lst, and at the end of lst if pos is equal or superior to the length of lst.

Procedure: list-replace-all old new lst [pred eq?]

Returns a list.

All elements in lst that satisfies (pred element old) are replaced by new.

Procedure: interleave l1 l2 l3 …

Returns a list.

The result is the concatenation of the tuples composed of one element of l1 l2 l3 … taken at the same index. The first index is zero, the last idex is (- n 1), where n is the length of the shortest list.

Procedure: flatten lst

Returns a ‘non-nested’ list obtained by removing all ‘nested structure’ from lst, while retaining all of its elements, hence flattening lst.

For example:

(flatten '(1 2 (3) (4 (5 (6 (7 8) 9) (10 11))) 12))
-|
$4 = (1 2 3 4 5 6 7 8 9 10 11 12)

Next: , Previous: , Up: API Reference   [Contents][Index]