Terrence Brannon wrote:
>However, I think there should be a period between "x" and "If"

Good catch.

>Also, I find this description confusing. What does it mean to index an
>array? Are y and x both arrays?

In J, all data (AKA nouns AKA variables) are arrays.  Even a simple scalar like 
 5  is an array.  So, yes, both  x  and  y  are arrays.

An index is a way to refer to a part of an array without regard to the actual 
value in that array.  In lots of languages, you say something like  
array[index] .  In J, you say  index { array  .  

If you think about it, pulling parts out of an array is an action like any 
other.  An action is a verb.  The authors of J realized this, and so, instead 
of giving indexing special syntax as in other languages, they made it a normal 
verb (function).  

At first, coming from other languages, this is frustrating and annoying.  For 
example, you can no longer say:
   
           array[14] = 52;  // J equivalent is   array =: 52 ( 14} ) array

But you soon learn how powerful and useful this model is. You can calculate 
indicies (even multi dimensional), pull them out of the array, put them back, 
ALL WITHOUT REFERENCE TO THE SPECIFIC ARRAY.  It allows one to abstract a level 
from the array; all arrays of the same shape are, in this sense, identical; 
indistinguishable.

A simple example:  pulling out the very middle atom of an array.  J makes this 
easy:

           center =: {~ [: <@:(<"0) (#: <.@:-:@:(*/))@:$   NB.  Examples in PS

which will work correctly on all arrays -- of any rank, shape, or type.  

It's either impossible or very awkward to reproduce this example in many other 
languages.  Often, you need other syntax (i.e. compiled source code) to 
reference a multidimensional array (e.g.  array[3;14]  or array[3][14]  ).  
This limitation means you must (at least) know an array's rank in advance.

> Is there some tagging  ... such that J knows the array 
>  is a permutation and not just an array?

No, a permutation is simply any ordering of the integers  i.N  (where  N  is 
the length of the array you're indexing and is known as the "order" of the 
permutation).  So the following are all permutations:

       0 1 2 3  
       3 2 1 0  
       2 0 1 3 

       5 4 1 2 0 3

       1 0

       0

       0#0   NB.  No indicies at all


etc.  There are many ways of generating permutations.  The verbs  /:  and  \:  
produce special permutations which tell you how to sort an array.  So  (/:x) {  
x  will sort x (doesn't matter what  x  is; can be any type, rank, or shape).  
Take a look at the verbs  A.  and  C.  too.


Hope this helps,

-Dan

PS:  

           center 1 2 3 4 5
        3

           center 'ABC|DEF'
        |

           center 0
        0

           center 1 2 3 , 4 5 6 ,: 7 8 9
        5

           center i. 5 6 8 3 2 4
        2880

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

Reply via email to