From J Wiki
Jump to: navigation, search

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

}. y Behead

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

Drop the leading item from y

   }. 'abc'

Related Primitives

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

More Information

1.  }.y is equivalent to  1 }. y .


1. The rank of  }.y is the same as the rank of y unless y is an atom, in which case  }.y is an empty list (with the same type as y).

2. If y has no items,  }.y is the same as y.

x }. y Drop

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

Drop the leading x items of y

if x is negative, the trailing x items are dropped

   2 }. 'abcde'
   _2 }. 'abcde'

Common uses

1. Remove data from a list

   datatosend =: sentlength }. datatosend   NB. remove sent data from the send queue
   21 }. 'This is sentence 1.  This is sentence 2.'
This is sentence 2.

2. (With Take {.) Chop out an interval from a list

C/f MID$ in BASIC, substr() in other languages

   az=: 'abcdefghijklmnopqrstuvwxyz'
   3 {. 5 }. az

Subarray ];.0 is a better way to do this.

3. (With Take {.) Split a list into head and beheaded list

   split   NB. defined in stdlib as...
{. ,&< }.
   lst=: 'abcde'
   2 split lst
   'hd lst'=: split lst
   hd ; lst

split is a

  • Standard Library word(s) residing in the 'z'-locale.
  • Defined in the factory script stdlib.ijs.
  • View definition(s) by entering in the J session:  open'stdlib'

Related Primitives

Take (x {. y)

More Information

1. If x is a list, each atom of x specifies a drop operation along the corresponding axis of y

   ]a =: _4 ]\ 'abcdefghijkl'
   _1 1 }. a   NB. Drop the last row, and the first column


1. When x is a list, axes of y beyond the length of x are taken in full.

2. If y is an array, x must not be longer than the rank of y

   2 3 {. i. 4
|length error

4. If y is an atom, it has leading axes of length 1 added to bring its rank up to the same as the length of x, and then the drop operations are applied.

5. If x is empty then  x }. y is the same as y. This is the only way that the result of  x }. y can be an atom.

6. In accordance with the description above, values in x that are larger than the length of the corresponding axis cause all atoms to be dropped, leaving an empty array

Infinity (_ or __) are valid values in x for this purpose

   $ _ }. i. 4 5
0 5