testfld (0{j_index)} table   NB. put new contents into 

This line doesn't do jack.  m} creates a new table, modified
as requested.  But you don't do anything with the new table, so it
is quietly discarded.  You meant

table =. testfld (<j_index,0)} table

where

<row,col

or

<row;col

is how you index an individual cell.


The loop could be replaced by

table =. (<"0 i. #table) (<a:;0)} table

Interesting exercise: why did your erroneous verb produce the result it did?

Henry Rich

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Hahn, Harvey
> Sent: Wednesday, July 30, 2008 4:06 PM
> To: Programming forum
> Subject: [Jprogramming] Amending within a For loop
> 
> I have read and re-read the "Amend" and "For" dictionary 
> entries as well as the "For" entries in the Rich and Stokes 
> online books, and I have tried a couple of experimental 
> variations with no luck.  Here's a simplified example of the 
> problem I'm having:
> 
> test=: 3 : 0
> table=. 4 3 $ 
> 'aaa';'aa';'a';'bbb';'bb';'b';'ccc';'cc';'c';'ddd';'dd';'d'
> numrows=. 0{$table
> for_j. (i. numrows) do.
>   testfld=. < j_index          NB. create arbitrary new field contents
>   testfld (0{j_index)} table   NB. put new contents into 
> first cell in row
> end.
> )
> 
>    test''
> +---+--+-+
> |aaa|aa|a|
> +---+--+-+
> |bbb|bb|b|
> +---+--+-+
> |ccc|cc|c|
> +---+--+-+
> |3  |3 |3│
> +---+--+-+
> 
> Why do I get the above table instead of the intended table below?
> 
> +-+--+-+
> |0|aa|a|
> +-+--+-+
> |1|bb|b|
> +-+--+-+
> |2|cc|c|
> +-+--+-+
> |3|dd|d│
> +-+--+-+
> 
> What am I missing about the "Amend" and/or "For" commands?  
> Thanks in advance for your guidance!
> 
> Harvey
> 
> ----------------------------------------------------------------------
> For information about J forums see 
> http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to