{ω×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:
A dfn releases each local name after the last statement that reads it, so the name no longer holds its array for the rest of the call. If that array is the result of a call that waits and nothing else holds it, the call then runs together with the calls that read its result, and the result is never stored. A dfn whose text contains ⍎ keeps all its names, because the text that ⍎ evaluates can read any of them:
⍎ that comes from outside the dfn’s text, as an operand or through a name bound outside the dfn, can’t read a name after its last read. It raises VALUE ERROR: “a has no value after its last read in the 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 can be read in later bodies:
Every body but the last needs a predicate. If every predicate fails, the call raises 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 of an absent α, such as x←α or α as an operand, raises a VALUE error.
α← gives α a default, because the assignment runs only when α is absent:
Valences ⊘ joins a monadic function and a dyadic function into one.
∇ calls the current dfn. This dfn computes 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 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 catches errors of the named kinds in any statement or body after the guard. When it catches an error, the dfn returns handler. ÷"a" raises a DOMAIN error:
∞:: catches every kind except INTERRUPT, TIMEOUT and UNSUPPORTED. In the handler, $e is the caught error, as a record. $e.message says what went wrong:
•signal raises an error of the kind on its right, with a message on its left. The kind can be any one-word name that the program chooses, and a guard catches it by that 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, any statement other than an assignment returns at once, so 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 and block headers. BPL uses Valences to choose a function by argument count. The review finds that BQN’s rule for 𝕨, which BPL adopts, makes ambivalent code easier to write than tacit combinators do.
The review would also prefer not to determine what a block defines from the special names in its body. BPL still does so. 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.