Strand notation: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
m (Text replacement - "http://help.dyalog.com/latest/Content/Language/" to "http://help.dyalog.com/latest/index.htm#Language/")
m (Text replacement - "<source" to "<syntaxhighlight")
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Strand notation, or stranding, is the convention that multiple (more than one) arrays written next to each other are automatically combined into a [[vector]]. Stranding can make code easier to read by eliminating the need for punctuation when writing small arrays in APL. It can also cause frustration when programming if unrelated arrays are stranded together. This issue occurs when operators are allowed to take array operands, and can be resolved by inserting extra parentheses or identity functions into the expression.
{| class=vertical-navbox style="float:right; font-size:500%; margin:0 1ex;"
|<code>1 2 3</code>
|}
'''Strand notation''', or '''stranding''', is the convention that multiple (more than one) arrays written next to each other are automatically combined into a [[vector]]. Stranding can make code easier to read by eliminating the need for punctuation when writing small arrays in APL. It can also cause frustration when programming if unrelated arrays are stranded together. This issue occurs when [[operator]]s are allowed to take array [[operand]]s, and can be resolved by inserting extra parentheses or [[identity function]]s into the expression.


Several variations on stranding exist:
Several variations on stranding exist:
* [[SHARP APL]] have no notion of array stranding.
* In [[Dyalog APL]], [[NARS2000]], [[APL.68000]], and others, arrays are stranded before operator or function evaluation.
* In [[APL2]] arrays are stranded before operator or function evaluation.
* In [[APL2]], [[APLX]] and others, arrays are stranded after operator evaluation and bracket indexing, but before function evaluation.
* In some APLs (???) arrays are stranded after operator evaluation but before function evaluation.
* In [[APL\360]], [[SHARP APL]] and [[J]] stranding is called '''vector notation''' and is a part of token formation rather than execution. Only plain numbers are stranded.
* In [[J]] stranding is a part of token formation rather than execution. Only plain numbers are stranded.
* In [[A+]] a system equivalent to APL\360 is implemented, but is described as part of [[numeric literal]] notation. "Stranding" in A+ refers to vector notation using parentheses and semicolons <syntaxhighlight lang=apl inline>(a;b;c)</syntaxhighlight>.
* [[BQN]] breaks [[backwards compatibility]] with APL and does not allow stranding by juxtaposition even for numbers. Instead, the "ligature" character <code>‿</code> is used for a more explicit variation of stranding.


An example in which stranding interferes with the most obvious way of writing a program is shown below. Consider applying the function <source lang=apl inline>f</source> to <source lang=apl inline>0.8</source> three times using the [[Power operator]]:
An example in which stranding interferes with the most obvious way of writing a program is shown below. Consider applying the function <syntaxhighlight lang=apl inline>f</syntaxhighlight> to <syntaxhighlight lang=apl inline>0.8</syntaxhighlight> three times using the [[Power operator]]:
<source lang=apl>
<syntaxhighlight lang=apl>
f⍣3 0.8
f⍣3 0.8
</source>
</syntaxhighlight>
In a language which strands before function application, this expression is equivalent to the derived function <source lang=apl inline>f⍣(3,0.8)</source>. Not what was intended! The two numbers must be separated somehow, for instance with parentheses or a [[tack function]].
In a language which strands before function application, this expression is equivalent to the derived function <syntaxhighlight lang=apl inline>f⍣(3,0.8)</syntaxhighlight>. Not what was intended! The two numbers must be separated somehow, for instance with parentheses or a [[Identity|tack function]].
<source lang=apl>
<syntaxhighlight lang=apl>
(f⍣3)0.8
(f⍣3)0.8
f⍣3⊢0.8
f⍣3⊢0.8
</source>
</syntaxhighlight>
For operators that take array operands, such as the [[Rank operator]], stranding before operator application can be beneficial. Without it, a function with two ranks such as <source lang=apl inline>⊥⍤0 1</source> would have to be written with parentheses <source lang=apl inline>⊥⍤(0 1)</source>.
For operators that take array operands, such as the [[Rank operator]], stranding before operator application can be beneficial. Without it, a function with two ranks such as <syntaxhighlight lang=apl inline>⊥⍤0 1</syntaxhighlight> would have to be written with parentheses <syntaxhighlight lang=apl inline>⊥⍤(0 1)</syntaxhighlight>.


== External links ==
== External links ==
Line 22: Line 26:
=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/latest/index.htm#Language/Introduction/Variables/Vector%20Notation.htm Dyalog]
* [https://help.dyalog.com/latest/index.htm#Language/Introduction/Variables/Vector%20Notation.htm Dyalog]
 
* [http://microapl.com/apl_help/ch_020_010_130.htm APLX]
* [http://microapl.com/apl_help/ch_020_010_130.htm APLX]


{{APL programming language}}
{{APL syntax}}[[Category:APL syntax]][[Category:Nested array model]]

Latest revision as of 10:34, 11 September 2022

1 2 3

Strand notation, or stranding, is the convention that multiple (more than one) arrays written next to each other are automatically combined into a vector. Stranding can make code easier to read by eliminating the need for punctuation when writing small arrays in APL. It can also cause frustration when programming if unrelated arrays are stranded together. This issue occurs when operators are allowed to take array operands, and can be resolved by inserting extra parentheses or identity functions into the expression.

Several variations on stranding exist:

  • In Dyalog APL, NARS2000, APL.68000, and others, arrays are stranded before operator or function evaluation.
  • In APL2, APLX and others, arrays are stranded after operator evaluation and bracket indexing, but before function evaluation.
  • In APL\360, SHARP APL and J stranding is called vector notation and is a part of token formation rather than execution. Only plain numbers are stranded.
  • In A+ a system equivalent to APL\360 is implemented, but is described as part of numeric literal notation. "Stranding" in A+ refers to vector notation using parentheses and semicolons (a;b;c).
  • BQN breaks backwards compatibility with APL and does not allow stranding by juxtaposition even for numbers. Instead, the "ligature" character is used for a more explicit variation of stranding.

An example in which stranding interferes with the most obvious way of writing a program is shown below. Consider applying the function f to 0.8 three times using the Power operator:

f⍣3 0.8

In a language which strands before function application, this expression is equivalent to the derived function f⍣(3,0.8). Not what was intended! The two numbers must be separated somehow, for instance with parentheses or a tack function.

(f⍣3)0.8
f⍣3⊢0.8

For operators that take array operands, such as the Rank operator, stranding before operator application can be beneficial. Without it, a function with two ranks such as ⊥⍤0 1 would have to be written with parentheses ⊥⍤(0 1).

External links

Documentation


APL syntax [edit]
General Comparison with traditional mathematicsPrecedenceTacit programming (Train, Hook, Split composition)
Array Numeric literalStringStrand notationObject literalArray notation (design considerations)
Function ArgumentFunction valenceDerived functionDerived operatorNiladic functionMonadic functionDyadic functionAmbivalent functionDefined function (traditional)DfnFunction train
Operator OperandOperator valenceTradopDopDerived operator
Assignment MultipleIndexedSelectiveModified
Other Function axisBracket indexingBranchStatement separatorQuad nameSystem commandUser commandKeywordDot notationFunction-operator overloadingControl structureComment