Array notation: Difference between revisions
m (→2016) 
m (add missing url) 

(34 intermediate revisions by 3 users not shown)  
Line 1:  Line 1:  
[[  { class=wikitable width=100% style=padding:"0 1em"  
! [[Dyalog Ltd]] requests community feedback on the array notation in the hope of ending up with a notation that is shared with other dialects.<ref>Dyalog Ltd/Adám Brudzewsky. [https://forums.dyalog.com/viewtopic.php?f=13&t=1856&p=7431#p7431 Re: Deserialise does it work as expected?]. Dyalog Forums. 20220905.</ref> Head to the [[Array notation design considerationsdesign considerations]] article for details!  
}  
{{BuiltinsArray notation(⋄)[⋄]}} is a way to write most [[array]]s literally, with no or minimal use of [[primitive function]]s, 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 <code>⟨⋄⟩</code> instead of round parentheses <code>(⋄)</code>), 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 <syntaxhighlight lang=apl inline>()</syntaxhighlight>, roughly equivalent to stranding, and a highrank notation using square brackets <syntaxhighlight lang=apl inline>[]</syntaxhighlight>, indicating the [[Mix]] of a vector. It also supports [[namespace]]s, using <syntaxhighlight lang=apl inline>name:value</syntaxhighlight> syntax in round parentheses. [[Statement separator]]s must appear between elements and between [[wikipedia:name–value_pairname–value pair]]s.  
== Examples ==  
Mediumsized array constants are often needed in code. Due to the lack of a native multiline notation, programmers have resorted to various adhoc methods of approximating such, usually at the cost of reduced [[readability]]. A very common technique is repeated [[concatenateconcatenation]]:  Mediumsized array constants are often needed in code. Due to the lack of a native multiline notation, programmers have resorted to various adhoc methods of approximating such, usually at the cost of reduced [[readability]]. A very common technique is repeated [[concatenateconcatenation]]:  
<  <syntaxhighlight lang=apl>  
poss←1 2⍴'fns' ((0 1)(0.7 0)(0.7 0)×size)  poss←1 2⍴'fns' ((0 1)(0.7 0)(0.7 0)×size)  
poss⍪← 'fnd' ((0 1)(0 0)(0 0)×size)  poss⍪← 'fnd' ((0 1)(0 0)(0 0)×size)  
poss⍪← 'lines'((0 0)(0.7 0)(0.7 0)×size)  poss⍪← 'lines'((0 0)(0.7 0)(0.7 0)×size)  
poss⍪← 'lnd' ((0 0)(0 0)(0 0)×size)  poss⍪← 'lnd' ((0 0)(0 0)(0 0)×size)  
</  </syntaxhighlight>  
Array notation allows this multiline construction to be made with a single assignment, and also provides an alternate syntax for the inner vectors of vectors:  
<syntaxhighlight lang=apl>  
<  
poss←['fns' ((0 1 ⋄ 0.7 0 ⋄ 0.7 0)×size)  poss←['fns' ((0 1 ⋄ 0.7 0 ⋄ 0.7 0)×size)  
'fnd' ((0 1 ⋄ 0 0 ⋄ 0 0)×size)  'fnd' ((0 1 ⋄ 0 0 ⋄ 0 0)×size)  
'lines'((0 0 ⋄ 0.7 0 ⋄ 0.7 0)×size)  'lines'((0 0 ⋄ 0.7 0 ⋄ 0.7 0)×size)  
'lnd' ((0 0 ⋄ 0 0 ⋄ 0 0)×size)]  'lnd' ((0 0 ⋄ 0 0 ⋄ 0 0)×size)]  
</  </syntaxhighlight>  
==  [[File:Array notation syntax.pngthumbright[[wikipedia:Railroad diagramRailroad diagram]].]]  
The notation  == 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 ERROR]]s:  
* ''broken'' round parentheses  * ''broken'' round parentheses: <syntaxhighlight lang=apl inline>(</syntaxhighlight>…<syntaxhighlight lang=apl inline>)</syntaxhighlight>  
* ''broken'' square brackets  * ''broken'' square brackets: <syntaxhighlight lang=apl inline>[</syntaxhighlight>…<syntaxhighlight lang=apl inline>]</syntaxhighlight>  
* empty round parentheses: <  * empty round parentheses: <syntaxhighlight lang=apl inline>()</syntaxhighlight>  
where ''broken'' means interrupted by one or more [[diamond]]s (<  where ''broken'' means interrupted by one or more [[diamond]]s (<syntaxhighlight lang=apl inline>⋄</syntaxhighlight>) or line breaks (outside of [[dfn]]s).  
* A ''broken'' round parenthesis creates a [[namespace]] if every diamond/line breakseparated statement is a ''namevalue pair''.  * A ''broken'' round parenthesis creates a [[namespace]] if every diamond/line breakseparated statement is a ''namevalue pair''.  
* A ''broken'' round parenthesis creates a [[vector]] if every diamond/line breakseparated statement is a value expression. In that case, every such statement forms an [[element]] in the resulting vector.  * A ''broken'' round parenthesis creates a [[vector]] if every diamond/line breakseparated 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 breakseparated statement forms a [[major cell]] in the resulting array.  * <span id=minrank1>A ''broken'' square bracket creates a an [[array]] where every diamond/line breakseparated statement forms a [[major cell]] in the resulting array.[[#minrank1note*]]<span>  
* <  * <syntaxhighlight lang=apl inline>()</syntaxhighlight> creates a new namespace — equivalent to <syntaxhighlight lang=apl inline>(⎕NS 0⍴⊂'')</syntaxhighlight>  
* A ''namevalue pair''  * A ''namevalue pair'' consists of a valid APL identifier, followed by a colon (<syntaxhighlight lang=apl inline>:</syntaxhighlight>) and a value expression.  
<span id=minrank1note>[[#minrank1*]]</span> 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 ===  === Formal syntax ===  
Line 49:  Line 52:  
== History ==  == History ==  
:''See also the [[Array notation design considerations#Timeline]]''  
#  
Onedimensional list syntax with surrounding brackets and delimiters, matching [[wikipedia:sequencesequence]] notation in mathematics, is common in programming. It appears as early as [[wikipedia:ALGOL 68ALGOL 68]] with parentheses, and squarebracket lists feature in languages from the 1970s such as [[wikipedia:ML (programming language)ML]] and [[wikipedia:Icon (programming language)Icon]]. [[MATLAB]] uses matrix syntax with square brackets, semicolons to separate rows, and commas to separate elements within a row. [[wikipedia:FP (programming language)FP]] uses angle brackets for lists, and square brackets for function "construction", with behavior like [[function array]]s.  
List notation appears in [[Nial]] using brackets and commas like <syntaxhighlight lang=apl inline>[a,b,c]</syntaxhighlight>, and allowing function arrays called "atlases". [[A+]] and [[K]] have a list notation using parentheses and semicolons like <syntaxhighlight lang=apl inline>(a;b;c)</syntaxhighlight>. 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 highrank 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]].<ref>[[Phil Last]]. [https://dyalog.tv/Dyalog15/?v=9HAvTMhYao APL Array Notation] ([https://www.dyalog.com/uploads/conference/dyalog15/presentations/U07_APL_Array_Notation.pdf transcript]). [[Dyalog '15]].</ref><ref>[[Phil Last]]. [http://archive.vector.org.uk/art10501450 A Notation for APL array Embedding and Serialization]. [[Vector Journal]], Volume 26, number 4. [[British APL Association]]. 2016.</ref> Last cited the syntax of [[dfn]]s as a sequence of expressions with enclosing braces, as well as [[APL#]]'s namespace notation enclosed in double brackets <code>[[]]</code>, 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 highrank notation<ref>[[Adám Brudzewsky]]. [https://dyalog.tv/Dyalog17/?v=CRQNzL8cUQE Literal Notation for Arrays and Namespaces] ([https://www.dyalog.com/uploads/conference/dyalog17/presentations/D11_Literal_Notation_for_Arrays_and_Namespaces.pdf slides]). [[Dyalog '17]].</ref> and later returning to square brackets.<ref>[[Adám Brudzewsky]]. [https://dyalog.tv/Dyalog18/?v=GAdQuOtPcfM Array Notation Mk III]. [[Dyalog '18]].</ref><ref>[[Adám Brudzewsky]]. [https://aplgermany.de/wpcontent/uploads/2021/11/APL_Journal_2020_1u2.pdf#page=34 A Notation for APL Arrays]. APLJournal, Volume 2020, number 12. [[APL GermanyAPLGermany e.V.]] 2020.</ref> Because Last's use of <syntaxhighlight lang=apl inline>←</syntaxhighlight> to separate namespace keys from values prevented lists from including arbitrary expressions (which might contain assignment), he proposed a change to <syntaxhighlight lang=apl inline>:</syntaxhighlight> as in [[wikipedia:JSONJSON]]. [[Dyalog APL 18.0]], released in 2020, included support for array notation in source files loaded by Link<ref>[[Dyalog Ltd]]. [https://dyalog.github.io/link/3.0/Discussion/TechDetails/#creatingaplsourcefilesanddirectories Link User Guide: Creating APL Source Files and Directories]. Retrieved 20220824.</ref>, but not in the language itself.<ref>[[Adám Brudzewsky]]. [https://dyalog.tv/Dyalog20/?v=5drncJiWOM4 Array Notation RC1] ([https://www.dyalog.com/uploads/conference/dyalog20/presentations/D09_Array_Notation_RC1.pdf slides]). [[Dyalog '20]].</ref>  
The project manager Acre Desktop added support for the nonnamespace 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 highrank arrays with square brackets in 2020. [[BQN]] supported lists with angle brackets (<code>⟨</code>…<code>⟩</code>) in its initial implementation in 2020; square brackets (<code>[</code>…<code>]</code>) were reserved for highrank array notation, which was implemented in 2022.  
{{Template:Comparison of array notations}}  
== Documentation ==  
* [https://mlochbaum.github.io/BQN/doc/arrayrepr.html#arrayliterals BQN] (as <code>⟨⋄⟩</code>, <code>[⋄]</code>, and <code>{key⇐val⋄}</code>)  
* [https://www.nialarraylanguage.org/ndocs/NialDict2.html#bracketcommanotation Nial] (as <code>[,]</code> for vectors)  
== External links ==  
* [https://abrudz.github.io/aplan Evaluate APL Array Notation] sandbox  
== References ==  == References ==  
<references/>  <references/>  
{{APL syntax}}[[Category:APL syntax]][[Category:Nested array model]]  {{APL syntax}}[[Category:APL syntax]][[Category:Nested array model]] 
Latest revision as of 12:09, 21 September 2022
Dyalog Ltd requests community feedback on the array notation in the hope of ending up with a notation that is shared with other dialects.^{[1]} Head to the design considerations article for details! 

(⋄) [⋄]

Array notation ((⋄)
, [⋄]
) 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 highrank notation using square brackets []
, indicating the Mix of a vector. It also supports namespaces, using name:value
syntax in round parentheses. Statement separators must appear between elements and between name–value pairs.
Examples
Mediumsized array constants are often needed in code. Due to the lack of a native multiline notation, programmers have resorted to various adhoc methods of approximating such, usually at the cost of reduced readability. A very common technique is repeated concatenation:
poss←1 2⍴'fns' ((0 1)(0.7 0)(0.7 0)×size)
poss⍪← 'fnd' ((0 1)(0 0)(0 0)×size)
poss⍪← 'lines'((0 0)(0.7 0)(0.7 0)×size)
poss⍪← 'lnd' ((0 0)(0 0)(0 0)×size)
Array notation allows this multiline construction to be made with a single assignment, and also provides an alternate syntax for the inner vectors of vectors:
poss←['fns' ((0 1 ⋄ 0.7 0 ⋄ 0.7 0)×size)
'fnd' ((0 1 ⋄ 0 0 ⋄ 0 0)×size)
'lines'((0 0 ⋄ 0.7 0 ⋄ 0.7 0)×size)
'lnd' ((0 0 ⋄ 0 0 ⋄ 0 0)×size)]
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 breakseparated statement is a namevalue pair.
 A broken round parenthesis creates a vector if every diamond/line breakseparated 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 breakseparated statement forms a major cell in the resulting array.*
()
creates a new namespace — equivalent to(⎕NS 0⍴⊂'')
 A namevalue 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 expression
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#Timeline
Onedimensional 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 squarebracket 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 [a,b,c]
, and allowing function arrays called "atlases". A+ and K have a list notation using parentheses and semicolons like (a;b;c)
. 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 highrank 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.^{[2]}^{[3]} 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 highrank notation^{[4]} and later returning to square brackets.^{[5]}^{[6]} 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^{[7]}, but not in the language itself.^{[8]}
The project manager Acre Desktop added support for the nonnamespace 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 highrank arrays with square brackets in 2020. BQN supported lists with angle brackets (⟨
…⟩
) in its initial implementation in 2020; square brackets ([
…]
) were reserved for highrank array notation, which was implemented in 2022.
Comparison of array notations
The following systems support list or vector notation in some form, beyond simple strand notation. The separators ;
in A+ and K, and ⋄
in APL and BQN, indicate any separator, including a line break.
System  Vectors  Highrank  Namespaces  Function arrays  Assignable 

Nial  [,] 
No  N/A  Special  No 
A+  (;) 
No  N/A  Firstclass  Yes 
K  (;) 
N/A  [key:val;] 
Firstclass  Yes 
BQN^{[9]}  ⟨⋄⟩ 
[⋄] 
{key⇐val⋄} 
Firstclass  Yes 
dzaima/APL  (⋄) 
[⋄] 
(key:val⋄) 
Special  No 
Dyalog Link  (⋄) 
[⋄] 
(key:val⋄) 
No  No 
Acre Desktop^{[10]}  (⋄) 
[⋄] 
[key←val⋄] 
No  N/A 
Nial and A+ do not support namespaces, while K does not support highrank arrays, so any such notation is not applicable. The "Function arrays" column indicates whether functions can be placed in array notation. "First class" indicates that functions are first class, so this is possible without special consideration. "Special" indicates creating a special vectors of functions that can be applied to arguments to return a list of results. The "Assignable" column indicates that array notation can be used as an assignment target to perform destructuring. BQN's namespaces don't use a dedicated construction; instead, any block (like a dfn) with ⇐
statements returns a namespace reference. Acre Desktop only uses array notation for storing literal arrays; it cannot appear in executable code.
Documentation
External links
 Evaluate APL Array Notation sandbox
References
 ↑ Dyalog Ltd/Adám Brudzewsky. Re: Deserialise does it work as expected?. Dyalog Forums. 20220905.
 ↑ Phil Last. APL Array Notation (transcript). Dyalog '15.
 ↑ Phil Last. A Notation for APL array Embedding and Serialization. Vector Journal, Volume 26, number 4. British APL Association. 2016.
 ↑ Adám Brudzewsky. Literal Notation for Arrays and Namespaces (slides). Dyalog '17.
 ↑ Adám Brudzewsky. Array Notation Mk III. Dyalog '18.
 ↑ Adám Brudzewsky. A Notation for APL Arrays. APLJournal, Volume 2020, number 12. APLGermany e.V. 2020.
 ↑ Dyalog Ltd. Link User Guide: Creating APL Source Files and Directories. Retrieved 20220824.
 ↑ Adám Brudzewsky. Array Notation RC1 (slides). Dyalog '20.
 ↑ Lochbaum, Marshall. BQN: Array notation and display; Array literals. Retrieved 20220901.
 ↑ The Carlisle Group. APL Array Notation. Acre Desktop Wiki. GitHub. Retrieved 20220901.