x←3
x+25
← assigns the value to its right to the target, the run just before it. Besides plain names, a target can be a selection, a dot path, a subscript or a list of names. With a function just before ←, as in x+←1, the assignment is modified. For the exact rules, see Assign and Syntax.
x←Y binds x to Y and returns Y without displaying it:
A value can be a function, such as +/:
Assignments chain:
Put independent assignments on separate lines or between ⋄, because ← takes everything to its right:
The name _ discards a value. _←Y evaluates Y and keeps nothing.
x f←Y sets x to x f Y:
Any function works, such as , to append:
A named function goes in parentheses, as x(f)←Y. In x f←Y, the target would be f:
With nothing after the arrow, modified assignment applies the function to the target alone. x⌽← sets x to ⌽x:
A subscript target replaces one literal position:
Dot brackets name any positions, in plain or modified assignment:
Any other selection goes in parentheses, with a function that only selects or rearranges, as for structural Under:
The selection can apply a function with rank. 0⌷⍤1 selects the first item of each row:
A dot path writes a field of a record:
A plain assignment to a dot path creates any missing records along the path:
A subscript can follow a dot path:
A function’s name followed by ⁻¹ is a target for its inverse. f⁻¹←g attaches g as the inverse of the function f names. f⁻¹, negative powers and Under then call g:
f∂←g attaches g as the derivative, which ∂ and ⇄ call. g is a JVP rule: t g x gives the derivative of f at x along the direction t, and must be linear in t. ∂ calls g wherever it differentiates a call of f:
The function itself still runs when you call it, and each rule stays when you assign the other:
A list of names in brackets destructures a value by position:
Each name takes one major cell of a higher-rank value, such as one row of a matrix:
A single value goes to every name:
A nested list of names destructures a nested value:
Modified assignment works on a list of names too:
Inside brackets, every name is a target, even one that holds a function, such as f:
A list of names destructures by position even when the value has keys. A pattern takes items by key instead. Each cell of a pattern gives a key, then the name that takes the key’s item, as in [a:x]. A cell with only a key, as in [a:], gives the item to the name spelled like the key. A key is never a value: the a in [a:x] stands for the key "a", whatever a holds. A string key, as in ["first name":n], serves a key that isn’t a name. The cells can come in any order:
A program takes names from a module this way, as in [disp:]←•load "lib/array.bpl".
Inside a dfn, plain assignment makes a local name:
Modified and selective assignment, including assigning an inverse or derivative, update the nearest existing binding, even outside the dfn:
Arrays have value semantics, as numbers do: