![]() |
![]() |
|
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, ClassesIn APL, the term function is used for a basic program module. Functions can either be built-in to the APL interpreter (for example, the 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 ( 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 sizeThe workspace size is stated on the screen when you start an APL session. Depending on the workspace size, it's either expressed in 'K' or 'M' , where:
During the session you can find out how much space is free by using the system function For users of GUI versions of APLX (Windows, Macintosh and Linux), the initial workspace size can be changed using the APLX preferences dialog. You can also change the workspace size for a session by using the )CLEAR 50MB The initial size of the workspace also depends on how much random access memory (RAM) you have in your system and the amount of disk space reserved for virtual memory. Some of this is used by the operating system and other tasks, so you may not get a workspace as large as the one you requested. Do not set the workspace size to a value larger than the amount of RAM installed in your system or performance will be affected. Managing the workspaceThere 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. 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 commandsAt the start of a session, you're given an empty workspace which has the name You can get a list of the variable names in the workspace by using the If you don't want to clear the entire workspace, you can get rid of individual objects by using the command Loading and saving workspaces using the File menuFor GUI versions of APLX, the easiest way to save a workspace to disk is to use the "Save )SAVE" command in the File menu. If the workspace has not yet been saved, this will display a standard file selection dialog box asking you where you want to save it. On subsequent occasions, the copy of the workspace on disk will be updated each time you select Save again. To load a new workspace, select the "Open... )LOAD" item in the File menu. When you choose this menu item, a second dialog box usually appears to warn you that the operation you are about to perform will overwrite your current active workspace (you can disable this feature using the APLX Preferences dialog). This will only happen if you are not in a clear workspace. You will then be asked which workspace you want to load, using the standard file selection dialog box. The "Save As..." menu item allows you to save your current workspace under a new name. You will be asked to confirm if you try to overwrite an existing workspace. External workspace commandsAnother way to save a workspace is by typing the )SAVE myWorkspace 2008-08-06 12.10.54 APL responds by saving the workspace to disk under the specified file name, and displays the date and time at which the save operation happened, known as the timestamp. The 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 You can get rid of a workspace on a disc by using the To find out the names of the workspaces already stored on a disc, use the command You may be wondering where on the disk the workspaces are stored by a For example, if the first row of the mount table on a Windows version of APLX contains 'C:\Users\Fred\Documents', then the command A collection of workspaces in a folder is called a library. Each row of the mount table is numbered from 0 to 9, so you can select other rows by specifying a library number, e.g. )SAVE 3 myWorkspace 2008-08-06 12.22.07 This will save the workspace in the folder named by the fourth row of the mount table. The workspace ID includes the library number: )WSID 3 myWorkspace If a row of the mount table is blank (which is normally the case when you first install APLX), then the user's home folder will be used. The initial mount table when APLX starts up is set by your preferences. You can also change the mount table at any time using the Preferences dialog, or you can use the APL command If you specify a full path name when loading or saving a file, the mount table is bypassed and the file name is used as specified. For example: )SAVE 'C:\My Workspaces\Utilities\searchWS.aws' 2008-08-06 12.32.06 )WSID C:\My Workspaces\Utilities\searchWS.aws )LIB 'C:\My Workspaces\Utilities' searchWS In addition to the libraries 0 - 9, Library 10 is defined to refer to the folder where the APLX interpreter is located. It contains a number of demo workspaces which ship with the APL interpreter, e.g. )LIB 10 CONVERTQWI DISPLAY HELPDOTNET HELPDRAW HELPIMAGE HELPJAVA HELPOBJECTS HELPQWI HELPSYSCLASS HELPTRANSFORM PACKAGEDEMO SAMPLEEXCEL SAMPLESCHART SAMPLESQWI SAMPLESSYSCLASS TOOLKIT )LOAD 10 SAMPLESCHART SAVED 2007-12-12 10.47.50 APLX SAMPLESCHART Workspace Version 4.0 November 2007 This workspace contains functions showing various charts programmed using the Chart and Series objects. We recommend that you explore these demo workspaces as you will find a lot of useful material. System variablesWhat 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 10 You can change the value of most system variables by using the symbol ⎕PP ← 6 Other system variables you may occasionally want to enquire about or (in some cases) alter are (the full list is given in the APLX Language Manual):
System functionsWe've been discussing system variables. System functions can also affect your working environment. The system function Other system functions duplicate tasks performed by system commands. For example, the system function 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 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 the APLX Language Manual. Some of them have somewhat specialised applications, but many of them help with everyday tasks and are well worth knowing about.
|
Copyright © 1996-2008 MicroAPL Ltd