{⍵×2}36
A dfn is a function written in braces. ⍵ is its right argument:
⍺ is its left argument:
A dfn returns the value of its last statement. Statements are separated by ⋄ or by line breaks:
The values of earlier statements are discarded:
A statement can run for its side effect alone, such as adding each item to a total:
A dfn that ends in an assignment returns the assigned value without displaying it:
Names follow lexical scope. Modified assignment, such as +←, updates the nearest binding of its name, looking outward through enclosing dfns to the top level:
Plain assignment always creates a name local to its dfn:
; separates a dfn’s bodies. A predicate C? tests the Boolean singleton C. When C is false, the dfn abandons the body and tries the next one. This dfn negates a negative number:
After a predicate, a body can hold several statements:
A name assigned in one body is still there in the next:
Every body but the last needs a predicate. If every predicate fails, the call is a DOMAIN error.
An empty body, such as {} or the first body of {⍵≡0?;⍵}, returns no result.
In a call with one argument, ⍺ is absent. An expression that uses an absent ⍺ is evaluated as if ⍺ weren’t there. Called with one argument, {⍺-⍵} negates:
Called with two, the same dfn subtracts:
Anything computed only from an absent ⍺ drops out with it:
In a list, an absent ⍺ leaves no item:
Any other use, such as x←⍺ or ⍺ as an operand, is a VALUE error.
⍺← gives ⍺ a default. The assignment runs only when ⍺ is absent:
Valences, ⊘, joins a monadic function and a dyadic function into one.
∇ calls the current dfn. This dfn is factorial:
A call to ∇ that is the last thing its body does reuses the current frame.
A dfn that uses ⍶, its left operand, is a monadic operator. twice applies its operand two times:
A dfn that also uses ⍹, its right operand, is a dyadic operator. This one applies ⍶ between ⍺ and ⍹ ⍵:
⍢ refers to the current operator, for recursion with new operands.
An error guard kinds::handler makes the dfn return handler when an error of one of the named kinds happens after it, in any later statement or body. ÷"a" raises a DOMAIN error:
In the handler, $e is the caught error, as a record. Its message says what went wrong:
•signal raises an error, with a message on its left. The kind can be the program’s own, and a guard catches it by name:
BPL’s dfns come from Dyalog APL, with three rules from BQN’s blocks: the last statement gives the result, predicates choose between bodies separated by ;, and an absent left argument drops out of the expression, as BQN’s 𝕨 does.
In Dyalog APL, a statement that isn’t an assignment returns at once. Running a statement only for its side effect needs a workaround.
Marshall Lochbaum’s five-year review of BQN’s design criticises two BQN features that BPL leaves out: choosing a body by argument count, which Valences covers in BPL, and block headers. The review finds that BQN’s rule for 𝕨, which BPL adopts, makes ambivalent code easier to write than tacit combinators do.
Unlike the review, BPL still lets special names decide what braces define. Braces whose body uses ⍶ or ⍹ define an operator. Other braces define a function.
Unlike a BQN block, a dfn keeps one scope across its bodies, as Dyalog APL’s guards do.