Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

SRFI-63

Homogeneous and Heterogeneous Arrays

  1. Outdated egg!
  2. SRFI-63
  3. Documentation
    1. Homogeneous Array Types
    2. Procedures
  4. Author
  5. Version history
  6. License

Documentation

This SRFI, which is to supersede SRFI-47, "Array",

For the complete SRFI-63 document see SRFI 63.

Note: this extension is compiled in case-sensitive mode, so array prototype identifiers like A:fixZ64b must be spelled using the correct case.

Homogeneous Array Types

All implementations must support Scheme strings as rank 1 character arrays. This requirement mandates that Scheme strings be valid arguments to array procedures; their stored representations may be different from other character arrays.

Although an implementation is required to define all the prototype functions, it is not required to support all or even any of the homogeneous numeric arrays. It is assumed that no uniform numeric types have larger precision than the Scheme implementation supports as numbers.

prototype procedure exactness element type
vector any
A:floC128b inexact 128 bit binary flonum complex
A:floC64b inexact 64 bit binary flonum complex
A:floC32b inexact 32 bit binary flonum complex
A:floC16b inexact 16 bit binary flonum complex
A:floR128b inexact 128 bit binary flonum real
A:floR64b inexact 64 bit binary flonum real
A:floR32b inexact 32 bit binary flonum real
A:floR16b inexact 16 bit binary flonum real
A:floQ128d exact 128 bit decimal flonum rational
A:floQ64d exact 64 bit decimal flonum rational
A:floQ32d exact 32 bit decimal flonum rational
A:fixZ64b exact 64 bit binary fixnum
A:fixZ32b exact 32 bit binary fixnum
A:fixZ16b exact 16 bit binary fixnum
A:fixZ8b exact 8 bit binary fixnum
A:fixN64b exact 64 bit nonnegative binary fixnum
A:fixN32b exact 32 bit nonnegative binary fixnum
A:fixN16b exact 16 bit nonnegative binary fixnum
A:fixN8b exact 8 bit nonnegative binary fixnum
A:bool boolean
string char

Procedures

[procedure] (array? obj)

Returns #t if the obj is an array, and #f if not.

Note: Arrays are not disjoint from other Scheme types. Vectors and strings also satisfy array?. A disjoint array predicate can be written as follows:

(define (strict-array? obj)
  (and (array? obj) (not (string? obj)) (not (vector? obj))))
[procedure] (array-rank obj)

Returns the number of dimensions of obj. If obj is not an array, 0 is returned.

[procedure] (array-dimensions obj)

Returns a list of dimensions.

