⌽"trams""smart"
Read Searching and indexing first.
⌽ (Circle Stile)⌽ (Reverse)Reverse puts items in the opposite order along the last axis. On a matrix, it reverses each row:
Reverse undoes itself: its inverse is Reverse again.
⌽ (Rotate)Rotate turns left for a positive count and right for a negative count. Items that leave one end return at the other.
With a vector of counts, Rotate can turn each row by a different amount:
The inverse of Rotate turns in the opposite direction, using the same count:
⌽₀ (First-axis reverse and rotate)⌽₀ (Reverse First)The subscript selects an axis: ⌽₀ acts along the first, while ⌽₋₁ acts along the last, as plain ⌽ does. A vector has only one axis, so these give the same result there. On a matrix, ⌽₀ reverses or rotates the rows.
Reverse First also undoes itself:
⌽₀ (Rotate First)The inverse of Rotate First reverses the rotation, using the same count:
⍉ (Circle Backslash)⍉ (Transpose)Transpose reverses the order of the axes. A matrix’s rows become its columns:
A 2 3 4 array becomes a 4 3 2 array:
Transpose undoes itself too:
Write the superscript ᵀ after an array to apply monadic Transpose. It is for arrays, not functions. Like the digit superscripts, it is applied before functions. After a space it applies to the whole run on its left:
Without a space, Index reads row 1 of the transpose. With a space before ᵀ, it first reads row 1, then transposes that vector:
⍉ (Transpose)Each item on the left gives the destination of the corresponding input axis. With 1 0, Transpose sends the rows to axis 1 and the columns to axis 0:
A diagonal holds the items at matching positions along two axes: row 0 with column 0, row 1 with column 1, and so on. Sending two axes to the same destination selects their diagonal. The diagonal is as long as the shorter axis:
On a rank-3 array, Transpose with 1 0 2 swaps the first two axes. Repeated destinations again select diagonals:
Inverting a diagonal with ⁻ raises a DOMAIN error. When each axis has a different destination, ⁻ restores the original axis order:
A nested item in the left argument splits one input axis into several axes. Here the last axis of length 8 becomes two axes of lengths 2 and 4, named "group" and "offset". Each pair in the nested item gives a destination axis and a length. Use ∞ for the length needed to keep the number of items unchanged. The key on the group, "packed", names the axis when it is merged back:
["batch":2 "group":2 "row":3 "offset":4]ₓ
The inverse form, ⍉⁻, lists input axes in output order. A nested group merges its axes into one. This puts the group and offset axes together again:
split has numeric destinations, so split⁻ merges the split axes back into their original axis:
A ⍉⁻ pattern that uses names does not record the previous axis order, so it cannot be inverted with ⁻.
⌺ (Quad Diamond)⌺ (Stencil)A window is a section of an array around one position. Stencil applies its left operand to each window, with that position at the centre. Its right operand gives the window’s size. At the edges, Stencil replaces missing items with fill, which is zero for these numeric arrays. Enclosing each window shows what the operand receives:
Replace enclosure with summation to add the neighbours:
With two sizes, Stencil uses a rectangular window. Here we sum each three-by-three window:
In a two-row specification, the first row gives the window sizes and the second gives the movements, the distances between window centres. This uses three-item windows centred two positions apart:
⊘ (Valences)A function’s valence is the number of arguments it takes. Valences supplies separate functions for calls with one and two arguments. This function negates with one argument and adds with two:
The inverse selects a function by the number of arguments, then applies that function’s inverse. Here it negates with one argument and subtracts the fixed left argument with two:
@ (Under)f@g applies f to the selection that g makes, then writes the result back to the selected positions. The other items stay unchanged. Under selects along the first axis when its right operand is a list of positions. A value as the left operand replaces the selected items:
÷ᵣ gives rational reciprocals of machine integers, whereas ÷ would floor them. Positions 1 and 3 hold 2 and 4, whose reciprocals are 1ᵣ2 and 1ᵣ4:
A function inside a one-item list selects where its result is true. Here 2| marks the odd numbers:
A selecting function can also be Under’s right operand. Drop skips the first item; Under changes only the rest:
With an invertible transformation as its right operand, Under transforms, applies its left operand, then reverses the transformation. To round down to tenths, multiply by ten, floor, then divide by ten:
.[I] on its own is a selector function, which Under can take as its right operand. Here the selected positions are multiplied by ten. With a field selector such as ⊢.qty, Under changes just that field:
Under’s inverse keeps the selection and applies the inverse of its left operand. This decrements the selected items:
⍚ (Agenda)Agenda chooses a function from its right operand, a list of cases. Its left operand gives the position of the case to run, or a function that computes that position. Agenda runs case 0 for a false Boolean and case 1 for a true one:
With a vector of choices, Agenda picks one case for each cell. Here negative numbers become zero, while nonnegative numbers are replaced with their square roots:
⍎ (Hydrant)⍎ (Execute expression)Execute reads a string as code and returns its last result. The string can refer to names already defined here.
The results of intermediate statements are still displayed, even when the last result is assigned. This prints 2 and stores 4 in answer:
Execute’s inverse writes a value as BPL source text that Execute can read back. The source text keeps the ₓ that marks exact integers:
⍎ (Execute in)A keyed left argument supplies names for the expression:
⍕ (Thorn)⍕ (Format)Format turns values into text. The numeric vector and its character representation are displayed alike:
The vector has three numbers; the text has five characters, including its two spaces:
With a single number on the left, Format uses that many decimal places, the digits after the decimal point:
⍕ (Format By Specification)A two-item vector gives the field width and decimal places. The width is the number of characters for each number, padded with spaces:
Indexing covers more selections, and each entry in the glyph reference links to its full definitions.
Previous: Searching and indexing · Study guide · Next: Numerical tools