An Introduction to APL for analysis and planning
APL, A Programing Language,( A Personal Language )
BY A. M. Stevens ams

APL because of its array handling ability, range of primitive functions and operators is a useful notation for describing the many types of models used for component and systems analysis. It can also be used for routine data processing and many other computer based activities. It is especially useful for working directly on the computer display for the kinds of problems that traditionally are done with paper, pencil and calculator .One of the advantages is that the notation is machine readable, and paper or computer file copies can be made of the work.

APL allows considerable variation in style. These notes reflect my personal style. The intent is to illustrate the structure and capability of what I consider a general purpose tool. You may wish to use another style and/or LANGUAGE that is more suitable to your knowledge, personality and preferences. However some knowledge of APL may be useful for communication and comparison purposes.

APL was invented by K. E. Iverson as an algorithmic notation. It uses a number of special symbols, Many of these can be found in the lower case Greek alphabet. The J language is a modern APL dialect which uses only symbols found on the regular ASCII keyboard.

APL was first implemented by an IBM team as APL/360 for IBM 360 computers. It is available in many versions. There is an INTERNATIONAL Standard.

MYSYS is based on APL*PLUS/PC (version 11.1).  It was marketed first by Scientific Time Sharing, and later by MANUGISTICS inc. The latest versions are marketed by ALP2000 who have succeeded MANUGISTICS.
MYS2 uses APL*PLUS II, version 5.1 which was an expanded version that includes some of the features of APL2 which was developed and is marketed by IBM.  The versions used are 'Application Development' systems, and were licensed to UNB. They are generalized tool kits and system development platforms for use on personal computers.
These notes are part of MYNET that have been converted from MYSYS to HTML for display with a browser.

MYSYS is my customized version that has evolved for my personal use. It began with APL360 in 1974. It is made available to use as you see fit.

APL is an interpretative interactive language that defaults to Immediate execution mode. I refer to this as APLie . APL is terse, has a large set of symbols that are an extension of tradition arithmetic and algebraic in fix notation. It differs from common algebraic notation because it interprets expressions from right to left.

APL does not have precedence rules like algebra. It relies on the right to left sequence and levels of parentheses ( ) to establish the order of execution.

APL is said to have a rich set of primitives, i.e. functions and operators like +-, etc. The set continues to grow slowly as APL evolves. The primitives specify many actions with a single symbol which require considerable code in other languages.

To make extensive use of  any version of APL you should obtain a copy of the system documentation.

The SYSHELP distributed with the APL*PLUS systems includes help on all APL primitives and other system features. Key [F6] of  MYSYS executes qask, a general query function. Enter HELP or MYHELP at the prompt for a help directory. Many APL and MYSYS functions are described in the various 'help files'. The helps are a forward chaining expert system.

APL uses a random access memory segment called ACTIVE WORKSPACE (ws). The ws name is displayed on status line that also shows the keyboard type and other status indicators.

The primitives are available by keystrokes from the keyboard. There are several APL keyboards in use. This is called the TEXT or UNIFIED keyboard. Key [F6] and ask for 'keyboard' for a map. The APL360 keyboard was restricted by the number of symbols available on a 'selectric typewriter' terminal.

The keyboard map that you are using may be another standard or customized version. The layout can be discovered by systematically pressing each key including combinations of [Shift], [Ctrl], [Alt], and [Shift Alt] with the other keys.

A little patience and a superficial knowledge of where the various APL primitives are located on your keyboard is necessary to get started. Keep a hard copy of a keyboard layout handy until you are familiar with the locations. Modern versions of APL include other 'tricks' that are not shown on a keyboard map, but are part of the 'session manager'.

APL uses 'objects' referred to as variables (numeric and character) and functions (which are sometimes called programs in other computer languages).

Consult 'APL language' by IBM; texts such as 'APL IS EASY'; 'APL an interactive approach' by GILMAN and ROSE; SHARP APL Manual; or APL*PLUS/PC documentation for more information.

When the 'Enter' key is pressed the line on the screen where the cursor is positioned is interpreted by this version of APL. This is called Entering in these notes.

An Entered line is interpreted and if it follows APL syntax, it is 'executed' and the result displayed, otherwise an error message is displayed describing why the interpretation failed

APL expressions (lines) in this system can be up to 255 characters long and are read from right to left.

Functions behave like verbs, variables and constants like nouns, etc. They can be combined as in mathematics. Eg. 3+4 is a sequence of the constant 3, the primitive function + and the constant 4.

If 3+4 is Entered on one line the result 7 will show on the next. This is APL in 'immediate execution mode'.

The above example will work with a+b, where a and b are variable names as used in algebra. Values must be assigned to a and b for APL to interpret the a+b expression, otherwise a 'value error' will result.

Values are assigned by using  as follows: a3, and b4 will produce the same result as 3+4. This is a dyadic or two variable use of the primitive function +.

The familiar y=a+b is written as ya+b in APL.

A variable may contain numeric or character data. It may be a singleton, a vector, which is a one dimensional list; or a multidimensional array. The shape of a variable can be determined by the shape function û. Eg. ûTEXT will determine the shape of the character variable TEXT.

It is not necessary to know very much about APL to use it or a system written with it as the background language. This system (MYSYS) normally leaves the user in a ready mode in an active workspace and clears the state indicator after an error.

If the system is disrupted enter: )RESET and try again. If failure continues, perhaps there is an error in the proceedure that you are trying to use or you are trying to achieve a result beyond the capabilities of the system.

