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 SearchMismatchCowan in WG2's repo for R7RS-large.

Search­Mismatch­Cowan

cowan
2012-11-19 14:33:29
1history
source

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

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

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

Searches vector2 from start2 to end2 for the leftmost (for vector-search) or the rightmost (for vector-rsearch) 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-search test list1 list2 [ [ [ [ start1 ] end1 ] start2 ] end2 ])

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

Analogous to vector-search and vector-rsearch, but applicable to lists.

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

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

Analogous to vector-search and vector-rsearch, but applicable to strings.

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

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

Compares vector1 from start1 to end1 element-wise with vector2 from start2 to end2. If there are the same number of elements, and they are the same in the sense of test, then returns #f, otherwise returns the leftmost (for vector-mismatch) or the rightmost (for vector-rmismatch) position within vector1 at which they fail to match. Test is a predicate of two arguments. The usual default rules and restrictions apply to the start and end arguments.

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

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

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

Analogous to vector-mismatch and vector-rmismatch, but applicable to lists.

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

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

Analogous to vector-mismatch and vector-rmismatch, but applicable to strings.