Re: SRFI 231 - Easy conversion for common array formats
Bradley Lucier 18 Jan 2022 16:51 UTC
On 1/17/22 1:50 PM, John Cowan wrote:
> Lastly, it seems to be common to use a nested-vector representation when
> the problem domain has a fixed rank, as in a 2D or 3D transformation
> matrix, and there is no need to abstract over the interval. Since there
> is no existing function to convert a nested vector to a nested list, it
> makes sense to me for `array` to accept either a list or a vector as its
> second argument.
I just looked at the (array unquoted-nested-vectors) form of Racket's
math/array library:
https://docs.racket-lang.org/math/array_construct.html
If you want to have vectors as elements of the array you quote the
vector elements, so it's an unambiguous representation. The type of the
array is the most specific type that contains all the entries.
It's syntax, it can examine all the elements at compile time, so it
knows what the type of the array is.
There's list->array:
https://docs.racket-lang.org/math/array_convert.html
which is a procedure, like our list->array, which takes a list to an
array. It takes an optional argument of dimensions to specify the shape.
And array->list, which takes an array and returns a flattened list.
There's also list*->array, which turns nested lists into an array.
And similar procedures for vectors.
So, what to do?
How about
(array nested-list-or-vector dimensions [storage-class [mutable? [safe?]]])
as a procedure.
Then Racket's
(array #[#[1 2 3] #[4 5 6]])
would become
(array '#[#[1 2 3] #[4 5 6]] 2)
In Racket
(array #['#[1 2 3] '#[4 5 6]])
builds a one-dimensional array with two vector elements, while this
proposal would be
(array '#[#[1 2 3] #[4 5 6]] 1)
Thoughts?
Brad