Skip to content

Primitive Pointers

Vector 18:2, page 44

programming techniques

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 44

(The purpose of this column is to point out some facts about the primitive APL functions you may have overlooked or forgotten. If you don’t believe use, try it out!)

From last issue: the first step in parsing an executable APL expression for identifier names is to ignore the text within quotes. Here’s an example:

      EXPR←'SUB←(∨/''FL''⍷NAMES)⌿NAMES'

The identifiers used in this expression are SUB and NAMES. FL is not an identifier because it’s within quotes. The =\ and ≠\ functions can be used to distinguish between text within quotes and text outside quotes. Let’s try them (blanks between bit elements are omitted for clarity):

      EXPR
SUB←(∨/'FL'⍷NAMES)⌿NAMES

Mark the quotes:

      EXPR=''''
000000010010000000000000

Text within quotes including leading quote:

      ≠\EXPR=''''
000000011100000000000000

Select all other characters:

      (~≠\EXPR='''')/EXPR
SUB←(∨/'⍷NAMES)⌿NAMES

=\ is the opposite of ≠\:

      EXPR≠''''
111111101101111111111111
      =\EXPR≠''''
111111100011111111111111

Exclude both quotes, selecting just non-quoted text:

      (=\EXPR≠'''')∧EXPR≠''''
111111100001111111111111
      ((=\EXPR≠'''')∧EXPR≠'''')/EXPR
SUB←(∨/⍷NAMES)⌿NAMES

The second step in parsing an executable APL expression is to ignore the text following lamp (⍝) symbols. An example:

      X←'SUB∨/''⍝FL''⍷NAMES ⍝ LOOK FOR ''⍝FL'''

The identifiers used in this expression are SUB and NAMES, not FL, LOOK, or FOR. What APL expression selects from a character vector X just those characters that are not with quotes or comments?

Answer next issue. (Hint: Experiment with ∧\ and ∨\. Consider only lamp symbols outside quotes.)


Reprinted with kind permission from Zark APL Tutor News, a quarterly publication of Zark Incorporated, 23 Ketchbrook Lane, Ellington, CT06029, USA