Array notation: Difference between revisions
Jump to navigation
Jump to search
m (→2014: "Dyalog '15" → "Dyalog '14") |
(Move most material to Dyalog-specific page and rework introduction) |
||
Line 1: | Line 1: | ||
'''Array 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]] and [[BQN]], and by some tools for [[Dyalog APL]], where it is planned as an eventual language feature. | |||
'''Array notation''' is a way to write most [[array]]s literally, with no or minimal use of [[primitive function]]s, possibly over multiple code lines. | |||
Array notation generally consists of a list notation written with parentheses <source lang=apl inline>()</source>, roughly equivalent to stranding, and a high-rank notation using square brackets <source lang=apl inline>[]</source>, indicating the [[Mix]] of a list. It may also support [[namespace]]s, with dzaima/APL and Dyalog using <source lang=apl inline>name:value</source> syntax in parentheses for this. In each case, elements are separated by [[statement separator]]s such as <source lang=apl inline>⋄</source> or line breaks. | |||
== 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 [[concatenate|concatenation]]: | 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 [[concatenate|concatenation]]: | ||
Line 9: | Line 12: | ||
poss⍪← 'lnd' ((0 0)(0 0)(0 0)×size) | poss⍪← 'lnd' ((0 0)(0 0)(0 0)×size) | ||
</source> | </source> | ||
Array notation allows this multi-line construction to be made with a single assignment, and also provides an alternate syntax for the inner vectors of vectors: | |||
<source lang=apl> | <source lang=apl> | ||
poss←['fns' ((0 1 ⋄ 0.7 0 ⋄ 0.7 0)×size) | poss←['fns' ((0 1 ⋄ 0.7 0 ⋄ 0.7 0)×size) | ||
Line 23: | Line 19: | ||
'lnd' ((0 0 ⋄ 0 0 ⋄ 0 0)×size)] | 'lnd' ((0 0 ⋄ 0 0 ⋄ 0 0)×size)] | ||
</source> | </source> | ||
== Description == | == Description == | ||
The notation is added to the language by giving meaning to previously invalid statements. The added syntax consists of three constructs that are currently [[SYNTAX ERROR]]s: | The notation is added to the language by giving meaning to previously invalid statements. The added syntax consists of three constructs that are currently [[SYNTAX ERROR]]s: | ||
Line 37: | Line 34: | ||
* <source lang=apl inline>()</source> is equivalent to <source lang=apl inline>(⎕NS 0⍴⊂'')</source> | * <source lang=apl inline>()</source> is equivalent to <source lang=apl inline>(⎕NS 0⍴⊂'')</source> | ||
* A ''name-value pair'' consist of a valid APL identifier, followed by a <source lang=apl inline>:</source> and a value expression. | * A ''name-value pair'' consist of a valid APL identifier, followed by a <source lang=apl inline>:</source> and a value expression. | ||
== History == | == History == | ||
:''See also [[Array notation in Dyalog APL]]'' | |||
[[ | |||
== References == | == References == | ||
<references/> | <references/> | ||
{{APL syntax}}[[Category:APL syntax]][[Category:Nested array model]] | {{APL syntax}}[[Category:APL syntax]][[Category:Nested array model]] |