14. Appendices#

14.1. Scalar Functions#

Function

Function

Conjugate

+ B

A + B

Plus

Negate

- B

A - B

Minus

Direction

× B

A × B

Times

Reciprocal

÷ B

A ÷ B

Divide

Magnitude

| B

A| B

Residue

Floor

B

A B

Minimum

Ceiling

B

A B

Maximum

Exponential

* B

A * B

Power

Natural Logarithm

B

A B

Logarithm

Pi Times

B

A B

Circular Functions

Factorial

! B

A ! B

Binomial

Not

~ B

Not a scalar function

Roll

? B

Not a scalar function

A B

AND / LCM

A B

OR / GCD

A B

NAND

A B

NOR

A < B

Less Than

A B

Less Than Or Equal To

A = B

Equal To

A B

Greater Than Or Equal To

A > B

Greater Than

Not a scalar function

A B

Not Equal To

Same

B

Not a scalar function

Same

B

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

)ed New

Function

)ed Borscht

Function

-

)ed - papyrus

Simple character matrix

)ed crouton

Simple character vector

)ed grunt

Nested vector of character vectors

)ed Ns

Namespace script

)ed Myclass

Class script

)ed Bridge

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

(6⍴mat) vec

/ and

Compress/replicate

(bin/vec1) vec2

Take

(2 2↑mat) 2 2⍴⍳4

Drop

(5↓vec1) vec2

,

Ravel

(,mat) vec

Enlist

(∊vec1) vec2

Table

(⍪cuboid) mat

and

(⌽vec1) 20↑vec2

(⍉mat1) mat2

Disclose/pick

(((2 3)(4 1))⊃nest) ← ‘APL’

\ and

Expand

(bin\vec1) vec2

Index

(3 2⌷mat) ← 0

In the examples above:

• vec, vec1, vec2 represent vectors;

• mat, mat1, mat2 represent matrices;

• cuboid represents a 3D array; and

• bin represents a Boolean vector.

14.4. Dyalog APL Operators#

The following table of primitive operators in Dyalog APL uses the following conventions:

• f and g represent functions: primitive, user defined or derived from another operator;

• X and Y represent the left and right arguments of the derived function, respectively;

• A and B 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

f¨Y

⍴¨Y

D

X Y

3↑¨Y

Reduce

M

M

f/Y

+/Y

Reduce $$n$$-Wise

M

D

X f/Y

2+/Y

Reduce First

M

M

f⌿Y

+⌿Y

Reduce First $$n$$-Wise

M

D

X f⌿Y

2+⌿Y

Axis(*)

D

M

f[n] Y

↓[1]Y

D

X f[n] Y

X,[1]Y

Scan

M

M

f\Y

×\Y

Scan First

M

M

y⍀Y

×⍀Y

Outer Product

D

D

X ∘.f Y

X ∘.< Y

Inner Product

D

M

X f.g Y

X +.× Y

Commute

M

M

f⍨ Y

=⍨ Y

D

X f⍨ Y

X-⍨Y

Constant

M

M

A⍨ Y

3⍨¨Y

D

X A⍨ Y

X 0⍨ Y

Beside

D

M

f∘g Y

⍴∘⍴Y

D

X f∘g Y

3↑∘⍴¨Y

Bind

M

A∘g Y

2 2∘⍴¨Y

M

(f∘B) Y

,∘'...'¨Y

Over

D

M

f⍥g Y

÷⍥|Y

D

X f⍥g Y

X⌈⍥|Y

Atop

D

M

f⍤g Y

-⍤÷Y

D

X f⍤g Y

X⍴⍤,Y

Rank

D

M

(f⍤B) Y

(⍋⍤1)Y

D

X (f⍤B) Y

X(+⍤0 1)Y

At (indices)

D

M

(A@B) Y or (f@B) Y

(0@2 4)Y

D

X (f@B) Y

10(×@2 4)Y

D

M

A@g Y or f@g Y

÷@(2∘|)Y

D

X f@g Y

X×@(2∘|)Y

Spawn

M

M

f& Y

⌹&Y

D

X f& Y

X⍳&Y

Power (repeat)

D

M

(f⍣B) Y

(⊃⍣3)Y

D

X (f⍣B) Y

1(+⍣5)10

Power (until)

D

M

f⍣g Y

(⊃⍣≡)Y

D

X f⍣g Y

