Next: , Previous: Efficient Accumulation, Up: Top


55 Common List Operations

This module provides an implementation of Common Lisp list functions for Guile. To load it:

     (use-modules (ice-9 common-list))

See SRFI-1, for another list library.

— Scheme Procedure: adjoin e l

Return list L, possibly with element E added if it is not already in L.

— Scheme Procedure: union l1 l2

Return a new list that is the union of L1 and L2. Elements that occur in both lists occur only once in the result list.

— Scheme Procedure: intersection l1 l2

Return a new list that is the intersection of L1 and L2. Only elements that occur in both lists occur in the result list.

— Scheme Procedure: set-difference l1 l2

Return elements from list L1 that are not in list L2.

— Scheme Procedure: reduce-init p init l

Same as `reduce' except it implicitly inserts INIT at the start of L.

— Scheme Procedure: reduce f ridentity lst

reduce is a variant of fold. If lst is (), ridentity is returned. Otherwise, (fold (car lst) (cdr lst)) is returned.

— Scheme Procedure: some pred l [rest...]

PRED is a boolean function of as many arguments as there are list arguments to `some', i.e., L plus any optional arguments. PRED is applied to successive elements of the list arguments in order. As soon as one of these applications returns a true value, return that value. If no application returns a true value, return #f. All the lists should have the same length.

— Scheme Procedure: every pred ls [lists...]

Apply pred across the lists and return a true value if the predicate returns true for every of the list elements(s); return #f otherwise. The true value returned is always the result of the final successful application of pred.

— Scheme Procedure: notany pred [ls...]

Return #t iff every application of PRED to L, etc., returns #f. Analogous to some but returns #t if no application of PRED returns a true value or #f as soon as any one does.

— Scheme Procedure: notevery pred [ls...]

Return #t iff there is an application of PRED to L, etc., that returns #f. Analogous to some but returns #t as soon as an application of PRED returns #f, or #f otherwise.

— Scheme Procedure: count-if pred l

Return the number of elements in L for which (PRED element) returns true.

— Scheme Procedure: find-if pred l

Search for the first element in L for which (PRED element) returns true. If found, return that element, otherwise return #f.

— Scheme Procedure: member-if pred l

Return the first sublist of L for whose car PRED is true.

— Scheme Procedure: remove-if pred l

Remove all elements from L where (PRED element) is true. Return everything that's left.

— Scheme Procedure: remove-if-not pred l

Remove all elements from L where (PRED element) is #f. Return everything that's left.

— Scheme Procedure: delete-if! pred l

Destructive version of `remove-if'.

— Scheme Procedure: delete-if-not! pred l

Destructive version of `remove-if-not'.

— Scheme Procedure: butlast lst n

Return all but the last N elements of LST.

— Scheme Procedure: and? [args...]

Return #t iff all of ARGS are true.

— Scheme Procedure: or? [args...]

Return #t iff any of ARGS is true.

— Scheme Procedure: has-duplicates? lst

Return #t iff 2 members of LST are equal?, else #f.

— Scheme Procedure: pick p l

Apply P to each element of L, returning a list of elts for which P returns a non-#f value.

— Scheme Procedure: pick-mappings p l

Apply P to each element of L, returning a list of the non-#f return values of P.

— Scheme Procedure: uniq l

Return a list containing elements of L, with duplicates removed.