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