Newsgroups: comp.lang.apl
Path: watmath!watserv1!torn.onet.on.ca!utgpu!news-server.csri.toronto.edu!rpi!usc!wupost!uunet!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: J Questions
Message-ID: <1992Jun15.165324.7094@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <1992Jun11.211513.29040@csus.edu>
Date: Mon, 15 Jun 92 16:53:24 GMT
Lines: 87


Re "J questions" from Emmett McLean.  Several of the desired results can be 
computed by using "expand":
 
   expand =. (* +/\)@[ { 0&,@]
 
The left argument is a boolean list "b"; the right argument "a" is a numeric
array with as many items as 1s in "b"; and the result has #b items, with
0s where "b" has a 0 and an item from "a" where "b" has a 1.  (This is a
version of backslash-bar in APL, and can be readily generalized to use "fills"
other than 0.)
 
   a
0 1  2  3
4 5  6  7
8 9 10 11
 
> 1.  Insert a zero row in (new rows) 0 and 3
   0  0  0  0
   0  1  2  3
   4  5  6  7              <->  0 1 1 0 1 expand a
   0  0  0  0
   8  9 10 11
 
> 2. Insert a zero column  in ( new columns ) 0 and 3
   0   1  2  0   3
   4   5  6  0   7         <->  1 1 1 0 1 expand"1 a
   8   9 10  0  11
 
> 3. Annihilate row 1 to get
   0  1  2  3
   8  9 10 11              <->  1 0 1#a
 
> 4. Annihilate column 2 to get
   0  1  3
   4  5  7                 <->  1 1 0 1#"1 a
   8  9 11
 
>    If a =. 4 4 $  0
>       b =. 2 2 $  >: i.4
>       c =. 10  *  >: i. 2 4
>       d =. 1 2 3 4
 
   0 0 0 0                      0,.(0,b,0),.0
   0 1 2 0                 <->  0,(0,.b,.0),0
   0 3 4 0                      0 1 1 0 expand 0 1 1 0 expand"1 b
   0 0 0 0                      4 4{._3 _3{.b
 
   0 0 0 0
   0 0 0 0                 <->  0 0 1 1 expand 0 0 1 1 expand"1 b
   0 0 1 2                      _4 _4{.b
   0 0 3 4
 
    0  0  0  0
   10 20 30 40             <->  0 1 0 1 expand c
    0  0  0  0
   50 60 70 80
 
   10 0 50 0
   20 0 60 0               <->  |: 1 0 1 0 expand c
   30 0 70 0                    1 0 1 0 expand"1 |:c
   40 0 80 0
 
   0 0 0 0
   0 0 0 0                 <->  0 0 1 0 expand ,:d
   1 2 3 4                      0 0 1 0 *"0 1 d
   0 0 0 0
 
   0 0 1 0                      |: 0 0 1 0 expand ,:d
   0 0 2 0                 <->  0 0 1 0 expand"1 ,.d
   0 0 3 0                      0 0 1 0 *"1 0 d
   0 0 4 0
 
> 6. I would like to see a simple example using UNTIL
>    as described in the dictionary on the bottom of page 15 .
>    I find the explanation to complicated.
>    What is the meaning of (1 _1) ? In this context?
 
Until (m`:1) is obsolescent and has been replaced by power (^:).
The notation (1 _ 1) (there is a blank between the _ and the 1) means that
the derived verb has monadic rank 1, left rank infinity, and right rank 1
(as explained in the general description of entries in the opening paragraphs
on page 6).

------------------------------------
Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
Phone: (416) 925 6096;  Fax: (416) 488 7559
