From b25291180db6271b3fff46c3b5d097dfdfb48c5a Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Thu, 16 Jun 2005 17:15:19 +0000 Subject: [PATCH] Implement GUARANTEE-VECTOR-OF-TYPE, VECTOR-OF-UNIQUE-SYMBOLS?, and GUARANTEE-VECTOR-OF-UNIQUE-SYMBOLS. --- v7/src/runtime/runtime.pkg | 5 ++++- v7/src/runtime/vector.scm | 42 +++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg index 6d6d930a3..e593c04a8 100644 --- a/v7/src/runtime/runtime.pkg +++ b/v7/src/runtime/runtime.pkg @@ -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! diff --git a/v7/src/runtime/vector.scm b/v7/src/runtime/vector.scm index 2cae8833d..4e304d4e9 100644 --- a/v7/src/runtime/vector.scm +++ b/v7/src/runtime/vector.scm @@ -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)))))))) (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 -- 2.25.1