[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.24.1 Uvector basic operations

Builtin Class: <TAGvector>
A class for TAGvector. It inherits <sequence>.

Reader Syntax: #TAG(n ...)
Denotes a literal homogeneous vector.
 
#s8(3 -2 4)
#u32(4154 88357 2 323)
#f32(3.14 0.554525 -3.342)

Function: TAGvector? obj
[SRFI-4] Returns #t if obj is a TAGvector, #f otherwise.

Function: TAGvector x ...
[SRFI-4] Constructs TAGvector whose elements are numbers x .... The numbers must be exact integer for exact integer vectors, and in the valid range of the vector.
 
(s8vector 1 2 3) => #s8(1 2 3)

Function: make-TAGvector len &optional fill
[SRFI-4] Constructs a TAGvector of length len. The elements are initialized by a number fill. For exact integer vectors, fill must be an exact integer and in the valid range. If fill is omitted, the content of the vector is undefined.
 
(make-u8vector 4 0) => #u8(0 0 0 0)

Function: TAGvector-length vec
[SRFI-4] Returns the length of the TAGvector vec.

Note that the generic function size-of can be used to obtain the length of vec as well, if you import gauche.collection (See section 9.3 gauche.collection - Collection framework).
 
(s16vector-length '#s16(111 222 333)) => 3

(use gauche.collection)
(size-of '#s16(111 222 333)) => 3

Function: TAGvector-ref vec k &optional fallback
[SRFI-4+] Returns the k-th element of TAGvector vec.

If the index k is out of the valid range, an error is signalled unless an optional argument fallback is given; in that case, fallback is returned.

Note that the generic function ref can be used as well, if you import gauche.collection.

 
(u16vector-ref '#u16(111 222 333) 1) => 222

(use gauche.collection)
(ref '#u16(111 222 333) 1) => 222

Function: TAGvector-set! vec k n &optional clamp
[SRFI-4+] Sets a number n to the k-th element of TAGvector vec. Optional clamp argument specifies the behavior when n is out of valid range. Default is to signal an error.

Note that the setter of the generic function ref can be used as well, if you import gauche.collection.
 
(let ((v (s32vector -439 852 8933)))
  (s32vector-set! v 1 4)
  v)
 => #s32vector(-439 4 8933)

(use gauche.collection)
(let ((v (s32vector -439 852 8933)))
  (set! (ref v 1) 4)
  v)
 => #s32vector(-439 4 8933)

Function: TAGvector-copy vec &optional start end
Copies the srfi-4 vector vec. If start and/or end are given, they limit the range of vec to be copied.

 
(u8vector-copy '#u8(1 2 3 4))     => #u8(1 2 3 4)
(u8vector-copy '#u8(1 2 3 4) 2)   => #u8(3 4)
(u8vector-copy '#u8(1 2 3 4) 1 3) => #u8(2 3)

Function: TAGvector-copy! dstvec srcvec

Using collection and sequence framework, you can perform various operations on the homogeneous vectors.

 
(use gauche.collection)
(use gauche.sequence)

(fold + 0 '#s32(1 2 3 4)) => 10

(map-to <f32vector> * '#f32(3.2 1.1 4.3) '#f32(-4.3 2.2 9.4))
  => #f32(-13.760001 2.420000 40.420002)

(subseq #u32(1 4 3 4 5) 2 4) => #u32(3 4)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html