Vocabulary/comma

From J Wiki
Jump to navigation Jump to search

>> <<   Down to: Dyad   Back to: Vocabulary Thru to: Dictionary

, y Ravel

Rank Infinity -- operates on x and y as a whole -- WHY IS THIS IMPORTANT?



Produces a list containing all the atoms in y, in the order in which they appear in the display of y.

The result is ordered by items, each of which is ordered by its own items, etc.

An atom is converted to a 1-atom list, a list is left unchanged, and any noun of higher rank is flattened into a list

   ]z=: 0 20 10 +/ i.4  NB. sample noun
 0  1  2  3
20 21 22 23
10 11 12 13
   
   ,z
0 1 2 3 20 21 22 23 10 11 12 13

   $ 'a'                NB. Shape of an atom is empty

   # $ 'a'              NB. Rank is 0
0

   $ ,'a'               NB. Converted to a list, it has shape 1
1
   # $ , 'a'            NB.  ...and rank 1
1

Common uses

1. Convert atoms to singleton lists, for example in boxed strings.

   ]a =: ;: 'this is a list of strings'
+----+--+-+----+--+-------+
|this|is|a|list|of|strings|
+----+--+-+----+--+-------+
   ]z=: 'this' ; 'is' ; 'a' ; 'list' ; 'of' ; 'strings'
+----+--+-+----+--+-------+
|this|is|a|list|of|strings|
+----+--+-+----+--+-------+

   a -: z          NB. unexpectedly, a and z don't match!
0
   $ each a        NB. inspect the string-lengths inside each box of a
+-+-+-+-+-+-+
|4|2|1|4|2|7|
+-+-+-+-+-+-+
   $ each z        NB. The third word in z was an atom, not a list
+-+-++-+-+-+
|4|2||4|2|7|
+-+-++-+-+-+
   z =: , each z   NB. Make all items of z into boxed lists
   a -: z          NB. Now a and z do match
1

2. Remove the structure of an array, to view it better as a set of atoms

   ]a =: 4 4 ?@$ 100
90 47 58 29
22 32 55  5
55 73 58 50
40  5 69 46

   +/ 50 < , a     NB. How many numbers are greater than 50?
7

Use These Combinations

Combinations using , y that have exceptionally good performance include:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Operations on a flattened array x ({ ,) y

x ({. ,) y
x (}. ,) y
x (e. ,) y
f/@, y
(f is any verb)

or @: & &: in place of @ Avoids copying the array to compute (,y)
Reshape to exactly x x ($ ,) y Supported as a primitive by ($ ,)"n


x , y Append

Rank Infinity -- operates on x and y as a whole, after adjusting the smaller operand -- WHY IS THIS IMPORTANT?


Creates an array containing the items of x followed by the items of y .

If x and y are atoms or lists, x,y is simply a list made up of x followed by y

   z=: i.6

   z,99
0 1 2 3 4 5 99
   99,z
99 0 1 2 3 4 5
   z , 99 100
0 1 2 3 4 5 99 100

Related Primitives

Append Items (x ,. y), Laminate (x ,: y), Raze (; y)


More Information

1. If the items of x and y have the same shape,  x,y is an array which is the list of those items in the sequence they appear in first x then y .

   ]a =: i. 2 3
0 1 2
3 4 5
   ]b =: i. 3 3
0 1 2
3 4 5
6 7 8
   a , b   NB. All items are 3-atom lists
0 1 2
3 4 5
0 1 2
3 4 5
6 7 8

2. (x,y) is the same as  ;(<x),(<y) . If the items of x and y have different shapes, see the detailed description in Raze (;).

where the "contents" referred to are the values of x and y

   2 , i. 3 3   NB. all is explained in the detailed description
2 2 2
0 1 2
3 4 5
6 7 8

3. Use (,!.f) to specify the fill atom. See the detailed description in Raze (;).


Use These Combinations

Combinations using x , y that have exceptionally good performance include:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Combine first 2 axes (axes 0 and 1) ,/ y linear time
Join contents of boxed items along first axis ,&.>/ y Bug warning: Atomic replication is inaccurate. OK if contents of same rank. Better to use <@; y
Reshape infixes x ]\ y [ , in place of ]
Append in place not boxed, extended integer, or rational name =. name,expression =: in place of =.

the append must not increase the size of an item
Must be same name either side.

appends to the existing name usually