#| -*-Scheme-*-
-$Id: runtime.pkg,v 14.557 2005/06/14 18:17:34 cph Exp $
+$Id: runtime.pkg,v 14.558 2005/06/16 17:15:15 cph Exp $
Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology
Copyright 1994,1995,1996,1997,1998,1999 Massachusetts Institute of Technology
for-each-vector-element
guarantee-subvector
guarantee-vector
+ guarantee-vector-of-type
+ guarantee-vector-of-unique-symbols
list->vector
make-initialized-vector
make-vector
vector-map
vector-move!
vector-of-type?
+ vector-of-unique-symbols?
vector-ref
vector-second
vector-set!
#| -*-Scheme-*-
-$Id: vector.scm,v 14.24 2005/06/14 18:17:38 cph Exp $
+$Id: vector.scm,v 14.25 2005/06/16 17:15:19 cph Exp $
Copyright (c) 1988-2002 Massachusetts Institute of Technology
(define (for-each-vector-element vector procedure)
(vector-for-each procedure vector))
-
-(define (vector-of-type? vector predicate)
- (and (vector? vector)
- (let ((n (vector-length vector)))
- (let loop ((i 0))
- (or (fix:= i n)
- (and (predicate (vector-ref vector i))
- (loop (fix:+ i 1))))))))
\f
(define (subvector-find-next-element vector start end item)
(guarantee-subvector vector start end 'SUBVECTOR-FIND-NEXT-ELEMENT)
(define (vector-uniform? vector)
(guarantee-vector vector 'VECTOR-UNIFORM?)
- (subvector-uniform? vector 0 (vector-length vector)))
\ No newline at end of file
+ (subvector-uniform? vector 0 (vector-length vector)))
+
+(define (vector-of-type? object predicate)
+ (and (vector? object)
+ (let ((n (vector-length object)))
+ (let loop ((i 0))
+ (if (fix:< i n)
+ (and (predicate (vector-ref object i))
+ (loop (fix:+ i 1)))
+ #t)))))
+
+(define (guarantee-vector-of-type object predicate description caller)
+ (if (not (vector-of-type? object predicate))
+ (error:wrong-type-argument object description caller)))
+
+(define (vector-of-unique-symbols? object)
+ (and (vector? object)
+ (let ((n (vector-length object)))
+ (let loop ((i 0))
+ (if (fix:< i n)
+ (let ((elt (vector-ref object i)))
+ (and (symbol? elt)
+ (let find-dup ((i (fix:+ i 1)))
+ (if (fix:< i n)
+ (and (not (eq? (vector-ref object i) elt))
+ (find-dup (fix:+ i 1)))
+ #t))
+ (loop (fix:+ i 1))))
+ #t)))))
+
+(define-guarantee vector-of-unique-symbols "vector of unique symbols")
\ No newline at end of file