Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!utcsri!rpi!uwm.edu!caen!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: (J) Simultaneous column assignment into a list
Message-ID: <1993Jan16.000939.9169@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1993Jan5.041611.15629@csus.edu> <WEG.93Jan14130300@mace.cc.purdue.edu>
Distribution: NA
Date: Sat, 16 Jan 1993 00:09:39 GMT
Lines: 173


   NB. In article <WEG.93Jan14130300@mace.cc.purdue.edu> you write:
   NB. >    w 
   NB. >   9 7 7  6  1 6 8
   NB. >   2 4 7  4 20 2 3
   NB. >   1 4 8  9 40 9 5
   NB. >    s
   NB. >   30  1 
   NB. >   50 20
   NB. >   90 40
   NB. >    w[;3 4] =. s
   NB. >    w
   NB. >   9 7 7 30  1 6 8
   NB. >   2 4 7 50 20 2 3
   NB. >   1 4 8 90 40 9 5
   NB. >
   NB. >Isn't this sufficient?
   NB. >w=.   s 3 4}"1 w
   NB. >
   NB. >I think I missed the point.
   NB. >
   NB. No, you did not miss the point at all! Oddly, I didn't think of
   NB. using amend with the rank operator. At one time this yeilded
   NB. an index error on the VAX but it works perfectly now.
   NB. Unfortunately this approach fails if s has only one column vector:
   
   s =. 3 1 $ 10 NB. and then
   s 0}"1 w
   
   NB.  is a rank error. (BTW, is there way to do this?)
   NB. 
   NB.  Also, I am not able to find an elegant solution for reassignment
   NB.  into a row or rows.  (n m}"1)&.|:  comes close, but I still get
   NB.  an error when on reassign into just one row.
   NB. 
   NB.  This gets back to the 'generalized assignment into a noun'
   NB.  verbs I posted which I should have labeled 'generalized
   NB.  assignment into a table' verbs (I apologize for the 
   NB.  misrepresenting title ). These verbs were written so that
   NB.  one doesn't have to think so much about the ranks in an
   NB.  ammend instruction and can think more in terms of the rows or
   NB.  columns in a table which need to be reassigned. For example, the
   NB.  verb "asn" looks at the shape of the right argument to determine
   NB.  which operation, row or column reassignment, you want. So if 
   NB.  "w =. 3 2 $ 5" then "w =. w asn (0; 3 3 3)" is column reassignment 
   NB.  while "w =. w asn (0 ; 3 3)" is row reassignment. In the case of
   NB.  a square matrix, a column vector is required to do reassignment
   NB.  into a column. Also, asn , when used with the rank operator 
   NB.  can be more powerful than amend, since in a noun of shape (j k l)
   NB.  one can invoke column reassignments in some items of j while doing 
   NB.  row assignments in others. 
   NB. 
   NB.  The following are verbs genuinely allow for reassignment into
   NB.  nouns , not just tables, and should work for character and numeric 
   NB.  nouns. (The are not the same as the verbs I posted earlier.)
   NB. 
   acol  =.;@(|:@>@}.@])`(;@(>@{.@]+/(''&$@}.*i.@{.)@$@[))`[}
   g     =. ({.,<@,:@>@}.)`]@.(''&$@(<:@#@$@>@}.))
   arow  =. [;@:>@}.@]`(;@|:@(i.@}.@$@[+/(}.@$@>@}.*/>@{.)@]))`[}(g )@]
   list_rn  =. (arow)`(acol)`(>@}.@])@.(<:@#.@($@[ =/''&$@:,@($@>@}.@]@]@])))
   table_rn =. (arow)`(acol)`(>@}.@])@.(<:@(''&$)@:#.@(,:@$@[=$@>@}.@]))
   table_ln =. (acol)`(list_rn )`(table_rn )@.(''&$@(#@$@>@}.@]))
   list_ln  =. ;@(>@}.@])`(;@(>@{.@]))`[}
   asn =. [`(list_ln)`(table_ln) @. ((''&$)@#@$@[)
   
   NB. These verbs probably can be greatly simplified by using an amend
   NB. instrution similar to the suggested
   NB. w =. s 3 4}"1 w
   NB. which would also work for assignment into *one* column. 
   
   NB. Here are examples of asn:
   
   u0 =. ? 4 7   $ 10
   v0 =. 0 3 ;    100 * i. 2 7  
   v1 =. 2 5 ; ,. 100 * i. 4 2 
   v2 =. 1   ;    100 *  i. 4 
   v3 =. 1   ; ,. 100 *  i. 4
   v4 =. 1   ;    100 *  i. 7   
   v5 =. 1   ; ,: 100 *  i. 7  
   v6 =. (i. 4) ; ? 4 7   $ 10
   u1 =. ? 3 3 $ 20
   v7 =. 0  ; 100 *    i. 3 
   v8 =. 0  ; 100 * ,. i. 3 
   u2 =. 1 1 $ 4
   u3 =. 3 4 $ 16 # 'a'
   v0 ; u0 asn  v0  
+-------------------------------------+-------------------------------+
|+---+-------------------------------+|  0 100 200  300  400  500  600|
||0 3|  0 100 200  300  400  500  600||  9   8   2    5    5    1    4|
||   |700 800 900 1000 1100 1200 1300||  5   8   4    7    8    7    8|
|+---+-------------------------------+|700 800 900 1000 1100 1200 1300|
+-------------------------------------+-------------------------------+
   v1 ; u0 asn  v1 
+-------------+-----------------+
|+---+-------+|9 6   0 8 6 100 9|
||2 5|  0 100||9 8 200 5 5 300 4|
||   |200 300||5 8 400 7 8 500 8|
||   |400 500||7 7 600 8 5 700 0|
||   |600 700||                 |
|+---+-------+|                 |
+-------------+-----------------+
   v2 ; u0 asn  v2
+-----------------+---------------+
|+-+-------------+|9   0 4 8 6 7 9|
||1|0 100 200 300||9 100 2 5 5 1 4|
|+-+-------------+|5 200 4 7 8 7 8|
|                 |7 300 0 8 5 4 0|
+-----------------+---------------+
   v3 ; u0 asn  v3  
+-------+---------------+
|+-+---+|9   0 4 8 6 7 9|
||1|  0||9 100 2 5 5 1 4|
|| |100||5 200 4 7 8 7 8|
|| |200||7 300 0 8 5 4 0|
|| |300||               |
|+-+---+|               |
+-------+---------------+
   v4 ; u0 asn  v4 
+-----------------------------+-------------------------+
|+-+-------------------------+|9   6   4   8   6   7   9|
||1|0 100 200 300 400 500 600||0 100 200 300 400 500 600|
|+-+-------------------------+|5   8   4   7   8   7   8|
|                             |7   7   0   8   5   4   0|
+-----------------------------+-------------------------+
   v5 ; u0 asn  v5
+-----------------------------+-------------------------+
|+-+-------------------------+|9   6   4   8   6   7   9|
||1|0 100 200 300 400 500 600||0 100 200 300 400 500 600|
|+-+-------------------------+|5   8   4   7   8   7   8|
|                             |7   7   0   8   5   4   0|
+-----------------------------+-------------------------+
   v6 ; u0 asn  v6 
+-----------------------+-------------+
|+-------+-------------+|7 4 6 6 1 9 8|
||0 1 2 3|7 4 6 6 1 9 8||8 5 1 4 9 2 4|
||       |8 5 1 4 9 2 4||3 5 8 4 4 8 3|
||       |3 5 8 4 4 8 3||2 9 1 6 6 0 0|
||       |2 9 1 6 6 0 0||             |
|+-------+-------------+|             |
+-----------------------+-------------+
   v7 ; u1 asn  v7
+-------------+---------+
|+-+---------+|0 100 200|
||0|0 100 200||         |
|+-+---------+|         |
+-------------+---------+
   v8 ; u1 asn  v8
+-------+---------+
|+-+---+|  0 14  6|
||0|  0||100 13 13|
|| |100||200 16 14|
|| |200||         |
|+-+---+|         |
+-------+---------+
   u2 asn  0 ; 1       
1
   u2 asn  0 ; 1 1 $ 1 
1
   
   NB. example of assigment in nouns of rank 3
   NB. demonstrates the power of the rank operator
   (u0 ,: u0) asn"(2 1) (v0 ,: v1 ) 
  0 100 200  300  400  500  600
  9   8   2    5    5    1    4
  5   8   4    7    8    7    8
700 800 900 1000 1100 1200 1300

  9   6   0    8    6  100    9
  9   8 200    5    5  300    4
  5   8 400    7    8  500    8
  7   7 600    8    5  700    0
  Cheers,
  Emmett 
