Newsgroups: comp.lang.apl
Path: watmath!watserv1!torn!utcsri!rpi!usenet.coe.montana.edu!decwrl!csus.edu!sfsuvax1.sfsu.edu!vpcsc4
From: vpcsc4@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: More J Questions : About do (".) and tracing (1!: 2&2)
Message-ID: <1992Jul29.214620.10230@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
Distribution: NA
Date: Wed, 29 Jul 1992 21:46:20 GMT

1. In some versions of APL there is an "execute" instruction which
   does provides for conditional execution contingent on the value
   of a boolean variable.  The equivalent in J looks like it is the
   ". (do) instruction.

   If foo and boolean_var are as shown, what is the syntax for the
   conditional execution of foo?

   a   =. 1
   foo =. 'a =. a*3'
   b_v =. 1 

   Something like
   (b_v#1)(".foo)  ( This always executes foo but I
                     hope it communicates the idea)

2. This should be easy. What is J's equivalent to APL's []TRAP ?

3. How would I step through the (LU factorization) routine below using
   1!:1&2 ? I've tried trace =. ('1!:1&2 ', "1 m) : ''  but get a
   domain error when I type "trace a".

   s=. a =. 4 4 $ 1 3 5 2 3 6 9 12 15 18 21 24 27 1 3 5
   m=. 0 0 $''''
   m =. m, ' l =. u =. 0 0 $ '''''
   m =. m, ' i =. 0'
   m =. m, ' n =. ''''$ $ {. y. '
   m =. m, 'loop)'
   m =. m, ' l   =. l, < (i # 0 ) , 1, f =. }. ({."1 y.) % ({. {. y.)'
   m =. m, ' u   =. u, < (i # 0 ) ,{.y.'
   m =. m, ' y.  =. (}."1 }. y.) - (}.{.y.)*"(1 0) f'
   m =. m, ' i   =. >: i'
   m =. m, ' $.=. ((i<n)#loop),end'
   m =. m, 'end)'
   m =. m, ' y.  =. ( < |: >,l ), (< >,u) '
   lu =. m : ''
   
   lu
+---------------------------------------------------------+-++
| l =. u =. 0 0 $ ''                                      |:||
| i =. 0                                                  | ||
| n =. ''$ $ {. y.                                        | ||
|loop)                                                    | ||
| l   =. l, < (i # 0 ) , 1, f =. }. ({."1 y.) % ({. {. y.)| ||
| u   =. u, < (i # 0 ) ,{.y.                              | ||
| y.  =. (}."1 }. y.) - (}.{.y.)*"(1 0) f                 | ||
| i   =. >: i                                             | ||
| $.=. ((i<n)#loop),end                                   | ||
|end)                                                     | ||
| y.  =. ( < |: >,l ), (< >,u)                            | ||
+---------------------------------------------------------+-++
   
