Array notation

, abbreviated APLAN parallel to JSON, is a way to write most arrays literally, with no or minimal use of primitive functions, possibly over multiple code lines. It differs from the strand notation existing since APL\360 in that it can be used to write arrays of rank greater than one. Array notation is supported in dzaima/APL, BQN (using angle brackets  instead of round parentheses  ), and some tools for Dyalog APL, where it is planned as an eventual language feature.

Array notation generally consists of a vector notation written with parentheses, roughly equivalent to stranding, and a high-rank notation using square brackets  , indicating the Mix of a vector. It also supports namespaces, using  syntax in round parentheses. Statement separators must appear between elements and between name–value pairs.

Examples
Medium-sized array constants are often needed in code. Due to the lack of a native multi-line notation, programmers have resorted to various ad-hoc methods of approximating such, usually at the cost of reduced readability. A very common technique is repeated concatenation resulting in the desired value being held in a variable ( in the below examples), as opposed to array notation which can express the final value directly. In addition, the traditional technique sometimes involves the creation of helper variables as a side effect.

Specification
The notation consists of syntax that was invalid before its introduction, thus causing no issues for backwards compatibility. The added syntax consists of three constructs that are currently SYNTAX ERRORs:


 * broken round parentheses: …
 * broken square brackets: …
 * empty round parentheses:

where broken means interrupted by one or more diamonds or line breaks (outside of dfns).


 * A broken round parenthesis creates a namespace if every diamond/line break-separated statement is a name-value pair.
 * A broken round parenthesis creates a vector if every diamond/line break-separated statement is a value expression. In that case, every such statement forms an element in the resulting vector.
 * A broken square bracket creates a an array where every diamond/line break-separated statement forms a major cell in the resulting array.*
 * creates a new namespace — equivalent to
 * A name-value pair consists of a valid APL identifier, followed by a colon and a value expression.

* This rule is followed strictly in dzaima/APL, while Dyalog APL considers each statement to have a rank of at least 1, even if it is a scalar.

Formal syntax
The array notation can be described using Extended Backus–Naur form, where an  is any traditional APL expression: value   ::= expression | list | block | space list    ::= '(' ( ( value sep )+ value? | ( sep value )+ sep? ) ')' block   ::= '[' ( ( value sep )+ value? | ( sep value )+ sep? ) ']' space   ::= '(' sep? ( name ':' value ( sep name ':' value )* )? sep? ')' sep     ::= [⋄#x000A#x000D#x0085]+

History

 * See also the Array notation design considerations

One-dimensional list syntax with surrounding brackets and delimiters, matching sequence notation in mathematics, is common in programming. It appears as early as ALGOL 68 with parentheses, and square-bracket lists feature in languages from the 1970s such as ML and Icon. MATLAB uses matrix syntax with square brackets, semicolons to separate rows, and commas to separate elements within a row. FP uses angle brackets for lists, and square brackets for function "construction", with behavior like function arrays.

List notation appears in Nial using brackets and commas like, and allowing function arrays called "atlases". A+ and K have a list notation using parentheses and semicolons like. In A+ this is related to bracket indexing and an "expression group" notation written with curly braces and semicolons. It allows line breaks, but in addition to rather than in place of semicolons. The later K version corresponds more closely to APL: the semicolon is a statement separator and is interchangeable with a line break, and because K represents arrays with nested lists, it corresponds to both vector and high-rank array notation.

The first published proposals that influenced Dyalog APL's array notation were made by Phil Last at Dyalog '15 and later in Vector Journal. Last cited the syntax of dfns as a sequence of expressions with enclosing braces, as well as APL's namespace notation enclosed in double brackets, as precursors. He also used the design in Acre Desktop, a project manager for Dyalog APL, to support storing constant arrays and namespaces in text files. Following the conference presentation, Adám Brudzewsky began work on array notation and presented on it in a series of conferences, initially using parentheses for the high-rank notation and later returning to square brackets. Because Last's use of  to separate namespace keys from values prevented lists from including arbitrary expressions (which might contain assignment), he proposed a change to   as in JSON. Dyalog APL 18.0, released in 2020, included support for array notation in source files loaded by Link, but not in the language itself.

The project manager Acre Desktop added support for the non-namespace parts of the notation in early 2018, together with Phil Last's original namespace notation, using square brackets and assignment arrow. dzaima/APL added support for vector notation with parentheses in 2018, namespaces and function arrays in 2019, and high-rank arrays with square brackets in 2020. BQN supported lists with angle brackets ( … ) in its initial implementation in 2020; square brackets ( … ) were reserved for high-rank array notation, which was implemented in 2022.

On April 21, 2023, Dyalog Ltd published a blog post by Morten Kromberg announcing to the community the formal proposal for an APL array notation and by May 5, the specification for scoping in namespaces was changed due to feedback from Dyalog Ltd employee Peter Mikkelsen: Assignments inside value expressions would now affect the surrounding scope rather than having dfn-like auto-localisation, which can instead be achieved by wrapping the expression in an anonymous dfn.

Documentation

 * BQN (as,  , and  )
 * Nial (as  for vectors)