PG=Paul Gauthier, DB=me

DB>                   'gree' dbp  g
DB>                1 7
DB>                2 9
 
PG>  It should be:
PG>                1 7
PG>                2 0 

Yes, you're right.  I changed the noun  g  to fit better into one line of an 
email message, but I didn't re-execute the snippet
that'd I'd already copied into the email.  Indeed, when run in a fresh J 
session:

           idx0 =.  $ #: I.@:,
           ptrn =.  E.&>/@:((>. - ,)&:(#@:$) ,:@:]^:[&.> ,&:<)
           dbp  =.  idx0@:ptrn
        
           g =._3;:^:_1\;:'the grass is always greener when greecian grown'
           
           'gree' dbp g
        1 7
        2 0
           
Sorry about that.  

> And I can't figure out the reason behind the fancier ptrn ?

The fancier ptrn allows you to locate an rectangle of arbitrary rank in an 
array of greater or equal rank.  It's not restricted to
rank-1 arrays.  

But I believe you're right, that with the proper n  in   x E."n y  the 
expression would equivalent to  x ptrn y  .  The problem is
that dynamic ranks can't be tacit.  Plus part of the point of the message was 
to advertise the idiom  ,:^(difference in rank)  .
To wit:

           rank      =:  #@:$
           makeRank2 =:  ,:^:(2 - rank)
           
           rank makeRank2 scalar =.          2
        2

           rank makeRank2 vector =. i.       2
        2

           rank makeRank2 table  =. i.     2 2
        2

           rank makeRank2 cube   =. i.   2 2 2
        2

           rank makeRank2 hcube  =. i. 2 2 2 2
        2

-Dan

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to