• Aucun résultat trouvé

Characteristics of APL

Dans le document APL/PC Version 2.1 (Page 118-124)

The remaining chapters of this part of the book describe APL in detail, giving the meaning of each symbol and discussing the various features of APL for the IBM Personal Computer.

These details should be considered in light of the nlajor characteristics of APL, which may be surrunarised as follows:

• The primitive objects of the language are arrays (lists, tables, lists of tables, etc.). For example, A + B is

meaningful for any conformable arrays A and B, the size of an array (pA) is a prinutive function, and arrays may be indexed by arrays, as in A [3 1 4 2].

• The syntax is silnpIe: there are only three statement types (name assignment, branch, or neither), there is no function precedence hierarchy, functions have either one, two, or no arguments, and prirnitive functions and defined functions (programs) are treated alike.

• The semantic rules are few: the definitions of primitive functions are independent of the representations of data to which they apply, all scalar functions are extended to other arrays in the saIne \vay (that is, itenl-by-item), and

pritnitive functions have no hidden efiects (so-called side-effects).

• The sequence control is simple: one statenlent type

ernbraces all types of branches (conditional, unconditional, computed, etc.), and the completion of the execution of any function always returns control to the point of use.

• External communications are established by means of variables, which are shared between APL and other systenls or subsystems (such as auxiliary processors).

These shared variables are treated both syntactically and semantically like other variables. A subclass of shared variables - system variables - provides convenient comnlunications between APL programs and their environment.

Chapter 3. Using APL 3-5

IBM Internal Use Only

The usefulness of the primitive functions is vastly expanded by operators, which modify their behaviour in a systematic manner. For example, reduction (denoted by /) modifies a function to apply over all elements of a list, as in + / L for summation of the items of L. The remaining operators are scan (running totals, running maxima, etc.), the axis

operator which, for example, allows reduction and scan to be applied over a specified axis (rows or columns) of a table, the outer product, which produces tables of values as in RATE 0 •

*

YEARS for an interest table, and the inner product, a simple generalisation of matrix product that is very useful in data processing and other non-mathematical applications.

The number of primitive functions is few enough that each is represented by a single, easily-read and easily-written symbol, yet the set of primitives embraces operations from simple addition to grading (sorting) and formatting. The complete set can be classified as follows:

Arithmetic: + - x ..

*

$ 0

I

L

r

!

m

Boolean and Relational: v A ItP 'Pi tv < S

=

~ > 'i!

Selection and Structural: / \ f ~ [ ; ] ... '" p

<1> ~ e

General: e 1 ? .1 T 1T &. ~ ~

3-6 APLjPC. Version 2.1

IBM Internal Use Only

Chapter 4. Fundamentals

Character Set . . . 4-6 Spaces . . . 4-8 Function . . . 4-8 Order of Execution . . . 4-9 Data . . . 4-10 Arrays . . . 4-10 Constants . . . 4-12 W orkspaces and Libraries . . . 4-13 Names . . . 4-14 Implementation Limits . . . 4-15

Chapter 4. Fundamentals 4-1

IBM Internal Use Only

Notes:

4-2 APL/PC, Version 2.1

IBM Internal Use Only

A typical statement in APL is of the form:

AREA+-3x4

The effect of the statement is to assign to the name

AREA,

the value of the expression 3 x 4 to the right of the specification arrow +-. The statement may be read informally as "AREA is three times four".

The statement is the normal unit of execution. Two primitive types occur: the specification shown above, and the branch, which serves to control the sequence in which the statements in a defined function (see Chapter 8, "Function Definition") are executed. There is also a third type of statement that may specify the use of a defined function without either a

specification or a branch.

A variant of the specification statement produces a display of a result. If the leftmost part of a statement is not a name followed by a specification, the result of the expression is displayed. For example:

12 14

3X4

PERIMETER+-2

x (3+4)

PERIMETER

The result of any part of a statement can be displayed by including the characters O+- at the appropriate point in the statement. Moreover, any number of specification arrows may occur in a statement. For example:

12 14

4

X+-2+0+-3xY+-4

x

Y

Entry of a statement that cannot be executed will cause an error message to be displayed, which indicates the nature of the error and the point at which execution stopped. For example:

Chapter 4. Fundamentals 4- 3

IBM Internal Use Only

X+5 3+(ZxX)

VALUE ERROR

3+(ZxX)

A

Following is a list of error messages, with information about the cause and suggested corrective action.

DEFN

DOMAIN

Misuse of V or 0 symbols:

1. Invalid function header.

2. Use of other than a name alone in reopening a function.

3. Improper request for a line edit or display.

Argument is not valid.

0- - IMPLICIT The system variable 0- - (for example,

OIO)

has been set to an inappropriate value, or has been localised and not been assigned a value.

INDEX INTERRUPT

LENGTH

Index value out of range.

Execution interrupted:

1. The input line being typed is ignored.

Begin typing again.

2. Execution was suspended within an APL statement.

TO RESUME EXECUTION, ENTER A BRANCI-I TO THE STATEMENT

INTERRUPTED Shapes not conformable.

4-4 APLjPC, Version 2.1

IBM Internal Use Only

RANK Ranks not conformable.

SI DAMAGE The state indicator (an internal list of suspended and pendent functions) has been damaged in editing a function or in carrying out an )

ERASE.

STACK FULL Too many nested functions called.

Definition of a very large function with V, DFX, DTF or

)IN.

SYMBOL TABLE FULL Too many names used. This error can be corrected by executing the following seq uences of commands:

SYNTAX

SYSTEM

Dans le document APL/PC Version 2.1 (Page 118-124)

Documents relatifs