APL2 Programming: Language Reference
Total Page:16
File Type:pdf, Size:1020Kb
IBM APL2 Programming: Language Reference SH21-1061-01 IBM APL2 Programming: Language Reference SH21-1061-01 Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page x. | Second Edition (February 1994) | This edition replaces and makes obsolete the previous edition, SH21-1061-0. The technical changes for this edition are summarized | under “Summary of Changes,” and are indicated by a vertical bar to the left of a change. | This edition applies to: | Release 2 of APL2/370 Version 2, Program Number 5688-228 | Release 2 of APL2/6000 Version 1, Program Number 5765-012 | Release 2 of APL2/PC Version 1, Program Numbers 5604-260 (EMEA) and 5799-PGG (USA) | Release 1 of APL2 for Sun Solaris Version 1, Program Number 5648-065 | Release 1 of APL2/2 Advanced, Version 1.0, Part Number 89G1697 | Release 1 of APL2/2 Entry, Version 1.0, Part Number 89G1556 and to any subsequent releases until otherwise indicated in new editions or technical newsletters. Changes are made periodically to this publication; before using this publication in connection with the operation of IBM systems, consult the latest edition of the applicable IBM system bibliography for current information on this product. Requests for IBM publications should be made to your IBM representative or to the IBM branch office serving your locality. If you request publications from the address given below, your order will be delayed because publications are not stocked there. A Reader's Comment Form is provided at the back of this publication. If the form has been removed, comments may be addressed to IBM Corporation, Department J58, P. O. Box 49023, San Jose, California, U.S.A. 95161-9023. IBM may use or distribute what- ever information you supply in any way it believes appropriate without incurring any obligation to you. Copyright International Business Machines Corporation 1984, 1994. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Notices . x Programming Interface Information ........................... x Trademarks . x About This Book ..................................... xi Who Should Read This Book .............................. xi | APL2 Publications . xi Conventions Used in This Book ............................. xii | Summary of Changes ................................. xiv | Products . xiv Chapter 1. APL2 in Action ............................... 1 Interaction . 1 Workspaces . 2 Sample Use of APL2 ................................... 2 Chapter 2. Arrays . 5 Structure . 5 Rank . 5 Shape . 6 Depth . 8 Data . 10 Numeric Data . 10 Character Data . 13 Construction of Arrays ................................. 14 Vector Notation . 14 Using Functions to Create Arrays ......................... 15 Display of Arrays .................................... 17 Simple Scalars and Vectors ............................ 17 Simple Matrixes and Other Multidimensional Arrays .............. 17 Nested Arrays . 19 Chapter 3. Syntax and Expressions ........................ 20 Summary of Syntax and Evaluation of Expressions ................ 20 APL2 Syntax . 22 Functions . 23 Operators . 24 Names . 24 Syntactic Construction Symbols .......................... 27 Expressions . 27 Defined Functions and Operators ......................... 31 System Functions and System Variables ..................... 31 Evaluating Expressions . 32 Expressions with More Than One Function and No Operators ........ 32 Determining Function Valence ........................... 33 Name and Symbol Binding ............................. 33 | Multiple Expressions in a Line ........................... 36 Parentheses . 36 Specification of Variables .............................. 39 Copyright IBM Corp. 1984, 1994 iii Conditions for Axis Specification .......................... 45 Chapter 4. General Information . 46 Type and Prototype ................................... 46 Fill Item . 47 Empty Arrays . 48 Prototypes of Empty Arrays ............................. 49 Empty Arrays and Nesting ............................. 50 Scalar and Nonscalar Functions ............................ 51 Monadic Scalar Function .............................. 53 Dyadic Scalar Function ............................... 54 Fill Functions . 56 Fill Function for Primitive Scalar Functions .................... 56 Fill Functions for Primitive Nonscalar Functions ................. 57 System Effects on Evaluation ............................. 57 Size Limitations . 57 Precision . 58 Comparison Tolerance . 58 System Tolerance . 59 Errors and Interrupts in Immediate Execution .................... 59 Shared Variables . 60 Chapter 5. Primitive Functions and Operators ................. 62 APL2 Expressions Used in the Descriptions ................... 63 Meta Notation Used in Descriptions ........................ 64 Multivalued Functions . 64 + Add . 65 Binomial . 66 Boolean Functions . 68 [] Bracket Index .................................... 70 ,Catenate . 74 ,[] Catenate with Axis ................................ 77 Ceiling . 79 ○ Circle Functions .................................... 80 Circular Functions . 82 Hyperbolic Functions . 83 Pythagorean Functions . 83 Complex Number Functions ............................ 84 / Compress (from Slash) ............................... 85 /[] [] Compress with Axis (from Slash) .................... 86 + Conjugate . 88 Deal . 89 ⊤ Decode . 90 Depth . 91 Direction . 93 Disclose . 94 [] Disclose with Axis ................................ 96 ÷ Divide . 100 ↓ Drop . 101 ↓[] Drop with Axis ................................... 105 ¨ Each (Dyadic) ..................................... 107 ¨ Each (Monadic) .................................... 109 Enclose . 111 [] Enclose with Axis ................................. 113 iv APL2 Programming: Language Reference Encode . 116 ε Enlist . 118 Execute . 120 Expand (from Backslash) .............................. 122 [] []Expand with Axis (from Backslash) .................... 124 * Exponential . 127 Factorial . 128 Find . 129 ↑ First . 131 Floor . 133 Format (Default) ................................... 135 Format by Example ................................. 139 Format by Specification ............................... 143 Grade Down ...................................... 147 Grade Down (with Collating Sequence) ...................... 149 Grade Up ....................................... 153 Grade Up (with Collating Sequence) ........................ 155 Index . 160 ι Index Of ........................................ 162 [] Index with Axis .................................. 163 Inner Product (from Array Product) ......................... 165 ι Interval . 168 ,[] Laminate . 169 Logarithm . 171 Magnitude . 172 Match . 173 ! Matrix Divide ..................................... 174 ! Matrix Inverse ..................................... 177 Maximum . 180 ε Member . 181 Minimum . 182 Multiply . 183 Natural Logarithm ................................... 184 | Negative . ..