Topic: APLX Help : Help on APL language : APL Fundamentals : The Workspace
[ Next | Contents | Index | APL Home ]

www.microapl.co.uk

The Workspace


The workspace is a fundamental concept in APL. It enables you to develop a project as a series of small pieces of program logic. These are organized into functions, operators and classes, as described below. (For brevity, we sometimes use the term 'function' in this discussion to refer to all three of these). All of these co-exist in the workspace and are instantly available for inspection, amendment, and execution - or for use on another project.

Data of all shapes and sizes (stored in variables) can inhabit the same workspace as the functions, and is also instantly available, which greatly facilitates testing. And, of course, the entire collection can be saved on to disk by a single command or menu option.

Functions, operators, and classes can quickly be constructed, tested, strung together in various combinations, and amended or discarded. Most importantly, it is very easy in APL to create test data (including large arrays), for trying out your functions as you develop them. Unlike many traditional programming environments, you do not need to compile and run an entire application just to test a small change you have made - you can test and experiment with individual functions in your workspace. This makes the workspace an ideal prototyping area for 'agile development', and helps explain why APL is sometimes referred to as a 'tool of thought'.

Functions, Operators, Classes

In APL, the term function is used for a basic program module. Functions can either be built-in to the APL interpreter (for example, the + function which does addition), or defined by the user as a series of lines of APL code. Functions can take 0, 1 or 2 arguments. For example, when used for addition + takes two arguments (a left argument and a right argument). The arguments to functions are always data (APL arrays). Functions usually act on whole arrays without need for explicit program loops.

An operator is like a function in that it takes data arguments, but it also takes either one or two operands which can themselves be functions. One of the commonly-used built-in operators is Each (¨). This takes any function as an operand, and applies it to each element of the supplied data arguments. Just as you can define your own functions as a series of lines of APL code, you can also define your own operators.

A class is a collection of functions and possibly operators (together known as methods), together with data (placed in named properties of the class). A class acts as a template from which you can create objects (instances of classes), each of which can have its own copy of the class data, but which shares the methods with all other instances of the class. A class can be used to encapsulate the behavior of a specific part of your application.

Workspace size

The workspace size is stated on the screen when you start an APL session. Depending on the workspace size, it is either expressed in 'KB' 'MB' or 'GB', where:

  • One 'GB' represents a Gigabyte, approximately a thousand million bytes
  • One 'MB' represents a Megabyte, approximately a million bytes
  • One 'KB' represents a Kilobyte, approximately a thousand bytes, and
  • One byte is (again approximately) the amount of computer memory used to store a single character.

During the session you can find out how much space is free by using the system function ⎕WA, which stands for Workspace Available.

The maximum size of the workspace depends on how much memory (RAM) you have on your system, and the amount of disk space reserved for virtual memory.

Managing the workspace

There are system commands for enquiring about the workspace and doing operations that affect it internally. The most useful of these are mentioned below under the heading 'Internal workspace commands'. (Note that, to distinguish them from names in your program, the names of system commands start with a right parenthesis.)

There are also system commands for copying the current workspace to disk, reloading it into memory and doing other similar operations. These are mentioned below under the heading 'External workspace commands'. You can either type these commands directly, or (on most versions of APLX) use the File menu to load and save workspaces.

Internal workspace commands

At the start of a session, you're given an empty workspace which has the name CLEAR WS. At any time you can return to this state by issuing the system command )CLEAR. Any variables or functions you have set up in the workspace are wiped out by this command, so if you want to keep them, you should first save the workspace on to a disk.

You can get a list of the variable names in the workspace by using the )VARS command. The command )FNS produces the equivalent list of user-defined functions, and the command )OPS gives the list of user-defined operators. The command )CLASSES lists the classes you have defined.

If you don't want to clear the entire workspace, you can get rid of individual items by using the command )ERASE followed by the name(s) of the items(s) you want to remove.

