There are a few places where I am implicitly treating Vector as having a second dimension:
- In multiple-binding
for loops (for a;b;c in v)
- In
zip(), which takes multiple vectors and produces a vector suitable for multiple-binding
- In functions that take an optional group-size argument, e.g.,
sum() and accumulate()
- In functions that produce or consume pairs, e.g.,
polar() and angle()
- Explicitly in the
Matrix33 and Matrix44 sub-classes of Vector
Would all of this be neater if I just supported a second dimension to vectors? I hesitate to call this a "matrix" as I feel that ought to be reserved for fixed-size objects rather than the variable length objects the first four of these usages operate on. I'm going to call these "arrayed vectors" for the moment based on the C++ terminology of arrays being fixed-length and vectors being variable-length.
So the array part of an arrayed vector would be a size value that the vector length becomes a multiple of. Mostly no changes to the model would be required except for adding a new attribute that contains this array size and some changes to how indexing works.
Let's say that zip consumes m flat vectors (i.e., vectors with an array size of 1) and returns an arrayed vector with an array size m. Indexing or iterating over this should produce m-vectors. If multiple-binding for loops were redefined such that the names are bound to each element of the vector produced by iterating over the loop source, then the overall behaviour of:
for a;b;c in zip(as, bs, cs)
...
stays the same. However, looping with multiple names over a flat vector would always result in binding each element to the first name and setting the other names to null.
Functions that implicitly return arrayed vectors, like polar() could just explicitly do that and therefore could still be iterated over naturally:
let n = 12
indices = 0..n
for x;y in polar(indices/n)
...
However, now one could also naturally index the results:
let n=12
indices = 0..n
coords = polar(indices/n)
for i in indices
let x;y = coords[i]
...
which would improve the various places in my code where I have ugly indexing like coords[i*2..(i+1)*2]. Functions like angle() would take 2-arrayed vectors and return flat vectors. hypot() would take an n-arrayed m-item vector and return a flat m-item vector with the n-dimensioned hypotenuse of each item. sum() and acculumate() would lose their second argument and just do The Right Thing with any n-arrayed vector they are given.
Matrix33 and Matrix44 are only used internally, but it would make sense for these to match 3-arrayed and 4-arrayed vectors in terms of their attributes. It might be neat to abstract out operations into Vector that can easily work with any size of matrix – like translate, scale, vmul, mmul and transpose.
There are a few places where I am implicitly treating
Vectoras having a second dimension:forloops (for a;b;c in v)zip(), which takes multiple vectors and produces a vector suitable for multiple-bindingsum()andaccumulate()polar()andangle()Matrix33andMatrix44sub-classes ofVectorWould all of this be neater if I just supported a second dimension to vectors? I hesitate to call this a "matrix" as I feel that ought to be reserved for fixed-size objects rather than the variable length objects the first four of these usages operate on. I'm going to call these "arrayed vectors" for the moment based on the C++ terminology of arrays being fixed-length and vectors being variable-length.
So the array part of an arrayed vector would be a size value that the vector length becomes a multiple of. Mostly no changes to the model would be required except for adding a new attribute that contains this array size and some changes to how indexing works.
Let's say that
zipconsumes m flat vectors (i.e., vectors with an array size of 1) and returns an arrayed vector with an array size m. Indexing or iterating over this should produce m-vectors. If multiple-bindingforloops were redefined such that the names are bound to each element of the vector produced by iterating over the loop source, then the overall behaviour of:stays the same. However, looping with multiple names over a flat vector would always result in binding each element to the first name and setting the other names to
null.Functions that implicitly return arrayed vectors, like
polar()could just explicitly do that and therefore could still be iterated over naturally:However, now one could also naturally index the results:
which would improve the various places in my code where I have ugly indexing like
coords[i*2..(i+1)*2]. Functions likeangle()would take 2-arrayed vectors and return flat vectors.hypot()would take an n-arrayed m-item vector and return a flat m-item vector with the n-dimensioned hypotenuse of each item.sum()andacculumate()would lose their second argument and just do The Right Thing with any n-arrayed vector they are given.Matrix33andMatrix44are only used internally, but it would make sense for these to match 3-arrayed and 4-arrayed vectors in terms of their attributes. It might be neat to abstract out operations intoVectorthat can easily work with any size of matrix – liketranslate,scale,vmul,mmulandtranspose.