slib-arraymap
Description
A port of the SLIB applicative routines for arrays library. For SLIB documentation see arraymap.
Documentation
Usage
(import slib-arraymap)
array-map!
[procedure] (array-map! ARR0 FUNC [ARR1 ...])ARR1, ... must have the same number of dimensions as ARR0 and have a range for each index which includes the range for the corresponding index in ARR0. {FUNC}} is applied to each tuple of elements of ARR1, ... and the result is stored as the corresponding element in ARR0. The value returned is unspecified. The order of application is unspecified.
array-map
[procedure] (array-map PROTO FUNC [ARR1 ARR2 ...]) -> arrayARR2, ... must have the same number of dimensions as ARR1 and have a range for each index which includes the range for the corresponding index in ARR1. proc is applied to each tuple of elements of ARR1, ARR2, ... and the result is stored as the corresponding element in a new array of type prototype. The new array is returned. The order of application is unspecified.
array-for-each
[procedure] (array-for-each PROC [ARR0 ...])PROC is applied to each tuple of elements of ARR0, ... in row-major order. The value returned is unspecified.
array-fold
[procedure] (array-fold PROC SEED [ARR0 ...]) -> *PROC is applied to the SEED & each tuple of elements of ARR0 ... in row-major order. The value returned is the result of the repeated application of PROC to SEED.
- PROC
- (* [* ...] -> *) ; SEEDi+1 <- (PROC SEEDi [ARR0i ...])
- SEED
- * ; initial value
- ARR0 ...
- array ... ; arrays to fold
array-indexes
[procedure] (array-indexes ARR) -> arrayReturns an array of lists of indexes for ARR such that, if LI is a list of indexes for which ARR is defined, (equal? LI (apply array-ref (array-indexes ARR) LI)).
array-index-for-each
[procedure] (array-index-for-each ARR PROC)Applies proc to the indices of each element of array in turn. The value returned and the order of application are unspecified.
One can implement array-index-map! as
(define (array-index-map! ra fun)
(array-index-for-each
ra
(lambda is (apply array-set! ra (apply fun is) is))))
array-index-map!
[procedure] (array-index-map! ARR PROC)Applies 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 '#() (array-dimensions array))))
(array-index-map! ra (lambda x x))
ra))
Another example:
(define (apl:index-generator n)
(let ((v (make-vector n 1)))
(array-index-map! v (lambda (i) i))
v))
array:copy!
[procedure] (array:copy! DST SRC)Copies every element from vector or array SRC to the corresponding element of DST. DST must have the same rank as SRC, and be at least as large in each dimension. The order of copying is unspecified.
array-copy
[procedure] (array-copy SRC) -> arrayReturns a fresh copy of the vector or array source. The order of copying is unspecified.
Notes
- array-fold & array-copy are not part of the the SLIB library.
Author
Aubrey Jaffer
Maintainer
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/slib-arraymap
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Requirements
Version history
- 1.1.0
- Add array-fold.
- 1.0.0
- C5 release.
License
Copyright (C) 1993, 2003 Aubrey Jaffer
Permission to copy this software, to modify it, to redistribute it, to distribute modified versions, and to use it for any purpose is granted, subject to the following restrictions and understandings.
1. Any copy made of this software must include this copyright notice in full.
2. I have made no warranty or representation that the operation of this software will be error-free, and I am under no obligation to provide any services, by way of maintenance, update, or otherwise.
3. In conjunction with products arising from the use of this material, there shall be no use of my name in any advertising, promotional, or sales literature without prior written consent in each case.