If the system locks up it can be restarted by Keying: Ctrl, Alt, and Del at the same time and waiting for the loading process to take place.`

A modern APL system for a microcomputer will provide a full set of tools including facilities for report preperation and graphics, file handling, data enrty and the other desireable features for individual analysis of fairly large activity models.

It will also provide facilities for mainframe communication and interfaces to routines written in other languages.

Because APL is an array language, many of the techniques used for languages based on singletons are unnecessary. This and the mathematical type notation simplify the code required for many proceedures.

APL uses square brackets [ ] for indexing n dimensional arrays. The indicies within the brackets are seperated by semicolons ;. Eg. a[2;3;4] refers to element in plane 2, row 3, column 4 of array 'a'.

Using arrays and because APL is an interpretative also means that many algorithms based on looping and suitable for other languages should not be used in APL. Algorithms should use matrix and other array proceedures where convenient.

It is not necessary to understand all the functions, operators; system commands, functions and variables to use APL. Most APL users learn only the subset that is personally useful and enlarge their knowledge as required. It is much like using any language; you can start small and let your vocabulary and syntax grow.

The minimal useful set is familiar algebraic notation and by the addition of a few others to your tool kit you can do work of considerable complexity.

Texts and application descriptions illustrate powerful combinations of APL primitives known as 'idioms'. These are very useful to a constant or causual user. Some of theses are documented in the IDIOM help file.

APL also has a lengthy set of 'SYSTEM' COMMANDS, FUNCTIONS, VARIABLES and CONSTANTS. It is necessary to become familiar with:

)load 'wsname' to beging a previously saved workspace. 'wsname' can be any name beginning with a letter and up to 8 characters long. This version of APL does not distinguish between upper or lowercase letters for wsnames. It translates all to uppercase.`

)save will the workspace with the name shown on the status line. A workspace called 'clear' cannot be saved. This is the name of the default ws if none is named on startup.`

)wsid 'wsname' will change the name of the workspace to the name given in wsname. When using APL*PLUS on a PC the name includes the disk drive (library) number. 0 is the A: drive, 1 the B: dirve etc. On a hard disk system there can be many ' libraries'.`

It is good pratice to use )save periodically during your work to avoid loosing what you have done in the event of a system failure.`

)off to leave the APL system and return to the operating system. Be sure to use )save before using )off if you wish to save your work. )off unties files, erases the APL executor and active ws.`

 When you are in a workspace:

 )fns  ¦ to list FUNCTIONS;  [S6] if using MYSYS

 )vars  ¦ to list VARIABLES;  [S7] if using MYSYS`

 This APL has a 'line editor' that is active at all times on the
display and may be in 'replace' or 'insert' mode.

 APL*PLUS/PC has a full screen text and numeric editor. Use:
    )EDIT name
     or
    •edit 'name'`
The editor can also be used to define and edit functions. The editor chooses one of its three modes based on the type of object contained in the name used. If the name is not already in use it assumes that it is a character vector unless the name is prefixed by ì or #. The ì prefix idicates that the name is a function. The # prefix indicates a numeric array. In MYSYS use [F10] for )edit`

An APL implimentation is enhanced and constrained by: the HARDWARE, the Operating System, and the library of available utilities (UTILS and UVARS), and USER skill. My keyboard skills are poor so a variety of utilitiess are used to reduce the number of required keystrokes.`

For a schematic of MYSYS showing the files etc. [Enter] next. •tcff  ‘get 'x2'`

Early versions of APL used all sloping CAPS and the greek looking APL primitive symbols. The character constraint was the symbols that could be obtained from IBM model 2741 terminal. Many remember this version and avoid APL because of the funny looking type style. This should no longer be a constraint.`

As mentioned previously APL syntax is terse and intrepretation is from right to left. APL uses the following for describing ALGORITHMS. The OBJECTS are: FUNCTIONS including the primitives; VARIABLES including boolean, integer and floating point numbers and charater. The character set is based on an eight bit byte or 256 item atomic vector.`

APL is structured like the traditional math notation: y=f(x) which in APL becomes rfn x, or y=f(x,y) which becomes rx fn y or rfn (x,y) where: f denotes 'a function of' and fn 'function name'

An APL function is said to have 'valance and be: 'Nilidic' (valence = 0) no 'arguments', Eg. start 'Monadic' (valence = 1) right argument only, Eg. mean X 'Dyadic' (valence = 2) left and right arguments, Eg. a VSUM b

A function 'returns a result' when it assigns its output to a variable, eg. ra VSUM b.

'OPERATOR' is a special primitive function that can be used in conjunction with other primitives, Eg. / \ and . are the usual operators.`

Note: Character and Numeric Variables cannot be mixed in this version of APL. In other versions, especially those which allow the use of 'general' or 'nested' arrays allow mixed use of characters and numerics.

 Variables can be singletons, or multidimensional arrays
Some examples of APL syntax in immediate execution: Traditional Aritmetic & Algebraic like notation: 3’4` Some APL's allow a number of expressions on a line: 6ö5  4ö3  6+9+15` 3’4+2  2+3’4` 4-3’2  4’3-2’6  4’3ö6` The examples above demonstrate dyadic use of the primitives. Monadic use of some common primitives: +6  -6  ö6  ’6  ’ý6  ’0` Interpretation is modified by Parentheses ( ): 4’3-2’6  (4’3)-2’6` The inner nest of () is interpreted first starting at right: (6+(1-5)’6)+4ö2` The above are ok with vectors (arrays) of numbers: 3’6 7 8 9  6 7’6 5  3 4 5 - 2 3` Note that a singleton will operate on an array of any size but arrays must match in size and shape.` Unambiguous assigment using '' rather than '=' a3  b7  c2 5 9  a  b  c  a+b’c` For more examples [Enter] on the line below:

End to date, ams 990715