Setting PF keys and Other Initialization
Vector 5:4, page 97
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 97
I have always found it very convenient for program development to have such frequently used strings as ‘)EDIT’ and ‘)SAVE’ on programmed function keys. With APL*PLUS/PC these strings can be incorporated in the interpreter so that they are there when one starts up APL. Consequently, I was somewhat disappointed when I discovered that it is not possible to have preset PF keys with APL*PLUS II.
We have a number of PC based APL applications, all run via DOS batch files, each of which calls the batch file which runs APL, passing to it the name of the desired workspace. The obvious thing to do to get values on PF keys, without having to edit every workspace, is to use an initializing workspace which, having done its work, loads the application workspace. The difficulty is: how to pass the name of the workspace? The technique I found makes use of the output redirection facility in DOS. My batch file to call APL*PLUS II has the following lines in it:
SET TEMP= %1 %2
IF X%1==X SET TEMP=?
ECHO %TEMP% > C:\TEMP\APLWS.NAM
SET TEMP=
D:\APLII\APLSM J=D:\APLII\XAPL387 Q='8 INIT'
The third line writes the name of the required workspace, or ‘?’ if none was specified, to a temporary file. The last line invokes APL, requesting a quiet load of the initializing workspace. (If you need to have parameters other than the workspace name passed to the APL-calling batch file, then the latter will have to be correspondingly more sophisticated.)
The latent expression in INIT performs the initialization, which clearly need not be restricted to setting up PF keys, and then calls the following function:
∇ GETWS;X
[1] ⍝ Retrieve the name of the ws the user wanted, and load it
[2] ⍝ If nothing requested, or error, then CLEAR
[3] ⎕SA←'CLEAR'
[4] X←¯2↓NCREAD 'C:\TEMP\APLWS.NAM'
[5] →('?'=1⍴X)/0
[6] ⍎'⎕LOAD''',X,''''
∇
The function NCREAD reads the contents of a native file as a character string (excluding any end-of-file marker); the carriage-return and line-feed, which DOS adds after the workspace name, are dropped. The loading is done via an execute so that, if an error occurs during the ⎕LOAD, the name of the requested workspace will be displayed (rather than just the name of the variable, X).