some srfi122 comments Per Bothner 27 Sep 2015 05:22 UTC Re: some srfi122 comments Per Bothner 28 Sep 2015 19:50 UTC Re: some srfi122 comments Bradley Lucier 28 Sep 2015 21:17 UTC

```On 09/28/2015 03:50 PM, Per Bothner wrote:
> On 09/26/2015 10:22 PM, Per Bothner wrote:
> More fundamentally: It's nice to have the flexibility of non-zero
> lower index bounds, but it does complicate the API a lot, and it

I certainly agree it simplifies things, but here's some code I'm working
on currently that calculates second differences of arrays of pixels; if
the difference step is (j_1,j_2), then the new array is defined on all
those indices (i_1,i_2) for which (i_1,i_2) plus or minus (j_1,j_2) is
in the original domain

I'd hate to program this without variable lower bounds on arrays.  It
would seem to be a deal-breaker for me.

(Note: My own private code doesn't yet use the revised names of the SRFI.)

;;; Calculate the four directions in which we'll do second differences

(define (offset->steps offset)
(list (list offset 0)
(list 0      offset)
(list offset offset)
(list offset (fx- offset))))

;;; Build the domains on which those differences are defined.

(define (offset->p-domains offset)
(map (lambda (step)
(let* ((j_1
(car step))
(j_2
(image-domain
(Array-domain zero-image)))
(Interval-dilate image-domain
;; fxabs because we both add and subtract j_1, j_2
(build-Dilation (vector (fxabs j_1) (fxabs j_2))
(vector (fx- (fxabs j_1)) (fx- (fxabs j_2)))))))
(offset->steps offset)))

;;; Compute the four difference arrays defined on the correct domains

(define (second-difference^j g offset)
(let* ((getter (Array-getter g))
(domain (Array-domain g))
(h (estimate-step-size domain)))
(map (lambda (step p-domain)
(let* ((j_1
(car step))
(j_2
(1/step*h
(fl/ (fl* h
(flsqrt (fixnum->flonum (fx+ (fxsquare j_1)
(fxsquare j_2))))))))
(Array->Fixed-array (build-Array p-domain
(lambda (i_1 i_2)
(fl* 1/step*h
(fl+ (getter (fx- i_1 j_1) (fx- i_2 j_2))
(fl* -2.0
(getter i_1 i_2))
(getter (fx+ i_1 j_1) (fx+ i_2 j_2)))))))))
(offset->steps offset)
(offset->p-domains offset))))

```