# Vocabulary/curlylfcoco

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

`{:: y`Map

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

Returns a *map* of the boxed noun `y`,
i.e. a noun having the same box structure as `y` but with each leaf replaced by a path to that leaf.

- A leaf is a noun that is empty or unboxed; i.e. one that has no contents
- A path describes a sequence of selection and unboxing that leads to part of a noun,

as defined by Fetch (`x {:: y`).

NB. Choose a standard library function, e.g. `boxxopen_z_` to yield a sample box structure ... ] y=: 5!:2<'boxxopen' +-+--+--------------+ |<|^:|+--+-+-------+| | | ||L.|<|+-+-+-+|| | | || | ||*|@|#||| | | || | |+-+-+-+|| | | |+--+-+-------+| +-+--+--------------+ {:: z +---+---+---------------------------------------+ |+-+|+-+|+-----+-----+-------------------------+| ||0|||1|||+-+-+|+-+-+|+-------+-------+-------+|| |+-+|+-+|||2|0|||2|1|||+-+-+-+|+-+-+-+|+-+-+-+||| | | ||+-+-+|+-+-+|||2|2|0|||2|2|1|||2|2|2|||| | | || | ||+-+-+-+|+-+-+-+|+-+-+-+||| | | || | |+-------+-------+-------+|| | | |+-----+-----+-------------------------+| +---+---+---------------------------------------+

Each leaf has been replaced by its path.

### Oddities

1. `{:: y` does not produce a path for a leaf that contains an empty array of boxes.

`x {:: y`Fetch

Rank 1 _ *-- operates on lists of x and the entirety of y --*
WHY IS THIS IMPORTANT?

(`x {:: y`) extracts the contents of a box is a boxed structure. It gives the box(es) inside noun `y` having the path `x`

If the path specifies a single box, the result is the **contents** of that box

]y =. 1 2;3 4;5 6 7 +---+---+-----+ |1 2|3 4|5 6 7| +---+---+-----+ 1 {:: y 3 4 ] y=: 5!:2<'boxxopen' +-+--+--------------+ |<|^:|+--+-+-------+| | | ||L.|<|+-+-+-+|| | | || | ||*|@|#||| | | || | |+-+-+-+|| | | |+--+-+-------+| +-+--+--------------+ 2 {:: y +--+-+-------+ |L.|<|+-+-+-+| | | ||*|@|#|| | | |+-+-+-+| +--+-+-------+ (2;0) {::y L. (2;2) {::y +-+-+-+ |*|@|#| +-+-+-+ (2;2;1) {::y @ (0,:1) {:: y < ^:

`x {:: y` can be used when `x` and `y` are unboxed, to perform simple indexing into `y`

