This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see SearchCowan in WG2's repo for R7RS-large.

Search­Cowan

cowan
2012-12-24 09:14:52
1history
source

This is a small WG2 proposal for Scheme procedures corresponding to the Common Lisp function SEARCH.

Procedures

(vector-contains test vector1 vector2 [ [ [ [ start1 ] end1 ] start2 ] end2 ])

(vector-contains-right test vector1 vector2 [ [ [ [ start1 ] end1 ] start2 ] end2 ])

Searches vector2 from start2 to end2 for the leftmost (for vector-contains) or the rightmost (for vector-contains-right) sub-vector whose elements are the same (in the sense of test) as those of vector1 from start1 to end1. Test is a predicate of two arguments. The usual default rules and restrictions apply to the start and end arguments.

Returns an index into vector2 if the search succeeds, or #f if it fails.

The order in which the search is made is unspecified; in particular, vector-rsearch may search from left to right rather than right to left. The number of times that test is invoked is also unspecified.

(list-contains test list1 list2 [ [ [ [ start1 ] end1 ] start2 ] end2 ])

Analogous to vector-search, but applicable to lists.

(string-contains test string1 string2 [ [ [ [ start1 ] end1 ] start2 ] end2 ])

(string-contains-right test string1 string2 [ [ [ [ start1 ] end1 ] start2 ] end2 ])

Analogous to vector-contains and vector-contains-right, but applicable to strings. String-contains is already part of SRFI 13.

Issues

SRFI 13's string-contains(-ci) allows only the fixed tests char=? and char-ci=?. Here are some reasonable ways to resolve the conflict: