Empty Array

From J Wiki
< Help(Redirected from Help/Primer/Empty Array)
Jump to navigation Jump to search


<=   =>

An array is empty if it contains no atoms. An empty array has a 0 in its shape.

   a =. 0 $ 0	NB. empty list
   $a
0
   $ ''	NB. empty list
0
   b =. 2 0 3 $ 'a'	NB. empty rank 3 array
   $b
2 0 3


Empty arrays have no atoms to display and their display can be confusing if you don't know what to expect. An empty list displays as a blank line. A table with 0 rows displays as 0 lines; a table with 3 rows, but 0 columns, displays as 3 blank lines.

   2 $ 5
5 5
   1 $ 5
5
   0 $ 5	NB. empty list displays as blank line
   2 2 $ 5
5 5
5 5
   1 2 $ 5
5 5
   2 0 $ 5	NB. 2 rows displays 2 lines


   0 2 $ 5	NB. 0 rows displays 0 lines


The display of lists and tables with 1 row can look the same, and you have to look at their shape to distinguish them.

   a =. 2 $ 5
   b =. 1 2 $ 5
   a
5 5
   b		NB. b displays the same as a
5 5
   $ a
2
   $ b		NB. but b has a different shape
1 2


<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106