Comparison of SRFIs 122 and 164 John Cowan (30 Nov 2019 22:07 UTC)
Re: Comparison of SRFIs 122 and 164 Per Bothner (30 Nov 2019 23:28 UTC)
Re: Comparison of SRFIs 122 and 164 John Cowan (01 Dec 2019 03:58 UTC)
Re: Comparison of SRFIs 122 and 164 Per Bothner (01 Dec 2019 06:36 UTC)
Re: Comparison of SRFIs 122 and 164 John Cowan (01 Dec 2019 13:55 UTC)
Re: Comparison of SRFIs 122 and 164 Per Bothner (02 Dec 2019 04:28 UTC)
Re: Comparison of SRFIs 122 and 164 Bradley Lucier (01 Dec 2019 21:16 UTC)
Re: Comparison of SRFIs 122 and 164 Bradley Lucier (01 Dec 2019 01:18 UTC)

Re: Comparison of SRFIs 122 and 164 Bradley Lucier 01 Dec 2019 21:16 UTC

On 11/30/19 10:58 PM, John Cowan wrote:
> SRFI 164 also provides a procedure for doing arbitrary transformations,
> whereas SRFI 122 does not.
>

OK, does that mean that you think there should be procedure like this?

(define (apply-general-transform domain transform A)
   (let ((A_ (array-getter A))
         (A! (and (mutable-array? A)
                  (array-setter! A))))
     (apply make-array
            domain
            (lambda args
              (call-with-values
                  (lambda ()
                    (apply transform args))
                A_))
            (if A!
                (list
                 (lambda args
                   ;; first arg is new value
                   (apply A!
                          (car args)
                          (call-with-values
                              (lambda ()
                                (apply transform (cdr args)))
                            list))))
                '()))))

Of course, one can always do something like

(let ((A_ (array-getter A)) ;; two-dimensional
       (A! (array-setter A)))
   (make-array new-domain    ;; one-dimensional
               (lambda (i)
                 (A_ (square i) (square i)))
               (lambda (v i)
                 (A! v (square i) (square i)))))

if new-domain and the domain of A are compatible.  The resulting array
is so much more efficient than

(apply-general-transform
  new-domain
  (lambda (i)
    (values (square i) (square i)))
  A)

that I'd be hesitant to provide the latter as a built-in (see "Lisp is
slow" meme).