A Programming Language: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Marshall
Miraheze>Adám Brudzewsky
m (Text replacement - "<code>" to "<source lang=apl inline>")
Line 12: Line 12:
''A Programming Language'' features precursors of many APL [[primitive functions]]. These include:
''A Programming Language'' features precursors of many APL [[primitive functions]]. These include:
* The [[shape]] vector is not used, but dimension functions are present: ν gives the length of a vector, and ν and μ give the row length and column length of a matrix.
* The [[shape]] vector is not used, but dimension functions are present: ν gives the length of a vector, and ν and μ give the row length and column length of a matrix.
* [[Comparison functions]] are defined using the symbols <code><</code>, <code>></code>, and <code>=</code> and the rules that a vertical bar negates a relation and that an underline combines it with <code>=</code> (relations are combined by or-ing them together).
* [[Comparison functions]] are defined using the symbols <source lang=apl inline><</code>, <source lang=apl inline>></code>, and <source lang=apl inline>=</code> and the rules that a vertical bar negates a relation and that an underline combines it with <source lang=apl inline>=</code> (relations are combined by or-ing them together).
* The arithmetic [[scalar functions]] [[Sum]] (<code>+</code>), [[Difference]] (<code>-</code>), [[Product]] (×), and [[Quotient]] (÷) are defined as in mathematics.
* The arithmetic [[scalar functions]] [[Sum]] (<source lang=apl inline>+</code>), [[Difference]] (<source lang=apl inline>-</code>), [[Product]] (×), and [[Quotient]] (÷) are defined as in mathematics.
* The logical functions [[And]] (<code>∧</code>) and [[Or]] (<code>∨</code>) also match mathematical usage. [[Logical negation]] is denoted with an overbar.
* The logical functions [[And]] (<source lang=apl inline>∧</code>) and [[Or]] (<source lang=apl inline>∨</code>) also match mathematical usage. [[Logical negation]] is denoted with an overbar.
* The functions [[Absolute Value]], [[Ceiling]], and [[Floor]] use paired symbols. The paired symbols for ceiling and floor were adopted by mathematicians (absolute value was already in use), but APL implementations dropped the closing symbol for consistency with monadic function syntax.
* The functions [[Absolute Value]], [[Ceiling]], and [[Floor]] use paired symbols. The paired symbols for ceiling and floor were adopted by mathematicians (absolute value was already in use), but APL implementations dropped the closing symbol for consistency with monadic function syntax.
* [[Residue]] uses <code>|</code> as in APL, but allows a subscript to indicate the smallest value allowed—mirroring [[index origin]].
* [[Residue]] uses <source lang=apl inline>|</code> as in APL, but allows a subscript to indicate the smallest value allowed—mirroring [[index origin]].
* [[Iota]] is called "Interval" and uses the letter <code>⍳</code> with an optional [[index origin]] subscript.
* [[Iota]] is called "Interval" and uses the letter <source lang=apl inline>⍳</code> with an optional [[index origin]] subscript.
* [[Index-Of]] is also written with <code>⍳</code> and an [[index origin]] subscript. It is defined on vector left arguments and vector or scalar right arguments.
* [[Index-Of]] is also written with <source lang=apl inline>⍳</code> and an [[index origin]] subscript. It is defined on vector left arguments and vector or scalar right arguments.
* [[Membership]] is <code>∊</code> as in APL.
* [[Membership]] is <source lang=apl inline>∊</code> as in APL.
* [[Reduction]] (<code>/</code>, or <code>//</code> instead of <code>⌿</code>) starts from the left rather than the right. For reductions of [[empty]] arrays, the [[identity element]] is returned.
* [[Reduction]] (<source lang=apl inline>/</code>, or <source lang=apl inline>//</code> instead of <source lang=apl inline>⌿</code>) starts from the left rather than the right. For reductions of [[empty]] arrays, the [[identity element]] is returned.
* [[Rotate]] is written with arrows: <code>↑</code> for left rotation and <code>↓</code> for right rotation.
* [[Rotate]] is written with arrows: <source lang=apl inline>↑</code> for left rotation and <source lang=apl inline>↓</code> for right rotation.
* [[Reverse]] is written with an arrow in some direction above the argument.
* [[Reverse]] is written with an arrow in some direction above the argument.
* [[Transpose]] is written with a tilde <code>~</code> above a matrix.
* [[Transpose]] is written with a tilde <source lang=apl inline>~</code> above a matrix.
* [[Compress|Compression]] and [[Expand|Expansion]] use <code>/</code> and <code>\</code> as in APL.
* [[Compress|Compression]] and [[Expand|Expansion]] use <source lang=apl inline>/</code> and <source lang=apl inline>\</code> as in APL.
* [[Catenate]] uses a circled comma.
* [[Catenate]] uses a circled comma.
* [[Indexing]] is written with a subscript, or <code>∫<sub>j</sub></code> to allow [[index origin]] specification.
* [[Indexing]] is written with a subscript, or <source lang=apl inline>∫<sub>j</sub></code> to allow [[index origin]] specification.
* [[Grade]] is called "ordering", and the Grade of <code>x</code> with [[index origin]] <code>j</code> is written <code>0<sub>j</sub>/x</code>
* [[Grade]] is called "ordering", and the Grade of <source lang=apl inline>x</code> with [[index origin]] <source lang=apl inline>j</code> is written <source lang=apl inline>0<sub>j</sub>/x</code>
* [[Base]] (<code>⊥</code>) on vectors works like in APL. On matrices, rows are paired up, or columns with a doubled base symbol.
* [[Base]] (<source lang=apl inline>⊥</code>) on vectors works like in APL. On matrices, rows are paired up, or columns with a doubled base symbol.
* The [[Intersection]] and [[Union]] are written with <code>∩</code> and <code>∪</code>, and the [[Set Difference]] with <code>∆</code>.
* The [[Intersection]] and [[Union]] are written with <source lang=apl inline>∩</code> and <source lang=apl inline>∪</code>, and the [[Set Difference]] with <source lang=apl inline>∆</code>.
* The [[Inner Product]] is written by placing one scalar function above another, and the [[Outer Product]] by using <code>∘</code> in place of the top function with two vector arguments.
* The [[Inner Product]] is written by placing one scalar function above another, and the [[Outer Product]] by using <source lang=apl inline>∘</code> in place of the top function with two vector arguments.

Revision as of 09:06, 29 October 2019

A Programming Language is a book published in 1962 by Kenneth E. Iverson to describe one iteration of his Iverson notation. The book's title later was used to form the acronym APL. At the time of writing Iverson notation was used for mathematics and description of IBM's hardware, and its purely human purposes are reflected in the loose conventions (relative to APL) and two-dimensional structure of the notation presented in A Programming Language.

Notation

A Programming Language does not feature a full multidimensional array model. Rather, operations are defined on scalars, vectors, and matrices and higher-rank arrays are not discussed. Nonetheless, it features many of the array conveniences that became characteristics of APL:

  • Scalar functions are present with the name "basic operations".
  • While scalar extension is not defined in general, a scalar can be multiplied by an array as a "scalar multiple".
  • Vector functions are usually extended to work on the rows of matrices (the opposite of the leading axis model). When doubled typographically, they work on columns instead.

In addition to scalars, vectors, and matrices, tree and file types are defined.

A Programming Language features precursors of many APL primitive functions. These include:

  • The shape vector is not used, but dimension functions are present: ν gives the length of a vector, and ν and μ give the row length and column length of a matrix.
  • Comparison functions are defined using the symbols <source lang=apl inline><, <source lang=apl inline>>, and <source lang=apl inline>= and the rules that a vertical bar negates a relation and that an underline combines it with <source lang=apl inline>= (relations are combined by or-ing them together).
  • The arithmetic scalar functions Sum (<source lang=apl inline>+), Difference (<source lang=apl inline>-), Product (×), and Quotient (÷) are defined as in mathematics.
  • The logical functions And (<source lang=apl inline>∧) and Or (<source lang=apl inline>∨) also match mathematical usage. Logical negation is denoted with an overbar.
  • The functions Absolute Value, Ceiling, and Floor use paired symbols. The paired symbols for ceiling and floor were adopted by mathematicians (absolute value was already in use), but APL implementations dropped the closing symbol for consistency with monadic function syntax.
  • Residue uses <source lang=apl inline>| as in APL, but allows a subscript to indicate the smallest value allowed—mirroring index origin.
  • Iota is called "Interval" and uses the letter <source lang=apl inline>⍳ with an optional index origin subscript.
  • Index-Of is also written with <source lang=apl inline>⍳ and an index origin subscript. It is defined on vector left arguments and vector or scalar right arguments.
  • Membership is <source lang=apl inline>∊ as in APL.
  • Reduction (<source lang=apl inline>/, or <source lang=apl inline>// instead of <source lang=apl inline>⌿) starts from the left rather than the right. For reductions of empty arrays, the identity element is returned.
  • Rotate is written with arrows: <source lang=apl inline>↑ for left rotation and <source lang=apl inline>↓ for right rotation.
  • Reverse is written with an arrow in some direction above the argument.
  • Transpose is written with a tilde <source lang=apl inline>~ above a matrix.
  • Compression and Expansion use <source lang=apl inline>/ and <source lang=apl inline>\ as in APL.
  • Catenate uses a circled comma.
  • Indexing is written with a subscript, or <source lang=apl inline>∫j to allow index origin specification.
  • Grade is called "ordering", and the Grade of <source lang=apl inline>x with index origin <source lang=apl inline>j is written <source lang=apl inline>0j/x
  • Base (<source lang=apl inline>⊥) on vectors works like in APL. On matrices, rows are paired up, or columns with a doubled base symbol.
  • The Intersection and Union are written with <source lang=apl inline>∩ and <source lang=apl inline>∪, and the Set Difference with <source lang=apl inline>∆.
  • The Inner Product is written by placing one scalar function above another, and the Outer Product by using <source lang=apl inline>∘ in place of the top function with two vector arguments.