Next: , Previous: , Up: lists   [Index]


23.9 Filtering and partitioning

Function: filter! pred ell

Return all the elements of ell that satisfy the predicate pred. The list is not disordered: Elements that appear in the result list occur in the same order as they occur in ell. The returned list may share a common tail with ell. The dynamic order in which the various applications of pred are made is not specified.

(filter! even? '(0 7 8 8 43 -4))
⇒ (0 8 8 -4)

filter! may alter the cons cells in ell to construct the result lists. Notice that filter is exported by (rnrs lists (6)). (vicare-scheme)List utilities.

Function: partition! pred ell

Partition the elements of ell with predicate pred, and return two values: the list of in–elements and the list of out–elements. The list is not disordered: Elements occur in the result lists in the same order as they occur in ell. The dynamic order in which the various applications of pred are made is not specified. One of the returned lists may share a common tail with ell.

(partition! symbol? '(one 2 3 four five 6))
⇒ (one four five) (2 3 6)

partition! may alter the cons cells in ell to construct the result lists. Notice that partition is exported by (rnrs lists (6)). (vicare-scheme)List utilities.

Function: remove* pred ell
Function: remove*! pred ell

Return ell without the elements that satisfy predicate pred:

(lambda (pred list)
  (filter (lambda (x)
            (not (pred x)))
          list))

The list is not disordered: Elements that appear in the result list occur in the same order as they occur in ell. The returned list may share a common tail with ell. The dynamic order in which the various applications of pred are made is not specified.

(remove* even? '(0 7 8 8 43 -4)) ⇒ (7 43)

remove*! is allowed to alter the cons cells in ell to construct the result lists.

Notice that (rnrs lists (6)) exports remove, which accepts a Scheme object as first argument. (vicare-scheme)List utilities.


Next: , Previous: , Up: lists   [Index]