Re: [Factor-talk] multi dimensional arrays and console
Good suggestion On 04/06/2010 14:08, Miles Gould wrote: > On Fri, Jun 04, 2010 at 12:48:27AM +0300, Kobi Lurie wrote: >> there are two versions, one is based on an array, the other on a hashtable. > I'd suggest calling these dense-multiarray and sparse-multiarray. Both > could be useful in different circumstances. > > Miles > -- China: stop persecuting Falun Gong! http://faluninfo.net URGENT: Innocent people are being persecuted for their belief inside Communist China. -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
On Thu, Jun 3, 2010 at 2:48 PM, Kobi Lurie wrote: > Hi guys, so I took it up on Slava's words, > and tried. > http://paste.factorcode.org/paste?id=1713 > > I haven't tested much as I just wrote it. > But it seems like it works. (i think the calculation is ok too, but my > math is lousy so..) I think that's a good start, Kobi. Here's a revised version that precalculates the strides and allows for a more general underlying sequence type. By manipulating the value in the "strides" slot, the same type could handle row- or column-major layouts as well as J-style slices. http://paste.factorcode.org/paste?id=1716 -Joe -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
On Fri, Jun 4, 2010 at 4:06 AM, Jon Harper wrote: > On Fri, Jun 4, 2010 at 4:32 AM, Slava Pestov wrote: >> Hi Kobi, >> >> Do not override the nth and set-nth generic words for this purpose. >> These words should only be used for collections with integer indices >> 0..length-1. > Even if bounds-check is also overriden to correctly handle the array > of indices ? > Why can't multiarrays be part of the sequence protocol when they reuse > 90% of the code ? Doesn't this mean that the sequence protocol should > be broadened ? There's more to the sequence protocol than bounds checking. Right now, you're guaranteed to be able to take the length of any sequence and address its contents from 0 to (length - 1), and pretty much every sequence combinator is built on this assumption. If you want to reuse an existing protocol for n-dimensional arrays, the more general assocs protocol would make more sense, using index arrays as keys. -Joe -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
On Fri, Jun 04, 2010 at 12:48:27AM +0300, Kobi Lurie wrote: > there are two versions, one is based on an array, the other on a hashtable. I'd suggest calling these dense-multiarray and sparse-multiarray. Both could be useful in different circumstances. Miles -- Whenever a politician or a businessman talks about a quantum leap he _does_ mean the smallest possible change. It's just that he assumes his audience won't realise it. -- Roger Burton West -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
On Fri, Jun 4, 2010 at 4:32 AM, Slava Pestov wrote: > Hi Kobi, > > Do not override the nth and set-nth generic words for this purpose. > These words should only be used for collections with integer indices > 0..length-1. Even if bounds-check is also overriden to correctly handle the array of indices ? Why can't multiarrays be part of the sequence protocol when they reuse 90% of the code ? Doesn't this mean that the sequence protocol should be broadened ? Jon -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
Hi Kobi, Do not override the nth and set-nth generic words for this purpose. These words should only be used for collections with integer indices 0..length-1. Slava On Thu, Jun 3, 2010 at 5:48 PM, Kobi Lurie wrote: > Hi guys, so I took it up on Slava's words, > and tried. > http://paste.factorcode.org/paste?id=1713 > > I haven't tested much as I just wrote it. > But it seems like it works. (i think the calculation is ok too, but my > math is lousy so..) > > there are two versions, one is based on an array, the other on a hashtable. > anyway, you can see it as public domain, if you want to refine and put > in the library, go ahead. > > kobi > > > > -- > ThinkGeek and WIRED's GeekDad team up for the Ultimate > GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the > lucky parental unit. See the prize list and enter to win: > http://p.sf.net/sfu/thinkgeek-promo > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
Hi guys, so I took it up on Slava's words, and tried. http://paste.factorcode.org/paste?id=1713 I haven't tested much as I just wrote it. But it seems like it works. (i think the calculation is ok too, but my math is lousy so..) there are two versions, one is based on an array, the other on a hashtable. anyway, you can see it as public domain, if you want to refine and put in the library, go ahead. kobi -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
> The array language J stores multidimensional arrays as a "shape" > array, followed by a flattened array accessed by multiplying the > indices by the appropriate parts of the shape -- or, when one is > iterating over an array, by simply iterating over the flattened > version of the array (most operations in those array languages iterate > in that way). That sounds like an interesting solution, William. It would be easy to implement in Factor as well. -Joe -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
Joe Groff wrote: > Jon Harper wrote: >> - Why isn't already in the library ? Do multi-dimensional arrays > 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. APL, J, and K programmers would disagree :-). If we don't have a hammer, nothing looks like a nail. I hope the answer is "because we're waiting for someone who really knows multidimensional arrays to design the API." I can't help there, but I know a couple of people who can, if they're willing (extensive previous experience with array and concatenative languages). > 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). The array language J stores multidimensional arrays as a "shape" array, followed by a flattened array accessed by multiplying the indices by the appropriate parts of the shape -- or, when one is iterating over an array, by simply iterating over the flattened version of the array (most operations in those array languages iterate in that way). (I don't know how K does this, because K supports ragged arrays, where different elements can have different lengths; obviously, ragged arrays can't be stored in that particular compact format.) > -Joe -Wm -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
On Wed, Jun 2, 2010 at 10:03 AM, Jon Harper 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 Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
Hi, I had the same problem a few months ago : I expected multi-dimensional arrays to be part of the library. I decided to try and implement it. The challenge is to not rewrite everything and use existing code. Look at this paste to see the result : http://paste.factorcode.org/paste?id=1711 It's not finished at all, I only tested nth, set-nth, each, map, each-index and map-index. 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 ? - 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 ? What are your thoughts ? Jon Harper On Wed, Jun 2, 2010 at 8:10 AM, Slava Pestov wrote: > On Wed, Jun 2, 2010 at 1:47 AM, Kobi Lurie wrote: >> 1) In C sharp, multi dimensional arrays are built into the language, and >> I find them very useful for representing a board, or a board with a few >> layers. >> the syntax is also pretty nice: int[,,] cube = new int[3,3,3]; for example. >> but you can also do int[] (if you have the ram ;-) >> >> Does factor have something similar? (matrices with as many dimensions as >> I want) >> I don't know how to implement such a thing, or even how to access the >> elements in factor. > > Factor has the nth and set-nth words; you can cook up a > multiple-dimensional abstraction on top, either by representing it as > array of arrays, or one big array in row (or column) major order with > some arithmetic to convert indices into row (column) major indices. > >> 2) Does factor have support for command line windows, reading one key at >> a time? >> this can be useful for little games, or in tutorials for learning how to >> program. > > There is a curses binding in the curses vocabulary. It is > Unix-specific. We don't have anything for console access on Windows, > but you're welcome to add the relevant bindings to the > windows.kernel32 vocabulary and contribute your changes. > > Slava > > -- > > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] multi dimensional arrays and console
On Wed, Jun 2, 2010 at 1:47 AM, Kobi Lurie wrote: > 1) In C sharp, multi dimensional arrays are built into the language, and > I find them very useful for representing a board, or a board with a few > layers. > the syntax is also pretty nice: int[,,] cube = new int[3,3,3]; for example. > but you can also do int[] (if you have the ram ;-) > > Does factor have something similar? (matrices with as many dimensions as > I want) > I don't know how to implement such a thing, or even how to access the > elements in factor. Factor has the nth and set-nth words; you can cook up a multiple-dimensional abstraction on top, either by representing it as array of arrays, or one big array in row (or column) major order with some arithmetic to convert indices into row (column) major indices. > 2) Does factor have support for command line windows, reading one key at > a time? > this can be useful for little games, or in tutorials for learning how to > program. There is a curses binding in the curses vocabulary. It is Unix-specific. We don't have anything for console access on Windows, but you're welcome to add the relevant bindings to the windows.kernel32 vocabulary and contribute your changes. Slava -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk