memq, memv, member, memp - list lookup
(import (rnrs)) ;R6RS
(import (rnrs lists)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(memq obj list)
(member obj list)
(memv obj list)
(memp proc list) ;R6RS
(member obj list compare) ;R7RS
These procedures return the first sublist of
satisfies a given condition, where the sublists of lists are
the lists returned by
(list-tail list k)
less than the length of
procedures look for the first occurrence
does not contain an element satisfying the
with the elements of
- memp (R6RS)
to the cars of the sublists of
until it finds one for which
returns a true value.
is always called in the
same dynamic environment as
should accept one argument and return a single value.
should not mutate list.
- member (R7RS)
with the elements of
if given, and
Returns a single value which is either
a tail of
(memq 'a '(a b c))
=> (a b c)
(memq 'b '(a b c))
=> (b c)
(memq 'a '(b c d))
(memq (list 'a) '(b (a) c))
(member (list 'a) '(b (a) c))
=> ((a) c)
(memq 101 '(100 101 102)) => unspecified
(memv 101 '(100 101 102)) => (101 102)
(member "B" '("a" "b" "c") string-ci=?)
=> ("b" "c")
(memp even? '(3 1 4 1 5 9 2 6 5))
=> (4 1 5 9 2 6 5)
These procedures are used to search for an object in a list. It can be
used as a simple way to implement sets and it's commonly used to look
up data in property lists.
R6RS imposes the following responsibly on implementations:
The implementation must check that
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.
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.
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
procedures appear in MacLISP, so they would have been available in the
first Scheme implementation.
LISP 1.5 had a
procedure that returned true of the element was in the list.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Programs should not use the more discriminating
when the object is not comparable with
Markup created by unroff 1.0sc, March 04, 2023.