filter, partition - filter a list
(import (rnrs)) ;R6RS
(import (rnrs lists)) ;R6RS
(filter proc list)
(partition proc list)
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
The elements of the returned lists are in the same order as they
procedure is called in an unspecified order.
should accept one argument and return a single value.
should not mutate
is always called in the same dynamic
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.
(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
These procedures are common in functional code that works with lists.
These procedures are absent from reports other than R6RS. See SRFI-1
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
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
should avoid side-effects, because the order of calls is unspecified.
Markup created by unroff 1.0sc, March 04, 2023.