Implement GUARANTEE-VECTOR-OF-TYPE, VECTOR-OF-UNIQUE-SYMBOLS?, and
authorChris Hanson <org/chris-hanson/cph>
Thu, 16 Jun 2005 17:15:19 +0000 (17:15 +0000)
committerChris Hanson <org/chris-hanson/cph>
Thu, 16 Jun 2005 17:15:19 +0000 (17:15 +0000)
GUARANTEE-VECTOR-OF-UNIQUE-SYMBOLS.

v7/src/runtime/runtime.pkg
v7/src/runtime/vector.scm

index 6d6d930a32bcac26c7f997d4855957f6715ce78e..e593c04a874171ea536cb87bace3cad292515065 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-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
@@ -577,6 +577,8 @@ USA.
          for-each-vector-element
          guarantee-subvector
          guarantee-vector
+         guarantee-vector-of-type
+         guarantee-vector-of-unique-symbols
          list->vector
          make-initialized-vector
          make-vector
@@ -611,6 +613,7 @@ USA.
          vector-map
          vector-move!
          vector-of-type?
+         vector-of-unique-symbols?
          vector-ref
          vector-second
          vector-set!
index 2cae8833d177e040f7059ee35bd2a235d811c91c..4e304d4e9290923a66cf65b7a3bae500db234af0 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-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
 
@@ -152,14 +152,6 @@ USA.
 
 (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)
@@ -251,4 +243,34 @@ USA.
 
 (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