On Wed, Jun 2, 2010 at 10:03 AM, Jon Harper <[email protected]> wrote:
> At this point I have questions:
> - Why isn't already in the library ? Do multi-dimensional arrays
> somehow go against factor's idioms ? Would you want such functionality
> in the library ?

I think because arrays-of-arrays have been sufficient so far.
Two-dimensional arrays aren't needed all that often, and
higher-dimensional arrays hardly at all.

> - To reuse code from the sequence vocabulary, I have changed
> bounds-check? into a generic. Is it okay to do so ?
> - I had to create special words for each-index and map-index. Is it
> important to not have new words (meach-index, mmap-index), meaning
> that each-index and map-index should work on multiarrays also ?

Changing the sequence protocol is a bad idea--it's pretty deeply
ingrained that nth and set-nth should take an integer between 0 and
length-1, and breaking that invariant would make the sequence protocol
useless. If you want a packed multidimensional array type, it would be
more robust to implement it as a virtual sequence over a
single-dimensional array, where each element would be a slice of that
array representing a row (or column). Then you could have new words to
perform nth-of-nth operations on either these packed arrays or
arrays-of-arrays:

: nth2 ( x y seq -- elt ) nth nth ; inline
: set-nth2 ( elt x y seq -- ) nth set-nth ; inline

-Joe

------------------------------------------------------------------------------

_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to