Comment

From APL Wiki
Revision as of 09:48, 14 February 2024 by Adám Brudzewsky (talk | contribs) (Created page with "{| class=vertical-navbox style="float:right; font-size:500%; margin:0 1ex;" |<code><nowiki>⍝</nowiki></code> |} 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 <syntaxhighlight lang=apl inline>⍝</syntaxhighlight>, thus forming a line comment: <syntaxhighlight lang=apl> 2+3 ⍝ An example of addition 5 </syntaxh...")
(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: APL 64

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 features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell searchFirst-class function
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR