Skip to main content

Style

These forms make BPL easy to read for someone who doesn’t know APL. Choose the form that makes a line easiest to read. Resemblance to APL counts for nothing.

Use spaces to show the top-level structure of an expression. Keep parentheses where they make nested scope easier to see, as in α,(↓key_val,join),ω. Keep connected tokens in one run. Use ⁝ (Alt-:) where tokens must stay distinct without ending the run: h⁝m, +/⍠i⁝m. Two names that touch merge, as ix does in +/⍠ix. A name followed by a literal stays separate: f1 is f(1). Syntax gives the grouping rules.

Put a space on each side of a function between two runs, as in a×b + c. A space on one side only changes the grouping: a×b +c is the strand [a×b ; +c], and a×b+ c applies the train a×b+ to c.

⁝ separates a derived function’s operand from its right argument where a boundary is needed: f⍣3⁝0, 10÷√1++/⍠i⁝m, +/÷≢ ⍤1⁝2 3ρι6. It stops literal stranding without grouping the expression before it. A vector argument can touch the operand in brackets: ≥⍣2[1 2 3]. Add nothing where tokens already stay distinct, as in +/¹m or +/÷≢ ⍠d⊼n.

With a left argument as well, ⁝ works the same way, as in Q+.×⍠e⁝r. Parentheses can also separate a derived function from its arguments: 10 20(+⍤1)m. Use whichever reads better. Keep parentheses where a compound operand or nested train needs grouping, as in ⌊@(10×)x.

A space groups the whole run before it, including any prefix. +/÷≢ ⊼y-c+h+.×v applies the mean train to its complete argument. The space in mean_square←+/÷≢ ⊼ separates the atop’s subtrains, +/÷≢ and ⊼. f⁝g⁝h x keeps three named functions in one run. +/÷≢⁝v doesn’t group the mean train. For nested parentheses, try removing the inner pair first: (+⌿ N*Ms ÷ ≢N)*÷Ms. If a line uses a train twice, naming the train can make the line easier to read: mean¹m.

Lowercase j reads most clearly in complex literals, as in 3j4. Uppercase J is an input alias, used only in tests of that alias. Source kept from another project as a record, such as the original cases in the repo’s provenance/ files, keeps its original spelling. Array notation shows a literal matrix’s rows directly, as in [10 20 30◇40 50 60], whereas a reshape hides them. A reshape still suits an example about reshape. A ◇ between rows reads best with no spaces around it. A ◇ between statements reads best with a space on each side.

Brackets build a list from names or expressions. A bare literal list, such as 1 2 3, is a shorthand. In brackets, a list of names reads as a list at a glance, as in [a b], even when a b would also work. [n 2]ρ0, [x],y, [a◇b] and f¹m read more directly than APL’s (n,2)ρ0, (⊂x),y, ⊃[a b] and ⊃f¨↓m. When no item of a bracket list contains a space, prefer spaces to ; between items: [i j] rather than [i;j].

A run beginning with an operator takes the whole preceding run as its left operand. Use a space for a short function operand, as in ≢⊢ ⌸x or +/÷≢ ¹m. With two arguments, separate each part: K +/⊢ ⌸ Y. Keep parentheses where they show nested structure more clearly. A compound right operand keeps its grouping, as in ⌊@(10×)x. After a dyadic operator and a space, the whole next run is the operand, as in ⌊@ 10× x. When both operands are compound, parentheses around each show the grouping: (•ucs 9)@(⍸tabs)ω. An operand can keep its parentheses when a left argument comes before it, as in tree (α⍢)/ next. Report any case where none of these forms reads well.

A train reads more directly than naming an argument twice: +/÷≢ v rather than +/v ÷ ≢v. A tacit form usually reads more directly than a dfn. A dfn reads better when the tacit form would be longer or clearly awkward.

fib10 means fib 10, not an identifier, which would be fib_10. That form reads well when it’s shorter and needs no new parentheses. 32•float∞ converts ∞ to a 32-bit float, and needs none of the spaces in 32 •float ∞. 32 •float∞ gives the two items 32 64ₓ instead: the runs 32 and •float∞ strand, and •float∞ alone gives ∞’s width. When spaces separate names in a dyadic call, keep both spaces: x f 5 rather than x f5.

⌷ reads clearly for a selection, as in [⍋v]⌷v. Use numeric subscripts for literal positions, as in v₁, m₁ ₂ and v₁←0, and for literal axes, as in +/₁ and +/₂ ₃. Keep ⍠ for named or computed axes and options records. . suits other assignment targets, such as v.[i]←0, record fields, such as T.name, and places where ⌷ would be longer. For an assignment target that is a cross product of positions, use ⌷ with a spaced ←, as in [1 3;0 5]⌷a +←10. . pairs its index arrays instead: a.[1 3;0 5] selects only the items at positions 1 0 and 3 5.

Positions and counts are exact, while bare numbers are floats. Arithmetic that mixes the two gives floats. Under dynamic kinds, a write that mixes them leaves the array in mixed storage. ι10ₓ and ι≢x give exact positions, whereas ι10 gives floats. To keep an array of positions or counts exact, create it from exact numbers, as in nρ¯1ₓ, and start a counter at 0ₓ. On positions, ≥i, i+1ₓ and 2ₓ×i stay exact, whereas i+1 and 2×i give floats. +/÷≢ v floors for machine-integer inputs, stays rational for ᵣ inputs, and gives floats for float inputs. When a map’s branches give Booleans and numbers, convert the Booleans so that every result has one type: +b gives exact integers, and 1×b gives floats.