This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see AdvancedArraysCowan in WG2's repo for R7RS-large.

Advanced­Arrays­Cowan

cowan
2014-10-05 10:01:46
8history
source

This is a continuation of ArraysCowan, put on a separate page for convenience.

Advanced procedures

These procedures are mostly derived in function, and sometimes in name, from ISO/IEC 8485 and ISO 17351, which standardize basic and extended APL respectively.

(array-collapse array j)

Let k be the rank of array. This procedure constructs and returns an array of rank j, which MUST be less than or equal to k, whose components are arrays of rank k - j. The shape of the returned array is equal to the first j components of the shape of array, and the shapes of its subarrays are equal to the remaining k-j components.

(array-explode array j)

Let k be the rank of array. This procedure constructs and returns an array of rank j, which MUST be greater than or equal to k. Each component of array MUST be an array of rank j - k, all of which MUST have the same shape. The shape of the returned array is the shape of array concatenated with the shape of any of its components, and each component is the corresponding component of the corresponding subarray of array.

(array-reshape shape array)

Constructs and returns a new array of shape shape whose components in row-major order are the same (in the sense of eqv?) as the components of array in row-major order. (APL reshape.)

(array-reverse array axis)

Constructs and returns an array with the same shape as array, but whose elements on the specified axis are reversed. Axis must be a non-negative integer less than the rank of array. (APL reverse.)

(array-compress array booleans axis)

Constructs and returns an array with the same shape as array except possibly along the axis dimension. The array is sliced along axis and the elements of booleans (a vector of boolean values) are used to decide which slices to incorporate into the result: if the corresponding boolean is #t, the slice is incorporated, otherwise not. (APL compress.)

(array-expand array booleans nil axis)

Constructs and returns an array with the same shape as array except possibly along the axis dimension. Array is sliced along axis and the elements of booleans (which MUST be a vector of boolean values) are used to decide where, if anywhere, nil (which must have the same shape as a slice) is to be interpolated: if the corresponding boolean is #t, nil is interpolated, otherwise the next slice is incorporated. The size of booleans MUST be equal to the value of the axis dimension in the result. (APL expand.)

(array-rearrange array vector axis)

Constructs and returns an array with the same shape as array. Array is sliced along the axis dimension, and the slices are reassembled in the order given by vector, which MUST be a vector of exact integers. The slice whose number appears in the first element of vector appears first in the result, and so on. (Generalized version of APL rotate.)

(array-rearrange-axes array vector)

Constructs and returns an array whose shape is a permutation of the shape of array. Vector, which MUST be a vector of exact integers, specifies how to permute it. The axis whose number appears in the first element of vector appears as the first axis of the result, and so on. (APL dyadic transpose with integer-valued vector.)

(subarray array start-subscripts end-subscripts)

Constructs and returns a smaller array with the same rank as array whose elements begin at the "lower left" corner specified by the list start-subscripts and end at the "upper right" corner specified by the list end-subscripts. (APL take and drop.)

(array-recursive-ref array subscript ...)

Applies array-ref to the array using the first i subscripts, where i is the rank of array. If there are more subscripts, the result MUST be an array. Apply array-ref to the result using the next j subscripts, where j is the rank of the result. Repeat until there are no more subscripts, returning the last result. (APL enlist.)

Higher-order procedures

These procedures are mostly derived in function, and sometimes in name, from ISO/IEC 8485 and ISO 17351, which standardize basic and extended APL respectively.