Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!swrinde!emory!europa.eng.gtefsd.com!howland.reston.ans.net!usc!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: reassigning rows
Message-ID: <1993Feb25.184044.9704@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <abalje47.730654189@uther>
Date: Thu, 25 Feb 1993 18:40:44 GMT
Lines: 60

In article <abalje47.730654189@uther> abalje47@uther.calvin.edu (Alan Baljeu) writes:
>A short while ago, there was a discussion about using amend to reassign
>elements in the table. There was also some mention about doing the same with
>rows, but I don't recall any verbs presented to do that.  Can anyone present
>such a thing?
>

   NB.   Try this. (To run this program  port J to your 
   NB.   account and type "0!:2 <'thismessagename'" .)
   NB.   (NB. means comment)
   
   NB. provide english names to some J functions (a.k.a. J verbs)
   roll =. ?
   shape =. $
   link =. ;
   transpose =. |:
   right =. ]  NB. means right argument
   sumscan =. +/
   from =. {
   appendColSumsToNewRow =. ,sumscan
   appendRowSumsToNewCol =. ,. sumscan"1
   assignCol =. >@{:@]`($@[ #. (i.@$@>@{: ,. >@{.)@])`[}
   assignRow =. (assignCol right)&.transpose
   expand =. (* +/\)@[ { 0&,@]

   NB. define a table with 4 rows and 5 columns between 0 and 19
   a =. roll 4 5 shape 20 

   right a =. appendColSumsToNewRow a
   right a =. appendRowSumsToNewCol a

   NB. box a and the operations above
   (right link (appendColSumsToNewRow~ link appendRowSumsToNewCol~ )) a

   NB. insert 0 rows into b as specified in 1 1 0 1 1 0
   right b =. 1 1 0 1 1 0 expand roll 4 5 shape 20

   NB. put sum of rows 0 and 1 into row 2
   right b =. b assignRow (2 link sumscan 0 1 from b)
 
   NB. put sum of rows 3 and 4 into row 5
   right b =. b assignRow (5 link sumscan 3 4 from b)

   NB. put some 0 cols in b
   right b =. 1 1 0 1 1 1 0 expand"1 b

   NB. put sum of columns 0 and 1 into row 2
   right b =. b assignCol (2 link sumscan 0 1 from transpose b)

   NB. put sum of columns 0 and 1 into row 2
   right b =. b assignCol (6 link sumscan 3 4 5 from transpose b)

   NB. multiply the rows of b by 10 20 30 40 50 and 60
   b * 10 20 30 40 50 60

   NB. multiply the colums of b by 10 20 30 40 50 60 and 70 )
   b *"1 ( 10 20 30 40 50 60 70)
   
   <'Emmett'