5 6 {:: i. 10 10 NB. Fetch row 5 column 6 56 (<5 6) { i. 10 10 NB. This is the other way to do that 56

x {:: yfetches portions of a boxed structure. There is no corresponding primitive to modify a portion of a boxed structure.x m}:: yis reserved for that purpose, planned to operate along the lines ofx m} y, but it is unimplemented. If you want to modify internal portions of a multilevel boxed noun, look at utilities for amending boxed structures.

### Common Uses

1. To select and open a single box from a list of boxes

]a =: 'zero';'one';'two';'three' +----+---+---+-----+ |zero|one|two|three| +----+---+---+-----+ 2 {:: a two

For this purpose `x {:: y` is faster than the equivalent `> x { y`.

2. To select from a deep structure

]a =: 'zero';'one';('two point zero';'two point one');'three' +----+---+------------------------------+-----+ |zero|one|+--------------+-------------+|three| | | ||two point zero|two point one|| | | | |+--------------+-------------+| | +----+---+------------------------------+-----+ (2;1) {:: a two point one

3. To perform multidimensional indexing, when `x` is unboxed (equivalent to `>^:('' -.@-: $) (<x) { y`, in other words select from `y` using `x`, and then open the result if it is not an atom)

2 1 3 {:: i. 10 10 10 NB. coordinates for each axis 213 2 1 {:: i. 10 10 10 NB. omitted trailing axes are taken in full 210 211 212 213 214 215 216 217 218 219 1 2 {:: i. 3 4 NB. selection of an atom 6 1 2 {:: <"0 i. 3 4 NB. if the atom is boxed, it is opened 6 1 2 {:: i. 3 4 5 NB. selection of multiple atoms 30 31 32 33 34 1 2 {:: <"0 i. 3 4 5 NB. they are not opened +--+--+--+--+--+ |30|31|32|33|34| +--+--+--+--+--+

4. To select subarray

]A =: 'abcde' ; 10 + i. 2 4 +-----+-----------+ |abcde|10 11 12 13| | |14 15 16 17| +-----+-----------+ (0 ; << 1 2 3) {:: A NB. selection of a subvector bcd (0 ; <<< 1 2 3) {:: A NB. additional boxing excludes indices ae (1 ; 0 1) {:: A NB. selection of a scalar from subarray 11 (1 ; < 0 ; 1) {:: A NB. the same as above 11 (1 ; < 0 1 ; 1 2) {:: A NB. selection of a submatrix 11 12 15 16

### More Information

The path is defined by its effect on ` x {:: y `.

The path is a list of boxes which are processed one by one, as follows:

- If
`x`is empty or unboxed, it is put into a single box before the following is executed; that is, unboxed or empty`x`is processed as`<x`. -
`selectedy =: y`initializes the noun being searched - Then, for each box of
`x`:

]a =: 'zero';'one';('two point zero';'two point one');'three' +----+---+------------------------------+-----+ |zero|one|+--------------+-------------+|three| | | ||two point zero|two point one|| | | | |+--------------+-------------+| | +----+---+------------------------------+-----+ (<0) {:: a NB. 0 means item 0 along the first axis zero (<,0) {:: a NB. ...still means that zero (<<0) {:: a NB. ...still means that zero (<<,0) {:: a NB. ...now it is a list of items (length 1), so not unboxed +----+ |zero| +----+ $ (<<,0) {:: a 1 NB. The same rules apply when going down into the structure ((<2),(<<0)) {:: a two point zero ((<2),(<,0)) {:: a two point zero ((<2),(<<,0)) {:: a +--------------+ |two point zero| +--------------+ ((<2),(<<0 1)) {:: a +--------------+-------------+ |two point zero|two point one| +--------------+-------------+ NB. Often ; is used to build x. Remember, x;y always boxes x, but y only if not already boxed (2;,0) {:: a two point zero (2;<,0) {:: a two point zero (2;<<,0) {:: a +--------------+ |two point zero| +--------------+

### Details

1. If `x` is unboxed, it is first boxed before being used as the path.

0 1 {:: i. 2 3 Same as (<0 1) 1

It follows that the only way to use `{::` when `y` is an atom is to have an empty selector, that is `x` is an unboxed empty list or `a:`.

If `x` is a boxed empty list (`0$a:`), the result is always the same as `y`; if `x` is an unboxed empty list the result is
`y` except that if `y` is an atomic box, it is opened.

0 { 1 NB. 0 { atom is allowed 1 0 {:: 1 NB. ... but 0 {:: atom is not (it selects using (<0) which selects from the first axis |length error | 0 {::1 '' {:: 1 NB. empty selector is OK, It's like (<'') which takes all axes in full 1 a: {:: 1 NB. this is equivalent 1

2. If any selection other than the last selects an array, J signals `rank error` .

((<<0 1),(<'')) {:: a NB. Can't follow more than one selection path |rank error ((<<0 1)) {:: a NB. But may end with multiple leaves +----+---+ |zero|one| +----+---+

### Oddities

1. The definition of `fetch` in the J Dictionary does not conform to the operation of `x {:: y` as described above.