Vocabulary/commadot

From J Wiki
Jump to navigation Jump to search

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

,. y Ravel Items

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


Creates a table where each row of the table comes from an item of y.

Converts an atom to a (1-by-1) table

   $ ,. 'a'
1 1

Converts a list to a 1-column table

   ] ,. i.3
0
1
2

Converts a table to itself (i.e. unchanged)

]   z=: 3 4 {. i. 2#10   NB. self-indexing table
 0  1  2  3
10 11 12 13
20 21 22 23
   z -: ,.z
1

Converts an array of rank 3 or higher to a table

]   z=: 2 3 4 {. i. 3#10   NB. self-indexing brick
  0   1   2   3
 10  11  12  13
 20  21  22  23

100 101 102 103
110 111 112 113
120 121 122 123
   ,.z
  0   1   2   3  10  11  12  13  20  21  22  23
100 101 102 103 110 111 112 113 120 121 122 123

Common Uses

1. Arrange the atoms of a list of boxed strings vertically for easier reading

   d
+------------------------------------------+--------...
|The curfew tolls the knell of parting day,|The lowi...
+------------------------------------------+--------...
   ,. d
+-------------------------------------------+
|The curfew tolls the knell of parting day, |
+-------------------------------------------+
|The lowing herd wind slowly o'er the lea   |
+-------------------------------------------+
|The ploughman homeward plods his weary way,|
+-------------------------------------------+
|And leaves the world to darkness and to me.|
+-------------------------------------------+

Related Primitives

Ravel (,)


More Information

1. When y is an array,  ,.y applies Ravel (,) to each item of y — which gives the monad (,.) its name.


x ,. y Stitch

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


Joins each item of x to the corresponding item of y

   x ; y =: toupper x=: 3 5 $ 97}.a.
+-----+-----+
|abcde|ABCDE|
|fghij|FGHIJ|
|klmno|KLMNO|
+-----+-----+
   x ,. y
abcdeABCDE
fghijFGHIJ
klmnoKLMNO

If x or y is an atom, it is appended to each item of the other

      x ,. '/'
abcde/
fghij/
klmno/
      '\' ,. y
\ABCDE
\FGHIJ
\KLMNO

Common uses

1. Create a two-column table from two lists, or from a list and an atom

   1 2 3 ,. 5 6 7
1 5
2 6
3 7
   1 2 3 ,. 4
1 4
2 4
3 4
   10 ,. 1 2 3
10 1
10 2
10 3

2. Attach an index column to a table

   ]z=: 5 3 {. i.10 10   NB. sample noun
 0  1  2
10 11 12
20 21 22
30 31 32
40 41 42
      (_ ,. z) ,.~ i. #z    NB. uses (_) as a column separator
0 _  0  1  2
1 _ 10 11 12
2 _ 20 21 22
3 _ 30 31 32
4 _ 40 41 42

3. Prefix a space (or other character) to each line of a literal table

   ] z=: > ;: 'this is a matrix'
this
is
a
matrix

   ' ' ,. z
 this
 is
 a
 matrix

Related Primitives

Append (,), Laminate (,:), Raze (;)


More Information

1.  x ,. y is exactly equivalent to  x ,"_1 y .


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 axes 1 and 2 ,./ y linear time
Join contents of boxed items along axis 1 ,.&.>/ y