Regarding point 1: xyz_index does work. Please redo your experiments carefully.
I believe it was a mistake to include xyz_index in the specifications of for_xyz. Code that needs such an index should just use for_xyz. i.n (wherein xyz would be the index, assuming the values 0 1 2 etc. in the iterations). Regarding point 2: ts '>:i.10000' 0.0001232 131776 ts '>:i.100000' 0.00189605 1.04928e6 That is, nearly all of the space in your benchmarks were used to compute >:i.n . ----- Original Message ----- From: Richard Donovan <[EMAIL PROTECTED]> Date: Saturday, September 9, 2006 11:48 pm Subject: [Jprogramming] for_xyz. loops > from vocabulary definition of for. > > (quote) > for. T do. B end. > for_xyz. T do. B end. > > The B block is evaluated once for each item of the array A that > results from > evaluating the T block. In the for_xyz. form, the local name xyz > is set to > the value of an item on each evaluation of the B block and > xyz_index is set > to the index of the item; results are not dependable if these > names are > re-assigned within the B block. > (end-quote) > > > 1. This seems to imply that a variable called xyz_index is created > and > updated > automatically, but I cannot get that to work so assume that is not > the case. > > 2. The implementation of the for. and for_xyz. blocks seem > excessively over- > complicated for what they actually do, and in certain cases take > up far more > space than I would have expected for what it actually achieves: > > > testfor =: 3 :0 > sum=:0 > for_j. >:i.y. do. > sum=:sum+j > end. > sum > ) > > testfor 10000 > 50005000 > > ts 'testfor 10000' > 0.0581344835726 133888 > > ts 'testfor 100000' > 0.612705525423 1051392 > > 3. On the other hand, the while. construct seems easy to > understand and > use, takes up far less space, but also takes a lot longer to run! > Is there a > happy medium? > > testwhile =: 3 :0 > j=:0 > sum=:0 > while. j<y. do. > j=:>:j > sum=:sum+j > end. > sum > ) > > testwhile 10000 > 50005000 > > ts 'testwhile 10000' > 0.0984287109116 2112 > ts 'testwhile 100000' > 1.02252884096 2112 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
