Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!spool.mu.edu!umn.edu!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: General assignment into a noun!
Message-ID: <1993Jan11.005639.11230@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
Distribution: NA
Date: Mon, 11 Jan 1993 00:56:39 GMT
Lines: 65


   NB. Verbs for general assignment into a noun. Requires v6.1 
   NB. or 6.2 .These verbs should make indexing in J as easy as 
   NB. indexing in APL. 

   NB. With asn there is no need for separate verbs for 
   NB. row and column indexing since asn determines which
   NB. operation is needed based on the shape of the right
   NB. argument. Assignment into rank 3 verbs is 
   NB. implemented by using asn with the rank operator.


   acol  =.;@(|:@>@}.@])`(;@(>@{.@]+/(''&$@}.*i.@{.)@$@[))`[}
   g     =. ({.,<@,:@>@}.)`]@.(''&$@(<:@#@$@>@}.))
   arow  =. [;@:>@}.@]`(;@|:@(i.@}.@$@[+/(}.@$@>@}.*/>@{.)@]))`[}g@]
   list  =. arow`acol`arow@.(<:@#.@($@[ =/''&$@:,@($@>@}.@]@]@])))
   table =. arow`acol`arow@.(<:@(''&$)@:#.@(,:@$@[=$@>@}.@]))
   asn   =. acol`list`table@.(''&$@(#@$@>@}.@]))

   NB. arow does assignment into a row,   
   NB. acol does assignment into a column,   
   NB. asn  does assignment into a either a row or column based
   NB. on the shape of the noun in the right box. In the case
   NB. of a square table, ambiguity of row or column assignment
   NB. is determined by if  >@}. is a list (row assignment)
   NB. or a table (column assignment or row assignment). In the
   NB. jargon of mathematics a column vector is necessary for
   NB. column reassignment.

   NB. Test cases
   NB. >@}. of v can be a list or table
   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
   
   v0 ; u0 asn  v0  
   v1 ; u0 asn  v1 
   v2 ; u0 asn  v2
   v3 ; u0 asn  v3  
   v4 ; u0 asn  v4 
   v5 ; u0 asn  v5
   v6 ; u0 asn  v6 
   v7 ; u1 asn  v7
   v8 ; u1 asn  v8
   u2 asn  0 ; 1       
   u2 asn  0 ; 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 ,: v4 ) 

   NB. If anyone is interested in how these work just ask.

   NB. Emmett
