filter, partition - filter a list

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs lists))               ;R6RS

SYNOPSIS

(filter proc list)
(partition proc list)

DESCRIPTION

The filter procedure returns a list containing the elements in list for which proc returned a true value.

The partition procedure is exactly like filter, except it also returns a second list containing the elements that were eliminated by proc.

The elements of the returned lists are in the same order as they appear in list. The proc procedure is called in an unspecified order.

Proc should accept one argument and return a single value. Proc should not mutate list. Proc is always called in the same dynamic environment as filter or partition itself.

RETURN VALUES

The filter procedure returns a single list. The partition procedure returns two list.

If this procedure returns twice (e.g. by use of call/cc) then the lists returned earlier are not mutated.

EXAMPLES

(filter even? '(3 1 4 1 5 9 2 6))
           => (4 2 6)
(partition even? '(3 1 4 1 5 9 2 6))
           => (4 2 6) (3 1 1 5 9) ; two values

APPLICATION USAGE

These procedures are common in functional code that works with lists.

COMPATIBILITY

These procedures are absent from reports other than R6RS. See SRFI-1 for alternatives.

ERRORS

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain. Examples of this are a procedure proc that does not accept and return a single value, or a list which is circular or improper.

SEE ALSO

map(3scm), remp(3scm)

STANDARDS

R6RS

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.

BUGS

The procedure proc should avoid side-effects, because the order of calls is unspecified.


Markup created by unroff 1.0sc,    March 04, 2023.