Selecting without { (from)

From J Wiki
Jump to navigation Jump to search


<=   =>

Some situations where you could use { (from) are so common that they have their own primitives. These primitives are not dealt with in any detail here, and are mentioned so that you are aware of them and can look up their definitions and make use of them in your own work. They are shown here by example.

The monad {. (head) takes the first item of its argument and is similar to { with a left argument of 0.

   {. 5 6 7
5
   {. i. 3 4
0 1 2 3


The monad {: (tail) takes the last item of its argument and is similar to { with a left of _1 (oh yes, forgot to mention earlier that negative indexes simply index from the end of the axis).

   {: 5 6 7
7
   {: i. 3 4
8 9 10 11


The monad }. (behead) drops the first item of its argument.

   }. 5 6 7
6 7
   }. i. 3 4
4 5  6  7
8 9 10 11


The monad }: (curtail) drops the last item of its argument.

   }: 5 6 7
5 6
   }: i. 3 4
0 1 2 3
4 5 6 7


The dyad {. (take) takes the indexes from axes as indicated by the left argument.

   3 {. i. 8
0 1 2
   2 3 {. i. 3 4
0 1 2
4 5 6
   2 {. i. 3 4
0 1 2 3
4 5 6 7


The dyad }. (drop) drops the indexes from axes as indicated by the left argument.

   1 }. 2 3 4
3 4
   1 2 }. i. 3 4
 6  7
10 11


An interesting way to think of {., {:, }. and }: is that they are indexing corners of the array.

One capability that the dyad {. has that is not so directly related to from is it can create an array that is larger than the selected corner. It does this by filling in with 0, ' ', or a: as appropriate.

   5 {. 5 6 7
5 6 7 0 0
   4 5 {. i. 2 3
0 1 2 0 0
3 4 5 0 0
0 0 0 0 0
0 0 0 0 0
   5 {. 'abc'   
abc  
   <"0 [ 5 {. 'abc'	NB. make sure they are there
+-+-+-+-+-+
|a|b|c| | |
+-+-+-+-+-+
   7 {. (<"0) 5 {. 'abc'	NB. fill with a:
+-+-+-+-+-+++
|a|b|c| | |||
+-+-+-+-+-+++ 


The dyad # (copy) is also fairly directly related to from. Its left argument is a list of how many times to repeat the corresponding item from the right argument.

   3 2 1 2 3 # 'abcde'
aaabbcddeee

The above is equivalent to the following:

   0 0 0 1 1 2 3 3 4 4 4 { 'abcde'
aaabbcddeee


<=   =>

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