Cut ;.
The ;. (cut) conjunction applies a verb to partitions of its argument. In discussing cut we will use the expression f =: u ;. n to give names to the various elements. The left argument of cut is the verb u that will be applied to partitions of the right argument of the derived verbf. The right argument of ;. (cut) is the noun n that indicates the kind of partitions.
Let's consider cases where n is 1, _1, 2, or _2 and where the derived verb is used monadically.
If n is 2 or _2, the items of the right argument are partitioned into arguments that end with the last item in the argument. The item that is used to mark the partitions is called the fret. A negative n indicates that the fret is not included in the partition. Each partition is passed to the verb u and the partial results are assembled into the final result.
cut2 =. < ;. 2
The definition of cut2 could be read as: box cut last.
cut2 'how now brown cow ' +----+----+------+----+ |how |now |brown |cow | +----+----+------+----+
In this example the items of the right argument are characters. The fret is the last character, which is a blank. The fret is used to break the entire argument into a series of arguments to which the verb < is applied. Visually:
< 'how ' (first partition) gives first partial result < 'now ' (next partition) gives next partial result < 'brown ' < 'cow '
The partial results are assembled into the final result.
<;._2 'how now brown cow ' +---+---+-----+---+ |how|now|brown|cow| +---+---+-----+---+
The cut2 boxed results include the fret and the <;._2 boxed results do not include the fret.
The following applies to the same partitions of the right argument, but applies the dyad # (tally) instead. This gives us the count of each partition.
#;._2 'how now brown cow ' 3 3 5 3
This applies in the same way to numeric data. In the following _1 is the fret.
a =. 2 3 4 _1 5 3 2 _1 23 45 65 132 _1 <;._2 a +-----+-----+------------+ |2 3 4|5 3 2|23 45 65 132| +-----+-----+------------+ #;._2 a 3 3 4 +/;._2 a 9 10 265
A 1 or _1 uses the first item as the fret. If positive, the fret is included in the result, if negative it is not included.
<;._1 'madam i''m adam' +---+---+----++ |ada| i'| ada|| +---+---+----++
Sometimes the partition information is separate from the data. Instead of frets in the data, the partition information can be provided in a left argument to the derived verb. The partition information is boolean data where a 1 indicates the start (with 1 or _1) or end (with 2 or _2) of the partitions.
1 0 0 0 1 0 0 <;.1 'abcdefg' +----+---+ |abcd|efg| +----+---+ d =. 'the test is the thing' 'the' E. d 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 ('the' E. d) <;.1 d +------------+---------+ |the test is |the thing| +------------+---------+
The example above uses a new primitive E. that you can look up in NuVoc if you want additional information at this time. However, without worrying about the details you should get the idea of what is happening.
Chopping up character lists into boxes is so useful that there is a standard utility called cutopen that handles many of the common cases. For example:
cutopen 'testing testing 1 2 3' +-------+-------+-+-+-+ |testing|testing|1|2|3| +-------+-------+-+-+-+
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 | ✅ |