External workspace commands

Note: In practice, you will often use menus to load and save workspaces, rather than typing the system commands described below. For example, rather than typing )LOAD, you can use the File menu to open a dialog which allows you to select the workspace you want to load.

A collection of workspaces on a disk, or other storage medium, is a library. (It corresponds to a directory or folder in the host operating system). Unless you change the library number associated with each device, the device listed first when you type ⎕MOUNT '' (see below under 'System Functions') is Library 0, the next one is Library 1, and so on up to Library 9. (In most versions of APLX, you can set up these libraries using the Preferences item of the Tools or APLX menu). Most of the commands in this section can include the number (0, 1 or whatever) to indicate which library the command applies to. If no library number is given, APL assumes that library 0 is intended.

Library 10 is a special case. It contains the utility workspaces and examples supplied as part of the APLX installation.

The use of library numbers is a convenience which helps you organize your workspaces on disk, and saves you from having to enter long path names when referring to them. But if you prefer, you can enter the full path name to a workspace when you load and save it (or use the File menu).

To find out the names of the workspaces which you have already stored in library 0, use the command )LIB. To list the workspaces supplied with APLX, use: )LIB 10.

You can save the current workspace by simply issuing the command: )SAVE. Everything in the workspace is copied on to the disk and the saved workspace is given the same name as the workspace in memory. If you want the saved version to have a different name, you specify the (new) name immediately after the )SAVE (e.g. )SAVE NEWNAME).

The )LOAD command followed by the name of a workspace brings the named workspace back into memory. The workspace already in memory is overwritten.

If you want to bring specific functions or variables into memory, but don't want to overwrite the workspace already there, you can use the )COPY command.

You can get rid of a workspace on a disk by using the )DROP command.

System variables

What goes on in the workspace is conditioned to some extent by the current settings of system variables. These are built-in variables, whose names begin with ''.

Some system variables you may occasionally want to enquire about or (in some cases) alter are:

  • ⎕WA   Workspace available: the number of bytes available for use in the workspace.

  • ⎕PP   Print precision: the number of digits displayed in numeric output. The default setting is 10.

  • ⎕PW   Print width: the number of characters to the line. On most systems, the default setting is 80 (or the size of the visible window).

  • ⎕LX   Latent Expression: the expression or user-defined function in this variable is executed when the workspace is loaded. You might, for example, write a function which set things up for you when you started a session and assign its name to ⎕LX. Unless you assign a value to ⎕LX, it's empty.

You can find out the value of a system variable by typing its name. For example, to see the setting of ⎕PP, the variable which determines how many digits are displayed in numeric output, you would type:

      ⎕PP
10

You can reset the value of most system variables by using the symbol . For example, to change ⎕PP from its normal value of 10, to a value of 6, you would type:

      ⎕PP ← 6

System functions

We've been discussing system variables. System functions can also affect your working environment. The system function ⎕MOUNT, for example, is used to associate operating-system directories with the library identifiers you use in your programs.

Other system functions duplicate tasks performed by system commands. For example, the system function ⎕NL which stands for name list, can be used to produce a list of variables, functions, operators, or classes, and the system function ⎕EX can be used to expunge individual APL objects. Similar jobs are done by the system commands )VARS )FNS )OPS )CLASSES, and )ERASE.

The difference between system functions and system commands is that system functions are designed for use in user-defined functions, and behave like other functions in that they return results which can be used in APL statements. System commands, on the other hand, are primarily designed for direct execution and can only be included in a user-defined function if quoted as the text argument to the function (execute - a function which causes the expression quoted to be executed.)

There are many System Functions and Variables available in APLX. They have other purposes besides control of the workspace; for example they are used for reading and writing files, and for accessing databases, and for doing string-searches using regular expressions.


Topic: APLX Help : Help on APL language : APL Fundamentals : The Workspace
[ Next | Contents | Index | APL Home ]