This SRFI is currently in final status. Here is an explanation of each status that a SRFI can hold. To provide input on this SRFI, please send email to
email@example.com. To subscribe to the list, follow these instructions. You can access previous messages via the mailing list archive.
writeprocedures and by the program parser (i.e. programs can contain references to literal homogeneous vectors).
|datatype||type of elements|
|signed exact integer in the range -(2^7) to (2^7)-1|
|unsigned exact integer in the range 0 to (2^8)-1|
|signed exact integer in the range -(2^15) to (2^15)-1|
|unsigned exact integer in the range 0 to (2^16)-1|
|signed exact integer in the range -(2^31) to (2^31)-1|
|unsigned exact integer in the range 0 to (2^32)-1|
|signed exact integer in the range -(2^63) to (2^63)-1|
|unsigned exact integer in the range 0 to (2^64)-1|
|datatype||type of elements|
f64vectors preserve at least as much precision as
f32vectors (see the implementation section for details). A Scheme system that conforms to this SRFI does not have to support all of these homogeneous vector datatypes. However, a Scheme system must support
f64vectors if it supports Scheme inexact reals (of any precision). A Scheme system must support a particular integer vector datatype if the system's exact integer datatype contains all the values that can be stored in such an integer vector. Thus a Scheme system with bignum support must implement all the integer vector datatypes and a Scheme system may only support
u16vectors if it only supports small integers in the range -(2^29) to (2^29)-1 (which would be the case if they are represented as 32 bit fixnums with two bits for tag). Note that it is possible to test which numeric datatypes the Scheme system supports by calling the
#fif the Scheme system does not support inexact reals). Each homogeneous vector datatype has an external representation which is supported by the
writeprocedures and by the program parser. Each datatype also has a set of associated predefined procedures analogous to those available for Scheme's heterogeneous vectors. For each value of
f64}, if the datatype
TAGvectoris supported, then
). For example,
#u8(0 #e1e2 #xff)is an
u8vectorof length 3 containing 0, 100 and 255;
f64vectorof length 1 containing -1.5. Note that the syntax for float vectors conflicts with Standard Scheme which parses
#f32()as 3 objects:
(). For this reason, conformance to this SRFI implies this minor nonconformance to Standard Scheme. This external representation is also available in program source code. For example,
(set! x '#u8(1 2 3))will set
xto the object
#u8(1 2 3). Literal homogeneous vectors must be quoted just like heterogeneous vectors must be. Homogeneous vectors can appear in quasiquotations but must not contain
`(,x #u8(1 2))is legal but
`#u8(1 ,x 2)is not). This restriction is to accomodate the many Scheme systems that use the
readprocedure to parse programs.
(make-TAGvector n [ TAGvalue ])
(TAGvector-ref TAGvect i)
(TAGvector-set! TAGvect i TAGvalue)
objis any Scheme object,
nis a nonnegative exact integer,
iis a nonnegative exact integer less than the length of the vector,
TAGvectis an instance of the
TAGvalueis a number of the type acceptable for elements of the
TAGlistis a proper list of numbers of the type acceptable for elements of the
TAGvectordatatype. It is an error if
TAGvalueis not the same type as the elements of the
TAGvectordatatype (for example if an exact integer is passed to
f64vector). If the fill value is not specified, the content of the vector is unspecified but individual elements of the vector are guaranteed to be in the range of values permitted for that type of vector.
f64vectordatatypes could be represented the same way with 64 bit floating point numbers). A portable implementation of the homogeneous vector predefined procedures can be based on Scheme's heterogeneous vectors. Here is for example an implementation of
s8vectors which is exempt of error checking:
(define s8vector? #f) (define make-s8vector #f) (define s8vector #f) (define s8vector-length #f) (define s8vector-ref #f) (define s8vector-set! #f) (define s8vector->list #f) (define list->s8vector #f) (let ((orig-vector? vector?) (orig-make-vector make-vector) (orig-vector vector) (orig-vector-length vector-length) (orig-vector-ref vector-ref) (orig-vector-set! vector-set!) (orig-vector->list vector->list) (orig-list->vector list->vector) (orig-> >) (orig-eq? eq?) (orig-+ +) (orig-null? null?) (orig-cons cons) (orig-car car) (orig-cdr cdr) (orig-not not) (tag (list 's8))) (set! s8vector? (lambda (obj) (and (orig-vector? obj) (orig-> (orig-vector-length obj) 0) (orig-eq? (orig-vector-ref obj 0) tag)))) (set! make-s8vector (lambda (n . opt-fill) (let ((v (orig-make-vector (orig-+ n 1) (if (orig-null? opt-fill) 123 (orig-car opt-fill))))) (orig-vector-set! v 0 tag) v))) (set! s8vector (lambda s8list (orig-list->vector (orig-cons tag s8list)))) (set! s8vector-length (lambda (s8vect) (orig-+ (orig-vector-length s8vect) -1))) (set! s8vector-ref (lambda (s8vect i) (orig-vector-ref s8vect (orig-+ i 1)))) (set! s8vector-set! (lambda (s8vect i s8value) (orig-vector-set! s8vect (orig-+ i 1) s8value))) (set! s8vector->list (lambda (s8vect) (orig-cdr (orig-vector->list s8vect)))) (set! list->s8vector (lambda (s8list) (orig-list->vector (orig-cons tag s8list)))) (set! vector? (lambda (obj) (and (orig-vector? obj) (orig-not (and (orig-> (orig-vector-length obj) 0) (orig-eq? (orig-vector-ref obj 0) tag)))))))The Scheme system's
writeprocedures and the program parser also need to be extended to handle the homogeneous vector external representations. The implementation is very similar to heterogeneous vectors except that
readand the program parser must recognize the prefixes
#f32, etc. (this can be done by checking if the sharp sign is followed by a character that can start a symbol, and if this is the case, parse a symbol and check if it is
f32, and so on, and in the case of a homogeneous vector prefix, check if the next character is an opening parenthesis).
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.