Vocabulary/curlylfco

From J Wiki
Jump to: navigation, search

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

{: y Tail

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



The last item of y

   {: 'abc'
c

Common uses

1. Convert a single-item list y into an atom

   {: 'abc'
a

2. More generally, take the last item of array y, producing an array of lower rank

   ]z =: i. 3 4
0 1  2  3
4 5  6  7
8 9 10 11
   {: z
8 9 10 11

3. When applied on a list, e.g. the rows of a table, take the last atom on each row

   {:"1 z
3 7 11

Related Primitives

Head ({. y), Behead (}. y), Curtail (}: y)


More Information

1. Unless y is an atom, the rank of {: y is 1 less than the rank of y. This is different from _1{.y which is a list of items of y (and therefore has the same rank as y unless y is an atom).

({: y) is equivalent to (0 { _1 {. y)

   ]z =: i. 3 4
0 1  2  3
4 5  6  7
8 9 10 11
   {: z
8 9 10 11
   _1 {. z     NB. they look the same...
8 9 10 11
   $ {: z
4
   $ _1 {. z   NB. ...but they have different shapes
1 4

2. If y has no items, {: y produces an item of fill atoms. {:!.f sets the fill atom, which by default is the fill appropriate for the type of y. See Head for examples.