Open - monad >

From J Wiki
Jump to navigation Jump to search


<=   =>

The monad > (open) is the inverse of box. That is, it takes the contents out of a box. Applied to a noun that is already open it has no effect.

   > 23 5 7
23 5 7
   a =. i.5  
   a
0 1 2 3 4
   < a
+---------+
|0 1 2 3 4|
+---------+
   > < a
0 1 2 3 4


Look up > in NuVoc. The monad > has a rank of 0 so it applies to each atom in its argument. Each atom is opened, creating a partial result, that is then assembled with all the other partial results into the final result.

   a =. 1 2 3 ; 5 6 7
   a
+-----------+
|1 2 3|5 6 7|
+-----------+
   > a
1 2 3
5 6 7


The assembly of the partial results is straightforward if they all have the same rank and shape. But with open the partial results could have very different ranks and shapes.

   a =. 1 ; 2 3 ; 4 5 6
   a	
+-----------+
|1|2 3|4 5 6|
+-----------+
   > a
1 0 0
2 3 0
4 5 6


Each atom is opened and the partial results are extended to fit into the result frame.

> 1     gives	1	(atom) 
> 2 3  	gives	2 3	(list)
> 4 5 6	gives	4 5 6	(list)


The result frame has to have partial results that all have the same rank and shape. To do this, each partial result is extended to have the same rank as the rank of the highest rank result and a shape that is the maximum along any axis of all the partial results.

In the example above, the atom 1 is extended to a list and is padded with 0's to have a shape of 3. The list 2 3 is padded with a 0 to have a shape of 3. The 4 5 6 list is already OK. And the final result has a frame of 3 where each result cell is a list of 3 atoms.

What if the boxes contain characters?

   > 'abc' ; 'defg' ; 'hijkl'
abc  
defg 
hijkl

The result is a 3 by 5 table. The character partial results are extended in a similar manner, but blanks are used as fill, rather than 0. You cannot open a boxed list that contains both character and numeric data.

   > 1 2 3 ; 'asdf'
|domain error, executing monad >
|contents are incompatible: numeric and character
|       >1 2 3;'asdf'

There is no way to put the numeric and character partial results together in the frame so there is a domain error.

<=   =>

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