chickadee » srfi-179 » make-specialized-array

(make-specialized-array interval [ storage-class generic-storage-class ] [ safe? (specialized-array-default-safe?) ])procedure

Constructs a mutable specialized array from its arguments.

interval must be given as a nonempty interval. If given, storage-class must be a storage class; if it is not given it defaults to generic-storage-class. If given, safe? must be a boolean; if it is not given it defaults to the current value of (specialized-array-default-safe?).

The body of the result is constructed as

  ((storage-class-maker storage-class)
   (interval-volume interval)
   (storage-class-default storage-class))
  

The indexer of the resulting array is constructed as the lexicographical mapping of interval onto the interval [0,(interval-volume interval)).

If safe is #t, then the arguments of the getter and setter (including the value to be stored) of the resulting array are always checked for correctness.

After correctness checking (if needed), (array-getter array) is defined simply as

  (lambda multi-index
    ((storage-class-getter storage-class)
     (array-body array)
     (apply (array-indexer array) multi-index)))
  

and (array-setter array) is defined as

  (lambda (val . multi-index)
    ((storage-class-setter storage-class)
     (array-body array)
     (apply (array-indexer array) multi-index)
     val))
  

It is an error if the arguments of make-specialized-array do not satisfy these conditions.

Examples. A simple array that can hold any type of element can be defined with (make-specialized-array (make-interval '#(3 3))). If you find that you're using a lot of unsafe arrays of unsigned 16-bit integers, one could define

  (define (make-u16-array interval)
    (make-specialized-array interval u16-storage-class #f))

and then simply call, e.g., (make-u16-array (make-interval '#(3 3))).