1+∘÷⍣=1

Key

M

M

f⌸ Y

,⌸Y

D

X f⌸ Y

X,⌸Y

Stencil

D

M

(f⌺B) Y

({⊂⍵}⌺2 2)Y

I-Beam

M

M

N⌶ Y

8415⌶Y

D

X (N⌶) Y

1(219⌶)⍳10

Variant

D

M

(f⍠B) Y

('a'⎕S 0)⍠1⊢Y

D

X (f⍠B) Y

0(⎕JSON⍠'Dialect' 'JSON5')Y

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.

F

F/⍬

Identity on what side

+

0

×

1

-

0

right

÷

1

right

*

1

right

¯1.7977E308⁽*⁾

1.7977E308⁽*⁾

1

0

<

0

1

=

1

1

>

0

0

or ''

`

0

!

1

left

0

left

and

0

left

/ and

1

left

\ and

1

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
┌────┬─────────────────────────────────────────────────┬────┬──────────────────────────────────────────────┐ │1 │WS FULL │2 │SYNTAX ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │3 │INDEX ERROR │4 │RANK ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │5 │LENGTH ERROR │6 │VALUE ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │7 │FORMAT ERROR │10 │LIMIT ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │11 │DOMAIN ERROR │12 │HOLD ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │13 │OPTION ERROR │15 │LST FULL │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │16 │NONCE ERROR │17 │ACCESS ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │18 │FILE TIE ERROR │19 │FILE ACCESS ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │20 │FILE INDEX ERROR │21 │FILE FULL │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │22 │FILE NAME ERROR │23 │FILE DAMAGED │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │24 │FILE TIED │25 │FILE TIED REMOTELY │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │26 │FILE SYSTEM ERROR │28 │FILE SYSTEM NOT AVAILABLE │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │30 │FILE SYSTEM TIES USED UP │31 │FILE TIE QUOTA USED UP │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │32 │FILE NAME QUOTA USED UP │34 │FILE SYSTEM NO SPACE │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │35 │FILE ACCESS ERROR - CONVERTING FILE │36 │INCOMPATIBLE ARRAY │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │38 │FILE COMPONENT DAMAGED │52 │FIELD CONTENTS RANK ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │53 │FIELD CONTENTS TOO MANY COLUMNS │54 │FIELD POSITION ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │55 │FIELD SIZE ERROR │56 │FIELD CONTENTS/TYPE MISMATCH │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │57 │FIELD TYPE/BEHAVIOUR UNRECOGNISED │58 │FIELD ATTRIBUTES RANK ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │59 │FIELD ATTRIBUTES LENGTH ERROR │60 │FULL-SCREEN ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │61 │KEY CODE UNRECOGNISED │62 │KEY CODE RANK ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │63 │KEY CODE TYPE ERROR │70 │FORMAT FILE ACCESS ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │71 │FORMAT FILE ERROR │72 │NO PIPES │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │73 │LOST SLAVE │76 │UNABLE TO FORK PROCESS │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │84 │TRAP ERROR │86 │FUTURE ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │90 │EXCEPTION │91 │EXTERNAL DLL EXCEPTION │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │92 │TRANSLATION ERROR │93 │UNACCEPTABLE CHARACTER │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │94 │CHARACTER NOT REPRESENTABLE IN CLASSIC │98 │AFFIRM ERROR │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │99 │INTERNAL ERROR │101 │FILE ERROR 1 Operation not permitted │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │102 │FILE ERROR 2 No such file or directory │103 │FILE ERROR 3 No such process │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │104 │FILE ERROR 4 Interrupted function call │105 │FILE ERROR 5 Input/output error │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │106 │FILE ERROR 6 No such device or address │107 │FILE ERROR 7 Arg list too long │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │108 │FILE ERROR 8 Exec format error │109 │FILE ERROR 9 Bad file descriptor │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │110 │FILE ERROR 10 No child processes │111 │FILE ERROR 11 Resource temporarily unavailable│ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │112 │FILE ERROR 12 Not enough space │113 │FILE ERROR 13 Permission denied │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │114 │FILE ERROR 14 Bad address │116 │FILE ERROR 16 Resource device │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │117 │FILE ERROR 17 File exists │118 │FILE ERROR 18 Improper link │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │119 │FILE ERROR 19 No such device │120 │FILE ERROR 20 Not a directory │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │121 │FILE ERROR 21 Is a directory │122 │FILE ERROR 22 Invalid argument │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │123 │FILE ERROR 23 Too many open files in system │124 │FILE ERROR 24 Too many open files │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │125 │FILE ERROR 25 Inappropriate I/O control operation│127 │FILE ERROR 27 File too large │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │128 │FILE ERROR 28 No space left on device │129 │FILE ERROR 29 Invalid seek │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │130 │FILE ERROR 30 Read-only file system │131 │FILE ERROR 31 Too many links │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │132 │FILE ERROR 32 Broken pipe │133 │FILE ERROR 33 Domain error │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │134 │FILE ERROR 34 Result too large │136 │FILE ERROR 36 Resource deadlock avoided │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │138 │FILE ERROR 38 Filename too long │139 │FILE ERROR 39 No locks available │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │140 │FILE ERROR 40 Function not implemented │141 │FILE ERROR 41 Directory not empty │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │142 │FILE ERROR 42 Illegal byte sequence │1003│INTERRUPT │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │1004│INPUT INTERRUPT │1005│EOF INTERRUPT │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │1006│TIMEOUT │1007│RESIZE │ ├────┼─────────────────────────────────────────────────┼────┼──────────────────────────────────────────────┤ │1008│DEADLOCK │- │- │ └────┴─────────────────────────────────────────────────┴────┴──────────────────────────────────────────────┘

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 655
90 160 420 500 20 30 110 450 170 370 290 360 340 190 320 120 510 370 150 460 240 520 490 280
⎕RL  73
actual  forecast + ¯10+?4 620
89 166 420 508 12 23 111 453 177 365 284 352 349 192 329 115 515 374 160 467 234 519 485 283

14.7.2. salaries – numeric vector#

⎕RL  73
salaries  ?205000
2121 4778 4914 3139 4561 221 1252 1530 4475 332 3507 1829 1710 4964 3849 669 3653 3415 3867 151

14.7.3. ages – numeric vector#

⎕RL  73
20ages  ?400100  ⍝ We are only printing the first 20 items of the 400.
73 16 42 50 2 67 11 81 37 93 100 98 83 32 76 51 37 15 46 88

Used in Back to Primary School and Inner Product.

14.7.4. prod – numeric cuboid#

⎕RL  73
prod  ?5 2 1250
9 16 42 50 2 3 11 45 17 37 29 36 34 19 32 12 37 15 46 24 49 28 36 9 29 5 45 23 27 4 23 16 39 22 22 2 46 20 47 17 18 25 13 38 42 38 45 28 37 19 5 10 30 49 16 18 46 47 47 3 39 23 41 20 6 40 21 22 40 49 20 1 13 36 12 40 12 15 24 20 21 12 19 25 8 48 22 37 33 1 39 30 50 50 8 35 38 31 24 40 23 7 20 34 35 6 19 27 41 1 14 50 17 42 6 35 12 48 30 29

14.7.5. monMat – character matrix#

monMat  6 8'January FebruaryMarch   April   May     June    '
January February March April May June

14.7.6. nesMat – mixed nested matrix#

nesMat  2 3  'Dyalog' 44 'Hello' 27 (2 2  8 6 2 4) (2 31 2 0 0 0 5)
┌──────┬───┬─────┐ │Dyalog│44 │Hello│ ├──────┼───┼─────┤ │27 │8 6│1 2 0│ │ │2 4│0 0 5│ └──────┴───┴─────┘

14.7.7. chemistry – character matrix#

chemistry  3 5'H2SO4CaCO3Fe2O3'
H2SO4 CaCO3 Fe2O3

14.7.8. nm – numeric matrix#

⎕RL  73
nm  (?3 4200000)÷100
21.21 1534.88 375.46 704.5 1125.14 1963.52 464.45 1438.25 796.53 1569 157.14 886.59

14.7.9. weird - mixed doubly nested matrix#

weird  2 2456 (2 2 'Dyalog' 44 27 (2 28 6 2 4)) (17 51) 'Twisted'
┌─────┬────────────┐ │456 │┌──────┬───┐│ │ ││Dyalog│44 ││ │ │├──────┼───┤│ │ ││27 │8 6││ │ ││ │2 4││ │ │└──────┴───┘│ ├─────┼────────────┤ │17 51│Twisted │ └─────┴────────────┘