The Workspace (8 of 14)

The workspace as a container for the functions and data used to create a solution is a useful 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, where supported, 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, composed 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...

Functions can take 0, 1 or 2 arguments. For example, when used for subtraction - takes two arguments (a left argument and a right argument). Without the left argument it does negation (equivalent to 0 minus the right argument). The arguments to functions are always data (APL arrays). Functions usually act on whole arrays without the 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. (Classes are currently supported by Dyalog APL).

Workspace size

Exact details of workspace management vary from one APL to another, so the information in this section is only a guide...

Depending on the APL, the workspace size may be stated on the screen when you start an APL session. It's usually either expressed in 'K' or 'M' , where:

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

The initial workspace size is usually customisable, e.g. from the command line or a user preference item.

In some APLs you can also change the workspace size for a session by using the )CLEAR command with a parameter specifying the workspace size you want. For example:

      )CLEAR 50MB

(Implementation details will vary)

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, e.g. )CLEAR.)

There are also system commands for copying the current workspace to disc, reloading it into memory and doing other similar operations. These are mentioned below under the heading 'External workspace commands'.

The system variables and system functions also supply some useful facilities in this area, and are discussed in this chapter.

Internal workspace commands

Note: System commands vary from one APL vendor to another so you should check the documentation which comes with your copy of APL.

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 disc.

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 functions and the command )OPS gives the list of user-defined operators.

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

External workspace commands

For many versions of APL, the easiest way to save a workspace to disk is to use the "Save" command in the menu bar (or similar). To load a new workspace, select the "Open" item.

Another way to save a workspace is by typing the )SAVE system command, e.g.

      )SAVE myWorkspace
2008-08-06 12.10.54

APL responds by saving the workspace to disk under the specified file name, and typically displays the date and time at which the save operation happened, known as the timestamp.

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 disc by using the )DROP command.

To find out the names of the workspaces already stored on a disc, use the command )LIB.

You may be wondering where on the disk the workspaces are stored by a )SAVE operation? The answer is specific to the version of APL which you are using, so check your APL documentation for details.

System variables

Note: Like system commands, system variables vary from one APL vendor to another so you should check the documentation which comes with your copy of APL.

What goes on in the workspace is conditioned to some extent by the current settings of system variables.

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 change the value of most system variables by using the symbol  ← . For example, to change ⎕PP from its normal value to a value of 6 you would type:

      ⎕PP ← 6

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

System functions

We've been discussing system variables. System functions can also affect your working environment. These also vary from one APL vendor to another.

Some 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  )CLASSES  )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.)

System functions and variables are a mixed bag and have other purposes besides control of the workspace. They will be mentioned again under various other headings.

When you finish reading about Data in the next section, you should take a quick look at the system functions and variables in your APL documentation. Some of them have somewhat specialised applications, but many of them help with everyday tasks and are well worth knowing about.


CategoryAboutApl

LearnApl/AplWorkspace (last edited 2017-02-16 19:36:07 by KaiJaeger)