Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!mach1!torn!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!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: Selective assignment (was Re: J is NOT APL)
Message-ID: <1993Jan29.233943.5662@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1993Jan26.184600.24394@csi.jpl.nasa.gov> <1993Jan27.094037.13820@csus.edu> <1993Jan27.221845.11152@csi.jpl.nasa.gov>
Date: Fri, 29 Jan 1993 23:39:43 GMT
Lines: 122

 >   
 >   Whew! I'll have to look this over. I use a much simpler indexing
 >   function (that seems to use the same heart as yours):
 >   
 >   index=. ($@])#.[
 >   
 >   that can be used with amendd for copy-with-selective-reassignment:
 >
 Lets look at two real cases :

   x0 =. 100 
   i0 =. 0 2
   y0 =. i. 3 3
 So :
   x0 (i0 index y0) } y0
0 1 100
3 4   5
6 7   8
   x0 (i0&index@]) } y0
0 1 100
3 4   5
6 7   8
  
    And :
 
   x0 =. 100 
   i1 =. 0 6
   y0 =. i. 3 3

   i1 =. 0 6
   x0 (i1 index y0) } y0
  0 1 2
  3 4 5
100 7 8
   x0 (i1&index@]) } y0
  0 1 2
  3 4 5
100 7 8
   
   For the example x0, i0, and y0 your method works nicely. Unfort-
   unately, for the example of x0, i1, and y0 it also works nicely!
   The index value (0 6) usually would mean that one wanted to amend
   the 0th row and 6st column of a table. But y0 is 3 by 3. By
   using selectiveAssign one can watch out for unusual indexing.
   Also using selectiveAssign may help one avoid instances
   where one believes a verb works properly (which it will for most
   values of the index) when really it doesn't. 
   
   0!:3 <'A.js'

   y0 selectiveAssign i1;x0
index error (selectiveAssign)

   See.
   
>   so I don't have to link the index (i in the above) and the array (y),
>   as you do. For example
   
   The linking only occurs once and no variables are assigned as boxed.
   So  the additional computer time is marginal.  I estimate it about 
   about 0.01 secs for a 1000 by 1000 table.
   
   a =. i. 3 3
   b =. 0 ; 10 
   a selectiveAssign b
10 1 2
 3 4 5
 6 7 8
   
>   becomes
>   b; (>1{b) ((>0{b)&index@]) } a
+------+------+
|+-+--+|10 1 2|
||0|10|| 3 4 5|
|+-+--+| 6 7 8|
+------+------+
    I thought you said your method was easier -:) 
   
>   etc. It also works on more than one position:
>   i=. 3 2$ 2 1  0 2  3 3
>   (-1 2 3) (i&index@]) }a
 
   I think you mean:  i =. 3 2 $ 2 1 0 2 2 2
 
   So does selectiveAssign.

   a selectiveAssign i ; -1 2 3
   
  
   As an aside, selectiveAssign also provides for nice 3D indexing
   allowing the programmer to make efficient use of the rank operator.
   
   For example :
   (y0,:y0) selectiveAssign"(2 1) 2 2 $ (0 0 ; 100 ; 2 2 ; 200)
100 1   2
  3 4   5
  6 7   8

  0 1   2
  3 4   5
  6 7 200
   
   Your method also allows 3D indexing, but again, the potential
   for incorrect indexing is just compounded .
   
>   I'd really like to build something that I could use without amend:
>   x i thing a
>   but haven't found a way to do this. Does amend then violate the
>   gander principle?
   
   Gees. Isn't 
   (x;i) selectiveAssign~ a
   close enough? -:)
  
   selectiveAssign could easily be made part of the verb I've been
   working on (I've posted a preliminary version) for general assignment
   into a noun.  Thus one verb could handle row assignment, column 
   assignment, and selective assignment.

   Regards,

   Emmett 
