Statement separator: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Statement Separator (<syntaxhighlight lang=apl inline></syntaxhighlight>) often called by the name of its glyph Diamond, allows you to place multiple statements on a single line. It works both inside a function and directly within the interpreter. Statement separators can be empty.
{{Built-in|Statement Separator|}} often called by the name of its glyph, '''Diamond''', allows placing multiple statements on a single line. It works both inside a function and directly within the interpreter. Empty statements are generally ignored.


It is important to note that using a Statement Separator(<syntaxhighlight lang=apl inline>⋄</syntaxhighlight>) forces the interpreter to read from left to right. Each separated statement will be read as if it is on it's own line.  
== Description ==
The Statement Separator forces the interpreter to read from left to right. Each separate statement will be read as if on its own line.  


In Iverson's Dictionary of APL <ref>[[Kenneth E. Iverson|Iverson, Kenneth]]. [https://www.jsoftware.com/papers/APLDictionary1.htm#3e "Dictionary of APL"]. [[Sansom]] 1987.</ref> he states "expressions using the statement separator (<syntaxhighlight lang=apl inline>⋄</syntaxhighlight>) can be mimicked by expressions using the verb left [[Identity]]. The primary difference is that the separation imposed by <syntaxhighlight lang=apl inline>⊣</syntaxhighlight> follows the normal rules for order of execution."  
[[A Dictionary of APL]]<ref>[[Kenneth E. Iverson|Iverson, Kenneth]]. [https://www.jsoftware.com/papers/APLDictionary1.htm#3e "A Dictionary of APL"]. Sansom. 1987.</ref> states that "expressions using the statement separator (<syntaxhighlight lang=apl inline>⋄</syntaxhighlight>) can be mimicked by expressions using the verb '''[[left]]'''. The primary difference is that the separation imposed by <syntaxhighlight lang=apl inline>⊣</syntaxhighlight> follows the normal rules for order of execution."  


[[APL/700]] uses a semicolon to achieve the same effect as the left tack (<syntaxhighlight lang=apl inline>⊣</syntaxhighlight>).
Some historical APLs used a right-to-left alternative [[glyph]] to achieve the same effect as the left [[Identity]] function (<syntaxhighlight lang=apl inline>⊣</syntaxhighlight>), as does [[J]] (<syntaxhighlight lang=j inline>[</syntaxhighlight>).
* [[APL/700]] used a semicolon (<syntaxhighlight lang=apl inline>;</syntaxhighlight>)
* [[MCM/70]] used a "null operator" [[jot]] (<syntaxhighlight lang=apl inline>∘</syntaxhighlight>)
However, and while relevant for J, but not for these historical APLs, this does not allow definition of multiple single-line functions on the same line.


According to the Sharp APL Reference Manual<ref>[[Paul Berry|Berry, Paul]]. [https://archive.org/details/sharp-apl-reference-manual_202108 "Sharp APL Reference Manual"]. [[IP Sharp]] 1987.</ref> [[branching]] <syntaxhighlight lang=apl inline>→</syntaxhighlight> takes precedence over statement separators. ie "If the expression to the right of the branch is not empty, the system goes immediately to the line whose number is the first element in that expression"
[[Branch]] (<syntaxhighlight lang=apl inline>→</syntaxhighlight>) takes precedence over statement separators. "If the expression to the right of the branch is not empty, the system goes immediately to the line whose number is the first element in that expression."<ref>[[Paul Berry|Berry, Paul]]. [https://archive.org/details/sharp-apl-reference-manual_202108 "Sharp APL Reference Manual"]. [[I.P. Sharp Associates]]. 1987.</ref> It is only possible to branch to the first statement on any line.


When tracing errors within a line containing statement separators (<syntaxhighlight lang=apl inline>⋄</syntaxhighlight>), statements to the right of the caret have not yet been executed.
When displaying an errors message, where the error happened on a line containing statement separators, statements to the right of the position indicated by the error caret have not yet been executed:
<syntaxhighlight lang=apl>
DOMAIN ERROR: Divide by zero
      2÷0 ⋄ 1+3
      ∧
</syntaxhighlight>


Statement separators to the right of a [[comment]] are ignored.  
Statement separators to the right of a [[comment]] <syntaxhighlight lang=apl inline>⍝</syntaxhighlight> are part of the command are therefore ignored.


== Examples ==
== Examples ==
Line 24: Line 33:


=== Documentation ===
=== Documentation ===
* Dyalog: [https://help.dyalog.com/latest/index.htm#Language/Defined%20Functions%20and%20Operators/TradFns/Statements.htm]
* [https://help.dyalog.com/latest/index.htm#Language/Defined%20Functions%20and%20Operators/TradFns/Statements.htm Dyalog]
* APLX: [https://microapl.com/apl_help/ch_020_020_930.htm]
* [https://microapl.com/apl_help/ch_020_020_930.htm APLX]
* Nars2000: [http://wiki.nars2000.org/index.php?title=Diamond]
* [http://wiki.nars2000.org/index.php?title=Diamond NARS2000]
* BQN: [https://mlochbaum.github.io/BQN/doc/token.html#separators]
* [https://mlochbaum.github.io/BQN/doc/token.html#separators BQN] (<syntaxhighlight lang=apl inline>⋄</syntaxhighlight> and <syntaxhighlight lang=apl inline>,</syntaxhighlight> are synonymous)


== References ==
== References ==
<references />
<references />
{{APL built-ins}}[[Category:Primitive functions]]
{{APL syntax}}[[Category:APL syntax]]

Latest revision as of 05:24, 11 November 2022

Statement Separator () often called by the name of its glyph, Diamond, allows placing multiple statements on a single line. It works both inside a function and directly within the interpreter. Empty statements are generally ignored.

Description

The Statement Separator forces the interpreter to read from left to right. Each separate statement will be read as if on its own line.

A Dictionary of APL[1] states that "expressions using the statement separator () can be mimicked by expressions using the verb left. The primary difference is that the separation imposed by follows the normal rules for order of execution."

Some historical APLs used a right-to-left alternative glyph to achieve the same effect as the left Identity function (), as does J ([).

However, and while relevant for J, but not for these historical APLs, this does not allow definition of multiple single-line functions on the same line.

Branch () takes precedence over statement separators. "If the expression to the right of the branch is not empty, the system goes immediately to the line whose number is the first element in that expression."[2] It is only possible to branch to the first statement on any line.

When displaying an errors message, where the error happened on a line containing statement separators, statements to the right of the position indicated by the error caret have not yet been executed:

DOMAIN ERROR: Divide by zero
      2÷0 ⋄ 1+3
       ∧

Statement separators to the right of a comment are part of the command are therefore ignored.

Examples

Statements are read from left to right:

A←10 ⋄ A←A×3 ⋄ A÷2 
15

External links

Documentation

References

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