Array notation: Difference between revisions

Jump to navigation Jump to search
1,579 bytes added ,  17:07, 9 May 2021
no edit summary
No edit summary
Line 1: Line 1:
[[File:Array notation syntax.png|thumb|right|[[wikipedia:Railroad diagram|Railroad diagram]] for the array notation syntax.]]
'''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. While APL has had at least simple numeric [[strand notation]] since [[APL\360]], no major APL has implemented native support for an extended notation as of 2020.
'''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. While APL has had at least simple numeric [[strand notation]] since [[APL\360]], no major APL has implemented native support for an extended notation as of 2020.


Line 8: Line 9:
poss⍪←  'lnd'  ((0 0)(0  0)(0  0)×size)
poss⍪←  'lnd'  ((0 0)(0  0)(0  0)×size)
</source>
</source>
[[File:Array notation syntax.png|thumb|right|[[wikipedia:Railroad diagram|Railroad diagram]] for the array notation syntax.]]
Using the array notation described in this article, the array could for example be written as:
=== Syntax ===
<source lang=apl>
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)]
</source>
The array notation can also be used to express the inner vectors of vectors:
<source lang=apl>
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)]
</source>
== 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 ERRORs:
 
* ''broken'' round parentheses
* ''broken'' square brackets
* empty round parentheses: <source lang=apl inline>()</source>
 
where ''broken'' means interrupted by one or more <source lang=apl inline>⋄</source> or line breaks (outside of dfns).
 
* A ''broken'' round parenthesis creates a [[vector]], where every diamond/line break-separated 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.
* <source lang=apl inline>()</source> is equivalent to <source lang=apl inline>(⎕NS 0⍴⊂'')</source>
 
=== Formal syntax ===
The array notation can be described using [[wikipedia:Extended Backus–Naur form|Extended Backus–Naur form]], where an <code>expression</code> is any traditional APL expression:
The array notation can be described using [[wikipedia:Extended Backus–Naur form|Extended Backus–Naur form]], where an <code>expression</code> is any traditional APL expression:
<pre>
<pre>
Line 56: Line 83:
== Design considerations ==
== Design considerations ==


In creating the notation's specification, various alternatives were considered. During initial exploration, the following requirements were proposed:
In creating the notation's specification, various alternatives were considered. The following requirements were proposed:<ref>[[Adám Brudzewsky]]. Internaldocuments. [[Dyalog Ltd.]] 30 Jun 2017.</ref>


# No new [[glyph]]s
# No new [[glyph]]s
# Reusing existing glyphs for similar purposes
# Reusing existing glyphs for similar purposes
# Similarity to other languages ([[K]], [[wikipedia:JSON|JSON]], [[wikipedia:CSS|CSS]])
# Visual attractiveness
# Visual attractiveness
# Intuitive syntax
# Intuitive syntax

Navigation menu