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 can be chained:
Put independent assignments on separate lines, or put ◇ between them, because ← takes everything to its right:
_←Y evaluates Y and discards its value.
x f←Y sets x to x f Y:
Any function works, such as , to append:
To modify with a named function, write x⁝f←Y, which means x←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:
Assigning to a subscript target replaces the item at one literal position:
Use dot brackets to select any positions, in plain or modified assignment:
For any other selection, put the target in parentheses and use a function that only selects or rearranges, as for structural Under:
A dfn that returns items of its argument can be the selection too. A space before ← makes the whole run the target:
The selection can apply a function with rank. 0⌷¹ selects the first item of each row:
Assign to a dot path to write 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:
f⁻←g attaches g as the inverse of the function named by f. f⁻, negative powers and Under then call g:
f∂←g attaches g as the derivative of f, 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:
Calling the function still runs its original definition. Assigning an inverse does not change its derivative rule, and assigning a derivative does not change its inverse:
A list of names in brackets destructures a value by position:
Each name is assigned 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 destructures by key instead. Each cell of a pattern is a key, then the name that is assigned the key’s item, as in [a:x]. A cell with only a key, as in [a:], assigns 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. Use a string key, as in ["first name":n], when the key isn’t a valid 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:
An array is copied only when it is modified while another name or array holds it. Above, u₀←9 copies u first, because w holds it too. Assigning to part of an array that nothing else holds changes the array in place. x,←v and x⍪←v add to the end of the array’s storage. x←x,v always copies, because x still holds the old array while x,v is computed.