Appendices
Contents
14. Appendices#
14.1. Scalar Functions#
Function |
Monadic |
Dyadic |
Function |
---|---|---|---|
Conjugate |
|
|
Plus |
Negate |
|
|
Minus |
Direction |
|
|
Times |
Reciprocal |
|
|
Divide |
Magnitude |
|
|
Residue |
Floor |
|
|
Minimum |
Ceiling |
|
|
Maximum |
Exponential |
|
|
Power |
Natural Logarithm |
|
|
Logarithm |
Pi Times |
|
|
Circular Functions |
Factorial |
|
|
Binomial |
Not |
|
Not a scalar function |
|
Roll |
|
Not a scalar function |
|
|
AND / LCM |
||
|
OR / GCD |
||
|
NAND |
||
|
NOR |
||
|
Less Than |
||
|
Less Than Or Equal To |
||
|
Equal To |
||
|
Greater Than Or Equal To |
||
|
Greater Than |
||
Not a scalar function |
|
Not Equal To |
|
Same |
|
Not a scalar function |
|
Same |
|
Not a scalar function |
14.2. Invoking the Editor#
The editor provided with Dyalog APL can be invoked by double-clicking the name of an existing object. Then the editor knows the type of the object and adapts its behaviour accordingly.
The system command )ED
opens the editor and can be used to create a new object. By default a new function is created.
A prefix can be used to specify the type of the new object, according to the following table:
Prefix |
Example |
Object Created |
---|---|---|
none |
|
Function |
|
|
Function |
|
|
Simple character matrix |
|
|
Simple character vector |
|
|
Nested vector of character vectors |
|
|
Namespace script |
|
|
Class script |
|
|
Interface script |
It is possible to open several edit windows using a single command. For example, )ed Tyrex -moose
will open two edit windows. The first to create or edit a function named Tyrex
and the second to create a character matrix named moose
.
If a prefix is specified for the name of an already existing object, the prefix is ignored and the editor is invoked according to the type of the existing object.
More information is available at Dyalog’s help page for the “Edit Object”.
14.3. Selective Assignment#
Selective assignment cannot be used with every single primitive function; only the following selection functions are allowed. When appropriate, these functions can also be used with an axis specification:
Function |
Name |
Example |
---|---|---|
|
Reshape |
|
|
Compress/replicate |
|
|
Take |
|
|
Drop |
|
|
Ravel |
|
|
Enlist |
|
|
Table |
|
|
Reverse/rotate (monadic & dyadic) |
|
|
Transpose (monadic & dyadic) |
|
|
Disclose/pick |
`(((2 3)(4 1))⊃nest) ← ‘APL’ |
|
Expand |
|
|
Index |
|
In the examples above:
vec
,vec1
,vec2
represent vectors;mat
,mat1
,mat2
represent matrices;cuboid
represents a 3D array; andbin
represents a Boolean vector.
14.4. Dyalog APL Operators#
The following table of primitive operators in Dyalog APL uses the following conventions:
f
andg
represent functions: primitive, user defined or derived from another operator;X
andY
represent the left and right arguments of the derived function, respectively;A
andB
are arrays and they represent left and right operands, respectively;N
also represents an array operand, specifically a numeric one;a distinction is made between the syntax of the operator itself (“Op” in the table below) and the syntax of its derived function (“Fun” in the table below), as a monadic operator can generate a dyadic derived function or a dyadic operator can generate a monadic derived function; the syntax is indicated by M for Monadic and D for Dyadic.
Name |
Op |
Fun |
Notation |
Example |
---|---|---|---|---|
Each |
M |
M |
|
|
D |
|
|
||
Reduce |
M |
M |
|
|
Reduce \(n\)-Wise |
M |
D |
|
|
Reduce First |
M |
M |
|
|
Reduce First \(n\)-Wise |
M |
D |
|
|
Axis(*) |
D |
M |
|
|
D |
|
|
||
Scan |
M |
M |
|
|
Scan First |
M |
M |
|
|
Outer Product |
D |
D |
|
|
Inner Product |
D |
M |
|
|
Commute |
M |
M |
|
|
D |
|
|
||
Constant |
M |
M |
|
|
D |
|
|
||
Beside |
D |
M |
|
|
D |
|
|
||
Bind |
M |
|
|
|
M |
|
|
||
Over |
D |
M |
|
|
D |
|
|
||
Atop |
D |
M |
|
|
D |
|
|
||
Rank |
D |
M |
|
|
D |
|
|
||
At (indices) |
D |
M |
|
|
D |
|
|
||
At (mask) |
D |
M |
|
|
D |
|
|
||
Spawn |
M |
M |
|
|
D |
|
|
||
Power (repeat) |
D |
M |
|
|
D |
|
|
||
Power (until) |
D |
M |
|
|
D |
|
|
||
Key |
M |
M |
|
|
D |
|
|
||
Stencil |
D |
M |
|
|
I-Beam |
M |
M |
|
|
D |
|
|
||
Variant |
D |
M |
|
|
D |
|
|
Footnote
Strictly speaking, axis is not an operator, cf. the chapter on operators.
14.5. Identity Elements#
Reducing an empty vector v
using any function F/v
returns the identity element for the function F
, if such an identity element is defined.
Here is the list of the identity elements in Dyalog APL.
The last column specifies the side on which the element acts as the identity element in case the identity element does not work on both sides.
|
|
Identity on what side |
---|---|---|
|
|
|
|
|
|
|
|
right |
|
|
right |
|
|
right |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
` |
` |
|
|
|
left |
|
|
left |
|
|
left |
|
|
left |
|
|
left |
Functions that do not appear in this table will cause a DOMAIN ERROR
if they are used to reduce an empty vector.
Footnote
The identity elements for ⌈/
and ⌊/
are system-dependant and are, respectively, the smallest and the largest value supported by the system.
14.6. Event Numbers#
This page provides a reference table with all the event numbers and their assigned meanings.
We build the table by making use of the ⎕EM
system function, and then we filter event numbers that do not have an assigned meaning.
data ← ('-' '-'),⍨,(⍪,⎕EM¨)({(⊂⍬)≡¨('^$' '^ERROR \d+$' '^FILE ERROR \d+ Unknown error$'⎕S⊢)∘⎕EM¨⍵}⊢⍤⌿⍪)⍳2000
data⍴⍨(⌊4÷⍨≢data) 4
14.7. Variables#
This appendix lists variables and utility functions that are used repeatedly throughout the book, ordering them by first usage.
14.7.1. forecast
and actual
– numeric matrices#
⎕RL ← 73
⎕← forecast ← 10×?4 6⍴55
⎕RL ← 73
⎕← actual ← forecast + ¯10+?4 6⍴20
Used in Array Processing, Most Symbols Have a Double Meaning, Calculating Without Writing Functions, Some Scalar Dyadic Functions, Processing Binary Data, Axis Specification, Catenate, Ravel, Tradfns, Exercises on Tradfns, When an Error Occurs, Most Frequent Error Messages, Laminate, Expand, and More on Dyadic Transpose.
14.7.2. salaries
– numeric vector#
⎕RL ← 73
⎕← salaries ← ?20⍴5000
Used in Calculating Without Writing Functions, Friendly Binary Data, Reduce, Our First Program, and Input, Output, and Format.
14.7.3. ages
– numeric vector#
⎕RL ← 73
⎕← 20↑ages ← ?400⍴100 ⍝ We are only printing the first 20 items of the 400.
Used in Back to Primary School and Inner Product.
14.7.4. prod
– numeric cuboid#
⎕RL ← 73
⎕← prod ← ?5 2 12⍴50
Used in Arrays of Items, Shape, Rank, and Vocabulary, Indexing, Mixed and Nested Arrays, Workspaces and Commands, The Shape of the Result of Indexing Axis Specification, Catenate, Index Generator of Arrays, Ravel with Axis, Fractional Axis, Take and Drop, Expand, Dyadic Transpose, and Section 11.14.
14.7.5. monMat
– character matrix#
⎕← monMat ← 6 8⍴'January FebruaryMarch April May June '
Used in
Simple Character Values,
Processing Binary Data,
Where,
Index Generator of Arrays,
The ⎕FMT
System Function,
Rotate, and
Selective Assignment.
14.7.6. nesMat
– mixed nested matrix#
⎕← nesMat ← 2 3 ⍴ 'Dyalog' 44 'Hello' 27 (2 2 ⍴ 8 6 2 4) (2 3⍴1 2 0 0 0 5)
Used in Mixed and Nested Arrays, Input, Output, and Format, The Format Primitive, and First Contact.
14.7.7. chemistry
– character matrix#
⎕← chemistry ← 3 5⍴'H2SO4CaCO3Fe2O3'
Used in
Replicate,
Position (Index Of),
Ravel,
Ravel with Axis,
Border Cases,
Input, Output, and Format,
Syntax Considerations,
The Format Primitive,
The ⎕FMT
System Function,
Expand,
Rotate,
Split and Mix, and
High-rank Partition.
14.7.8. nm
– numeric matrix#
⎕RL ← 73
⎕← nm ← (?3 4⍴200000)÷100
Used in
Input, Output, and Format,
The Format Primitive,
The ⎕FMT
System Function, and
Processing Nested Arrays.
14.7.9. weird
- mixed doubly nested matrix#
⎕← weird ← 2 2⍴456 (2 2⍴ 'Dyalog' 44 27 (2 2⍴8 6 2 4)) (17 51) 'Twisted'
Used in Mixed and Nested Arrays, Pick, Reach Indexing, and Function Composition.