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

9.24.2 Uvector conversion operations

Function: TAGvector->list vec &optional start end
[SRFI-4+] Converts TAGvector vec to a list. If start and/or end are given, they limit the range of vec to be extracted.

Note that the generic function coerce-to can be used as well, if you import gauche.collection.
 
(u32vector->list '#u32(9 2 5)) => (9 2 5)

(use gauche.collection)
(coerce-to <list> '#u32(9 2 5)) => (9 2 5)

Function: TAGvector->vector vec &optional start end
Converts TAGvector vec to a vector. If start and/or end are given, they limit the range of vec to be copied.

Note that the generic function coerce-to can be used as well, if you import gauche.collection.
 
(f32vector->vector '#f32(9.3 2.2 5.5))   => #(9.3 2.2 5.5)
(f32vector->vector '#f32(9.3 2.2 5.5) 2) => #(5.5)

(use gauche.collection)
(coerce-to <vector> '#f32(9.3 2.2 5.5)) => #(9.3 2.2 5.5)

Function: list->TAGvector list &optional clamp
[SRFI-4+] Converts a list list to a TAGvector. Optional argument clamp specifies the behavior when the element of list is out of the valid range.

Note that the generic function coerce-to can be used as well, if you import gauche.collection.
 
(list->s64vector '(9 2 5)) => #s64(9 2 5)

(use gauche.collection)
(coerce-to <s64vector> '(9 2 5)) => #s64(9 2 5)

Function: vector->TAGvector vec &optional start end clamp
Converts a vector vec to a TAGvector. If start and/or end are given, they limit the range of vec to be copied. Optional argument clamp specifies the behavior when the element of vec is out of the valid range.

Note that the generic function coerce-to can be used as well, if you import gauche.collection.
 
(vector->f64vector '#(3.1 5.4 3.2)) => #f64(3.1 5.4 3.2)

(use gauche.collection)
(coerce-to <f64vector> '#(3.1 5.4 3.2)) => #f64(3.1 5.4 3.2)

Function: string->s8vector string &optional start end
Function: string->u8vector string &optional start end
Returns an s8vector or u8vector whose byte sequence is the same as the internal representation of the given string. Optional range arguments start and end specifies the character position inside string to be converted.

These procedures are useful when you want to access byte sequence of the string randomly.

 
(string->u8vector "abc") => #u8(97 98 99)

Function: s8vector->string vec &optional start end
Function: u8vector->string vec &optional start end
Converts a byte sequence in s8vector or u8vector to a string that has the same byte sequence. Optional range arguments start and end specifies the byte position in vec to be converted.

Note that these procedure may result an incomplete string if vec contains a byte sequence invalid as the internal encoding of the string.

Function: string->s32vector string &optional start end
Function: string->u32vector string &optional start end
Returns an s32vector or u32vector whose elements are the internal codes of the characters in the string. Optional range arguments start and end specifies the character position inside string to be converted.

These procedures are useful when you want to access the characters in the string randomly.

Function: s32vector->string vec &optional start end
Function: u32vector->string vec &optional start end
Without start and end, these procedures work like this:
 
(lambda (vec) (map-to <string> integer->char vec)))
Optional range arguments start and end limits the range of conversion between them.

Function: uvector-alias uvector-class vec &optional start end
This procedure creates an uvector of class uvector-class that shares the storage of the given uniform vector vec. If optional start and end arugments are given, only the specified range of vec is used for the new vector. Since the storage is shared, modification of the original vector can be seen from the new vector, or vice versa.

The class uvector-class must be either one of the uniform vector class, but is not necessary match the class of the source vector vec. In such case, the new vector looks at the same region of vec's memory, but interpretes it differently. For example, the following code determines whether Gauche is running on big-endian or little-endian machine:

 
(let ((u8v (uvector-alias <u8vector> #u32(1))))
  (if (zero? (u8vector-ref u8v 0))
      'big-endian 
      'little-endian))

If the uvector-class is other than s8vector or u8vector, the region the new vector points has to meet the alignment requirement. You can assume the beginning of the source vector is aligned suitable for any uniform vectors. So, for example, if you're creating u32vector from u8vector, the start and end must be multiple of 4 (or, if they're omitted, the length of the original u8vector must be multiple of 4). An error is signalled when the given parameters doesn't satisfy alignment constraint.


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

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