www.delorie.com/gnu/docs/guile/guile_238.html   search  
 
Buy GNU books!


Guile Reference Manual

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

22.6.2 Array Mapping

Scheme Procedure: array-map! ra0 proc . lra
Scheme Procedure: array-map-in-order! ra0 proc . lra
C Function: scm_array_map_x (ra0, proc, lra)
array1, ... must have the same number of dimensions as array0 and have a range for each index which includes the range for the corresponding index in array0. proc is applied to each tuple of elements of array1 ... and the result is stored as the corresponding element in array0. The value returned is unspecified. The order of application is unspecified.

Scheme Procedure: array-for-each proc ra0 . lra
C Function: scm_array_for_each (proc, ra0, lra)
Apply proc to each tuple of elements of array0 ... in row-major order. The value returned is unspecified.

Scheme Procedure: array-index-map! ra proc
C Function: scm_array_index_map_x (ra, proc)
Apply proc to the indices of each element of array in turn, storing the result in the corresponding element. The value returned and the order of application are unspecified.

One can implement array-indexes as
 
(define (array-indexes array)
    (let ((ra (apply make-array #f (array-shape array))))
      (array-index-map! ra (lambda x x))
      ra))
Another example:
 
(define (apl:index-generator n)
    (let ((v (make-uniform-vector n 1)))
      (array-index-map! v (lambda (i) i))
      v))


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003