vector-procs.scm 764 B

1234567891011121314151617181920212223
  1. (library (lib vector-procs)
  2. (export vector-contains?)
  3. (import
  4. (except (rnrs base) let-values map error vector-map)
  5. (only (guile) lambda* λ)
  6. ;; srfi-43 for vector procs
  7. (srfi srfi-43)))
  8. (define vector-contains?
  9. (λ (vec searched equality-proc)
  10. "Look in a vector for an element, that is equal to the
  11. given element under the given equality-proc. Note, that this
  12. procedure does not take advantage of any optimization for
  13. sorted vectors or similar things. It simply searches from
  14. first to last element of the vector sequentially."
  15. (let ([max-ind (vector-length vec)])
  16. (let next ([ind 0])
  17. (cond
  18. [(= ind max-ind) #f]
  19. [(equality-proc (vector-ref vec ind) searched) #t]
  20. [else (next (+ ind 1))])))))