(array-dimensions (make-array '#() 3 5))
   => (3 5)
[procedure] (make-array prototype k1 ...)

Creates and returns an array of type prototype with dimensions k1, ... and filled with elements from prototype. prototype must be an array, vector, or string. The implementation-dependent type of the returned array will be the same as the type of prototype; except if that would be a vector or string with rank not equal to one, in which case some variety of array will be returned.

If prototype has no elements, then the initial contents of the returned array are unspecified. Otherwise, the returned array will be filled with the element at the origin of prototype.

[procedure] (make-shared-array array mapper k1 ...)

make-shared-array can be used to create shared subarrays of other arrays. The mapper is a function that translates coordinates in the new array into coordinates in the old array. A mapper must be linear, and its range must stay within the bounds of the old array, but it can be otherwise arbitrary. A simple example:

(define fred (make-array '#(#f) 8 8))
(define freds-diagonal
  (make-shared-array fred (lambda (i) (list i i)) 8))
(array-set! freds-diagonal 'foo 3)
(array-ref fred 3 3)
   => FOO
(define freds-center
  (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
                     2 2))
(array-ref freds-center 0 0)
   => FOO
[procedure] (list->array rank proto list)

list must be a rank-nested list consisting of all the elements, in row-major order, of the array to be created.

list->array returns an array of rank rank and type proto consisting of all the elements, in row-major order, of list. When rank is 0, list is the lone array element; not necessarily a list.

(list->array 2 '#() '((1 2) (3 4)))
                => #2A((1 2) (3 4))
(list->array 0 '#() 3)
                => #0A 3
[procedure] (array->list array)

Returns a rank-nested list consisting of all the elements, in row-major order, of array. In the case of a rank-0 array, array->list returns the single element.

(array->list #2A((ho ho ho) (ho oh oh)))
                => ((ho ho ho) (ho oh oh))
(array->list #0A ho)
                => ho
[procedure] (vector->array vect proto dim1 ...)

vect must be a vector of length equal to the product of exact nonnegative integers dim1, ....

vector->array returns an array of type proto consisting of all the elements, in row-major order, of vect. In the case of a rank-0 array, vect has a single element.

(vector->array #(1 2 3 4) #() 2 2)
                => #2A((1 2) (3 4))
(vector->array '#(3) '#())
                => #0A 3
[procedure] (array->vector array)

Returns a new vector consisting of all the elements of array in row-major order.

(array->vector #2A ((1 2)( 3 4)))
                => #(1 2 3 4)
(array->vector #0A ho)
                => #(ho)
[procedure] (array-in-bounds? array index1 ...)

Returns #t if its arguments would be acceptable to array-ref.

[procedure] (array-ref array k1 ...)

Returns the (k1, ...) element of array.

[procedure] (array-set! array obj k1 ...)

Stores obj in the (k1, ...) element of array. The value returned by array-set! is unspecified.

[procedure] (A:floC128b)
[procedure] (A:floC128b z)

Returns an inexact 128-bit flonum complex uniform-array prototype.

[procedure] (A:floC64b)
[procedure] (A:floC64b z)

Returns an inexact 64-bit flonum complex uniform-array prototype.

[procedure] (A:floC32b)
[procedure] (A:floC32b z)

Returns an inexact 32-bit flonum complex uniform-array prototype.

[procedure] (A:floC16b)
[procedure] (A:floC16b z)

Returns an inexact 16-bit flonum complex uniform-array prototype.

[procedure] (A:floR128b)
[procedure] (A:floR128b x)

Returns an inexact 128-bit flonum real uniform-array prototype.

[procedure] (A:floR64b)
[procedure] (A:floR64b x)

Returns an inexact 64-bit flonum real uniform-array prototype.

[procedure] (A:floR32b)
[procedure] (A:floR32b x)

Returns an inexact 32-bit flonum real uniform-array prototype.

[procedure] (A:floR16b)
[procedure] (A:floR16b x)

Returns an inexact 16-bit flonum real uniform-array prototype.

[procedure] (A:fixZ64b)
[procedure] (A:fixZ64b n)

Returns an exact binary fixnum uniform-array prototype with at least 64 bits of precision.

[procedure] (A:fixZ32b)
[procedure] (A:fixZ32b n)

Returns an exact binary fixnum uniform-array prototype with at least 32 bits of precision.

[procedure] (A:fixZ16b)
[procedure] (A:fixZ16b n)

Returns an exact binary fixnum uniform-array prototype with at least 16 bits of precision.

[procedure] (A:fixZ8b)
[procedure] (A:fixZ8b n)

Returns an exact binary fixnum uniform-array prototype with at least 8 bits of precision.

[procedure] (A:fixN64b)
[procedure] (A:fixN64b k)

Returns an exact non-negative binary fixnum uniform-array prototype with at least 64 bits of precision.

[procedure] (A:fixN32b)
[procedure] (A:fixN32b k)

Returns an exact non-negative binary fixnum uniform-array prototype with at least 32 bits of precision.

[procedure] (A:fixN16b)
[procedure] (A:fixN16b k)

Returns an exact non-negative binary fixnum uniform-array prototype with at least 16 bits of precision.

[procedure] (A:fixN8b)
[procedure] (A:fixN8b k)

Returns an exact non-negative binary fixnum uniform-array prototype with at least 8 bits of precision.

[procedure] (A:bool)
[procedure] (A:bool boolean)

Returns a boolean uniform-array prototype.

Author

Aubrey Jaffer

Version history

License

Copyright (C) 2005 Aubrey Jaffer

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.