If you use an index that refers to an element that does not exist in the array, the
instruction cannot be executed and INDEX ERROR results:
A
1.1. 12 I:# 1.4 1.5 1. h 17
A&#]
AC83
INDEX ERROR
A
You cannot index or do anything else with an array until after the array has been
specified. For example, suppose that no value has been assigned to the name 2;
then an attempt to store values in certain elements within 2 would result in an
error, since those elements do not exist:
z 1: 3 '4.3 4-1 El 46
z 1:: 3 '4.3 f- 1.8 4.6
VALlJE ERROR
A
Indices (whatever is inside the brackets) can be expressions, provided that when
those expressions are finally evaluated, the results are values that represent valid
indices for the array:
I3
ABC DE F' (3 H
I: ,JK I.. M NO PQ R S 7'1.1 V W X Y Z
xi-1 2 3 4 s
B C X X 2 3
X
BI:: l+XX33
b D FiH ,J
12343
LSG JM P
The array from which elements are selected does not have to be a variable. For
example, a vector can be indexed as follows:
2 3 5 7 9 1.1 13 1s 17 1.9c.7 2 4 23
' ABCDEFOHX JI{LMNOPQR!S'TUVWXYZ ' 1122 15 15 11. 2'7 1. b x :I
1.3 3 7 3
LAOK PA
40
Indexing a matrix or N-rank array requires an index number for each coordinate.
The index numbers for each coordinate are separated by semicolons. Suppose M is
a 3 by 4 matrix of consecutive integers:
If you ask to see the values of M, they are displayed in the usual matrix form:
M
1.234
5 b 7 8
9 1.0 xi 12
If ypu want to refer to the element in row 2, column 3, you would enter:
If you want to refer to the third and fourth elements in that row, you would enter:
c
MC2;3 11.1
‘7 8
Similarly, to refer to the elements in column 4, rows 1, 2, and 1, you would enter:
MC1 2 1;bl
4 8 Lc
You can use the same procedure to select a matrix within a matrix. If you want the
matrix of those elements in rows 2 and 3 and columns 1, 2, and 1 of M, you would
enter:
MC2 3;j. 2 13
565
9 1.0 9
If you do not specify the index number for one or more 0. the coordinates of the
array that you are indexing, APL assumes that you want the entire coordinate(s).
For instance, to get all of row 2, you would enter:
M c: 2 ; :I
56‘78 , (,‘I
1
c
41
Previous Page Next Page