[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Slib-discuss] subarray to access diagonals
From: |
Aubrey Jaffer |
Subject: |
Re: [Slib-discuss] subarray to access diagonals |
Date: |
Tue, 24 Jun 2008 10:42:15 -0400 (EDT) |
| Date: Tue, 24 Jun 2008 19:57:54 +0800
| From: "Fernan Bolando" <address@hidden>
|
| Is there a direct way to access the diagonal of an array using
| subarray. My limited scheme abilities seem to prevent me from
| understanding the documentation directly.
Not using the subarray procedure, but using "make-shared-array":
http://swiss.csail.mit.edu/~jaffer/slib_7.html#SEC193
Function: 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