Next: , Previous: Vectors, Up: Top


19 Bytevectors

A bytevector is an object that contains a sequence of bytes, that is, exact integers between 0 and 255 inclusive. A bytevector has a length that is fixed at creation time, and as many bytes, indexed from 0 to length-1. Compared to vectors, bytevectors use less size for each element.

Bytevectors may be mutable or immutable. If an attempt is made to mutate an immutable bytevector, an error is signaled. Two immutable bytevectors are “eq?” iff they are “equal?”. Two mutable bytevectors are “eq?” if they were created by the same constructor call. Two mutable bytevectors are “equal?” iff they have the same length and have “equal?” bytes in each position. There is only one empty bytevector (that is, a bytevector of length 0) and that bytevector is immutable. The bytevector type is encapsulated.

SOURCE NOTE: The report doesn't currently include bytevectors. They are taken from r7rs scheme.

— Applicative: bytevector? (bytevector? . obje)

The primitive type predicate for type bytevector. bytevector? returns true iff all the objects in objects are of type bytevector.

— Applicative: immutable-bytevector? (immutable-bytevector? objects)
— Applicative: mutable-bytevector? (mutable-bytevector? objects)

The primitive type predicates for types immutable bytevector and mutable bytevector. These return true iff all the objects in objects are of type immutable bytevector or mutable bytevector respectively.

— Applicative: make-bytevector (make-bytevector k [u8])

Applicative make-bytevector constructs and returns a new mutable bytevector of length k. If u8 is specified, then all bytes in the returned bytevector are obj, otherwise the content of the bytevector is unspecified.

— Applicative: bytevector-length (bytevector-length bytevector)

Applicative bytevector-length returns the length of bytevector.

— Applicative: bytevector-ref (bytevector-ref bytevector k)

Applicative bytevector-ref returns the byte of bytevector at position k. If k is out of bounds (i.e. less than 0 or greater or equal than (bytevector-length bytevector)) an error is signaled.

— Applicative: bytevector-set! (bytevector-set! bytevector k u8)

Applicative bytevector-set! replaces the byte with index k in bytevector with byte u8. If k is out of bounds, or bytevector is immutable, an error is signaled. The result returned by bytevector-set! is inert.

— Applicative: bytevector (bytevector . u8s)

Applicative bytevector contructs and return a new mutable bytevector composed of the byte arguments.

— Applicative: bytevector->list (bytevector->list bytevector)
— Applicative: list->bytevector (list->bytevector u8s)

These applicatives convert between bytevectors and lists of bytes. If the list passed to list->bytevector contains an object that isn't a byte, an error is signaled. The objects returned by these applicatives are always mutable.

— Applicative: bytevector-copy (bytevector-copy bytevector)

Applicative bytevector-copy constructs and returns a new mutable bytevector with the same length and bytes as bytevector.

— Applicative: bytevector->vector (bytevector->vector bytevector)
— Applicative: vector->bytevector (vector->bytevector vector)

These applicatives convert between bytevectors and vectors. If a vector containing objects other than bytes (exact integers between 0 and 255 inclusive) is passed to vector->bytevector, an error is signaled. The objects returned by these applicatives are always mutable.

— Applicative: bytevector-copy! (bytevector-copy! bytevector1 bytevector2)

bytevector2 should have a length greater than or equal to that of bytevector1.

Copies the bytes in bytevector1 to the corresponding positions in bytevector2. If bytevector2 is immutable, an error is signaled. The result returned by bytevector-copy! is inert.

— Applicative: bytevector-copy-partial (bytevector-copy-partial bytevector k1 k2)

Both k1 & k2 should be valid indexes in bytevector. Also it should be the case that k1 <= k2.

Applicative bytevector-copy-partial constructs and returns a new mutable bytevector with length k2 - k1, with the bytes from bytevector, starting at index k1 (inclusive) and ending at index k2 (exclusive).

— Applicative: bytevector-copy-partial! (bytevector-copy-partial! bytevector1 k1 k2 bytevector2 k3)

Both k1 & k2-1 should be valid indexes in bytevector1. Also it should be the case that k1 <= k2. Both k3 & k3 + (k2-k1) - 1 should be valid indexes in bytevector2.

Applicative bytevector-copy-partial! copies bytes k1 (inclusive) through k2 (exclusive) from bytevector1 to the k2-k1 positions in bytevector2 starting at k3. If bytevector2 is an immutable bytevector, an error is signaled. The result returned by bytevector-copy-partial! is inert.

— Applicative: bytevector-fill! (bytevector-fill! bytevector u8)

Applicative bytevector-fill! replaces all the bytes in bytevector with byte u8. If bytevector is an immutable bytevector, an error is signaled. The result returned by bytevector-fill! is inert.

— Applicative: bytevector->immutable-bytevector (bytevector->immutable-bytevector bytevector)

Applicative bytevector->immutable-bytevector constructs and returns a new immutable bytevector with the same length and bytes as bytevector.