find(3scm) Scheme Programmer's Manual find(3scm)

find - search a list for an element satisfying a predicate

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

(find proc list)

The find procedure applies proc to the elements of list in order. If proc returns a true value for an element, find immediately returns that element. If proc returns #f for all elements of the list, find returns #f.

Proc is always called in the same dynamic environment as find itself.

Proc should accept one argument and return a single value. Proc should not mutate list.

The implementation must check that list is a chain of pairs up to the found element, or that it is indeed a list if no element is found. It should not check that it is a chain of pairs beyond the found element. The implementation must check the restrictions on proc to the extent performed by applying it as described. An implementation may check whether proc is an appropriate argument before applying it.

Returns a single value which is either one of the elements of list or #f.

(find even? '(3 1 4 1 5 9))  =>  4
(find even? '(3 1 5 1 5 9))  =>  #f

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.

member(3scm)

R6RS, SRFI-1

This procedure is new in R6RS, which got it from SRFI-1.

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

2022-03-27