Comment

From APL Wiki
Revision as of 14:22, 20 May 2024 by Marshall (talk | contribs) (APL syntax category)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

APL allows a comment at the end of a line, separating (optional) code on the left from comments on the right using the lamp glyph , thus forming a line comment:

      2+3  ⍝ An example of addition
5

Alternatives

An alternative way to write a comment is by exploiting that the left function () returns ignores its left argument, but then the comment has to be a string:

      2+3 ⊣ 'An example of addition'
5

In fact, the right function () can similarly be used to insert a leading or inline comment, although this does undo shyness:

      'An example of addition' ⊢ 2+3
5
      'The result of the assignment is printed' ⊢ res←2+3
5
      2+ 'inline comment' ⊢ 3
5

Inline comment extension

APL64 uniquely adds dedicated syntax for inline comments using and :

      2+ ⟃ inline comment ⟄ 3
5
      2 ⟃ inline comment ⟄ + 3
5
      2 ⟃ inline comment ⟄ 3
2 3
Works in: APL64

Special comments

In APL*PLUS, ⍝∇ marks a special "public comment" which can be retrieved with a dedicated system function even when the function is locked. This is also used to distinguish internal documentation from other comments.

Other similar patterns, consisting of the lamp glyph followed by another symbol, are occasionally as indicators to various code analysis tools.

Dyalog APL's Simple APL Library Toolkit (SALT) used ⍝∇:require as an instruction to load another source file before the current one, although this eventually was superceded by a proper :Require keyword.


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