Strand notation

From APL Wiki
Revision as of 09:07, 29 October 2019 by Miraheze>Adám Brudzewsky (Text replacement - "<code>" to "<source lang=apl inline>")
Jump to navigation Jump to search

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:

  • SHARP APL has no notion of array stranding.
  • In APL2 arrays are stranded before operator or function evaluation.
  • In some APLs (???) arrays are stranded after operator evaluation but before function evaluation.
  • In J stranding is a part of token formation rather than execution. Only plain numbers are stranded.

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 to <source lang=apl inline>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 <source lang=apl inline>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 <source lang=apl inline>⊥⍤0 1 would have to be written with parentheses <source lang=apl inline>⊥⍤(0 1).