Vocabulary/curlyrtco

From J Wiki
Jump to navigation Jump to search

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

}: Curtail

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


Drops the last item from y

   }: 'abc'
ab

Common Uses

1. Remove the last atom from a list.

Drop unwanted final LF from otherwise convenient noun definition

   V=: 0 : 0
abc
def
ghi
)
   <V           NB. See the (non-printable) LF at the end of the boxed string
+------------+
|abc def ghi |
+------------+
   <}: V        NB. Delete it
+-----------+
|abc def ghi|
+-----------+

2. Remove the last row from a table

   ]t =: _2 ]\ 'Fred';20;'John';50;'Total';70
+-----+--+
|Fred |20|
+-----+--+
|John |50|
+-----+--+
|Total|70|
+-----+--+
   }: t
+----+--+
|Fred|20|
+----+--+
|John|50|
+----+--+

3. Applied at rank 1, remove the last item from each row of a table

   }:"1 i. 3 3
0 1
3 4
6 7

Related Primitives

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


More Information

0. A video lab has been produced for the Curtail monadic verb in both the JHS and jqt formats. The video can be viewed here in its complete form Curtail monadic verb complete video or as components Curtail monadic verb Part 1 and Curtail monadic verb Part 2

1.  }:y is identical to  _1}.y .


Details

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 then  }:y is the same as y .