Email list hosting service & mailing list manager

Generalized arrays in the presence of call/cc Bradley Lucier (27 Jul 2022 12:39 UTC)
Re: Generalized arrays in the presence of call/cc Marc Nieper-Wißkirchen (27 Jul 2022 13:15 UTC)
Re: Generalized arrays in the presence of call/cc Bradley Lucier (27 Jul 2022 15:11 UTC)
Re: Generalized arrays in the presence of call/cc John Cowan (27 Jul 2022 20:19 UTC)
Re: Generalized arrays in the presence of call/cc Marc Nieper-Wißkirchen (27 Jul 2022 21:04 UTC)
Re: Generalized arrays in the presence of call/cc Bradley Lucier (28 Jul 2022 21:47 UTC)
Re: Generalized arrays in the presence of call/cc John Cowan (30 Jul 2022 15:33 UTC)
Re: Generalized arrays in the presence of call/cc Marc Nieper-Wißkirchen (30 Jul 2022 17:06 UTC)
Re: Generalized arrays in the presence of call/cc Bradley Lucier (30 Jul 2022 19:48 UTC)
Re: Generalized arrays in the presence of call/cc Bradley Lucier (06 Aug 2022 17:58 UTC)
Re: Generalized arrays in the presence of call/cc John Cowan (06 Aug 2022 18:05 UTC)
Re: Generalized arrays in the presence of call/cc Bradley Lucier (10 Aug 2022 18:27 UTC)

Generalized arrays in the presence of call/cc Bradley Lucier 27 Jul 2022 12:38 UTC

I recently noticed that array->list did not implement the guarantee that
array elements are computed in lexicographical order and changed:

(define (%%array->list array)
   (array-foldr cons '() array))

to

(define (%%array->list array)
   (reverse!
    (%%interval-foldl (%%array-getter array)
                      (lambda (a b) (cons b a))
                      '()
                      (%%array-domain array))))

I don't have a great understanding of continuations and call/cc, but it
appears that if the procedure (%%array-getter array) captures the
continuation which is then invoked multiple times, then subsequent
invocations of the continuation, which ends with calling reverse!, will
modify the pairs in the results of earlier calls.  So this code should
use reverse instead of reverse!.

More generally, the general programming ansatz of "allocate a
vector/structure/object/... and sequentially evaluate the elements of an
array and store them in the allocated object" appears to lead to
incorrect results.  One would need to "sequentially evaluate the
elements of an array, storing these values in newly allocated slots on
the stack or in a list, and when they're all evaluated and temporarily
stored, allocate the vector/structure/object/... and go back and store
the saved values into the vector/structure/object/...".

This would to make programming with generalized arrays quite a bit
slower with all the stack/list temporary storage of elements.  Unless
someone can offer other ideas.

Brad