x←10
[x ≥x "hi"]10 11 "hi"
BPL has two kinds of value. Numbers, characters and functions are atoms. An array is a rectangular collection of values, including other arrays. This is the based array model, named in a 1981 paper and popularized by BQN.
Write a vector by putting its items in brackets, separated by spaces. An item can be any expression without a space in it, such as a number, a name, ≥x or a string:
A bracket list is a vector, however many items it has. ρ shows that [5] has one axis of length 1, whereas the number 5 has no axes:
You can omit the brackets around a list of literals. Values written side by side form a strand, the same vector as the bracket list:
Names side by side form a strand too:
Matrices are written in brackets too, one row per line. Types of brackets covers this array notation, along with what ; and ◇ mean inside brackets:
An array’s shape lists the lengths of its axes. Its rank is the number of axes, the tally of its shape. Scalars, vectors and matrices are the arrays of rank 0, 1 and 2. m has two rows and three columns:
ρ builds an array of any shape from the items on its right. ι6 counts from 0 to 5:
An axis can have length 0. This matrix has no rows and three columns:
, lists the items in row-major order:
An atom has no axes, and neither does a scalar, which is the array of rank 0. Enclose ⊂ gives a scalar holding its argument:
3 and ⊂3 are still different values. The scalar ⊂3 is an array with one position, holding the atom 3:
Enclosing always adds a layer, even around an atom. ≡ counts the layers:
⊂ encloses only subjects. For a function f, the scalar holding it is fˢ:
The items of an array can be arrays. This vector holds two vectors of different lengths:
↑ gives the first item. Each ¨ applies a function to every item, here Tally ≢:
n, a vector of vectors of numbers, has depth 2:
Arithmetic, Each and indexing on a scalar give a scalar, not the atom inside it:
Rank and the search functions work on whole cells instead, as Rank describes.
Every array has a prototype, the value that it supplies as fill: zero for numbers, a space for characters, and a filled copy of the first item for nested arrays. ↑ pads with fill when its left argument is greater than the length of its right argument:
An empty array keeps its prototype. First of 0ρn gives the fill of 1 2, the first item of n:
When results of different lengths are assembled into one array, the shorter ones are padded with fill. ≥ι counts from 1 up to its argument, and with ⁰ it runs once for each item, which gives one row per count:
Each keeps the results as separate items instead:
Keys label the positions along an axis. Write them with :, then pick an item by its key with a dot:
Axes can also have names. Pass Reshape a keyed shape to name the axes it builds. Axis keys covers keyed arrays in full:
An array can hold functions. fs is a vector of three functions:
Selecting an item gives back a function. A subscript selects one position. To call the selected function, name it first, as with any function that a call or a selection returns:
Pick ⊃, First ↑ and Index ⌷ with a single position also return stored functions. ↑⌽fs is the last function in fs:
A list can mix functions with other values, including a vector of functions as one item:
Successive Picks select items from successively nested arrays. Picking with an empty vector returns the right argument unchanged:
A dfn can return a function it selects. Agenda selects one and calls it in one step:
An array that holds a function as an item is callable. Each function is called with the whole arguments, and each other item is returned unchanged:
The results have the array’s shape and keys as their frame, as Rank’s results do. Calling a keyed array of aggregation functions gives a keyed result, and calling it through Rank gives one row of results for each row of its argument. Write Rank out as ⍤1 here, because stats¹ would raise the items of stats to a power:
["mean":2.8 "max":5]
mean max
2.666666667 4
5 9
Results of different shapes are padded with fill:
An array is callable only when one of its direct items is a function. Calling a scalar that holds a function, such as -ˢ, calls that function, and its empty frame adds no axis. An enclosed function array holds an array rather than a function, so (⊂fs) 2 is a strand:
A function array acts as a function only where a subject follows it. Elsewhere it’s an array, so ≢fs counts its items. Binding gives the rule, and Operators and operands says which operators call the array:
An array holds a function item as a reference to the function. Reshape, selection, catenation and the other structural functions move function items without running them. Display prints each function as its source. A native function with no source spelling, such as a generator’s roll, prints in ⟨…⟩. A function’s fill is the function itself:
Two functions match when they’re built from matching parts. A primitive matches itself, as does a derived function such as +/, however many times either is written. A dfn matches only itself. Two separately written {ω} don’t match, even though they do the same thing. Functions have no ordering, and Grade and Interval Index reject them.
A dfn can return a function. A function that a dfn defines in its body works only while the call that defined it is running. Returning such a function, or storing it anywhere that outlives the call, including inside an array or an empty array’s prototype, raises a DOMAIN error.
In Python, arrays of functions work as Callable functions describes.