I would like to see )RSAVEOVER added as a feature.
It would be the RSAVE compliment to SAVEOVER and would allow us to replace a runtime workspace without having to erase the old one first.
/mas
A simple User Command can do the trick.
’ CMDRSAVEOVER A[1] A„²(+/^\' '=A)‡A[2] A„²(+/^\' '=A)‡A[3] :if 0¬½A[4] Œinbuf ')DROP ',A,Œtcnl,')RSAVE ',A,Œtcnl[5] :else[6] Œinbuf ')DROP ',Œwsid,Œtcnl,')RSAVE ',Œtcnl[7] :end ’
Note - line [2] is not a typo.
Examples of use:
ŒwsidC:\APLWIN50\RSAVEDWS ]rsaveover )DROP C:\APLWIN50\RSAVEDWSFriday, April 21, 2006 07:48:49 AM )RSAVE C:\APLWIN50\RSAVEDWS SAVED Friday, April 21, 2006 07:48:49 AM ]rsaveover rsavedws2 )DROP rsavedws2HOST ERROR DeleteFile 9015 0 2 The system cannot find the file specified. )RSAVE rsavedws2C:\APLWIN50\RSAVEDWS2 SAVED Friday, April 21, 2006 07:49:02 AM ]rsaveover )DROP C:\APLWIN50\RSAVEDWS2Friday, April 21, 2006 07:49:08 AM )RSAVE C:\APLWIN50\RSAVEDWS2 SAVED Friday, April 21, 2006 07:49:08 AM ]rsaveover rsavedws )DROP rsavedwsFriday, April 21, 2006 07:49:18 AM )RSAVE rsavedwsC:\APLWIN50\RSAVEDWS SAVED Friday, April 21, 2006 07:49:18 AM
OK - so line [2] is not a typo, but trailing blanks do not break the function. So I simplified the function to this:
’ CMDRSAVEOVER A[1] A„(+/^\' '=A)‡A[2] :if 0¬½A[3] Œinbuf ')DROP ',A,Œtcnl,')RSAVE ',A,Œtcnl[4] :else[5] Œinbuf ')DROP ',Œwsid,Œtcnl,')RSAVE ',Œtcnl[6] :end ’
I also have a need for )RSAVEOVER.
The reason for this is that if there is a machine problem such as a power failure between )DROP and )RSAVE (whether they are done manually or programmatically), the workspace is lost. To guard against this possibility I have to first save a backup copy of the ws and then do DROP and RSAVE
What if there is a machine failure during the )save?
I've take the strategy of naming workspaces serially. If my application name is MYAPP, I would save my workspace initially with the name of MYAPP1000. The next time I start a session of editing, I first load the workspace and rename it MYAPP1001. The I would periodically save the workspace as I edit. I might have several "versions" in a day. My runtime interpreter is named MYAPP.EXE. I have a workspace MYAPP.W3 that is very small, and it loaded with I run MYAPP.EXE. MYAPP.W3 looks for workspaces in the form of MYAPP9999.W3, and loads the one with the highest number. So my runtime system does not break. When I package up the program into a Setup program, I only need to change the name of the actual workspace that contains the latest version.
For saving the workspaces, I use a simple User Command I can MMSAVE, for "mirror save" or "multi-save" or "mirror multiple save". I have several disk drives with the same directory structure, so doing a MMSAVE would save the workspace to all of them. The command would be as follows:
]MMSAVE CDJ
This would save the workspace to the C: drive, D: drive, and J: drive. The User Command is here:
’ CMDMMSAVE drv;wsid;Œelx;d;nt;Œio;file;files;cmd[1] Œio„0[2] wsid„Œwsid[3] drv„(,¹drv)~' '[4][5] Œelx„'Œdm ª …end'[6] files„drv,¨›1‡wsid[7] cmd„''[8] :for file :in files[9] cmd„cmd,')wsid ',file,Œtcnl[10] cmd„cmd,')save ',Œtcnl[11] cmd„cmd,']openws ',file,Œtcnl[12] :end[13] cmd„cmd,')wsid ',wsid,Œtcnl[14] Œinbuf cmd[15] end:Œwsid„wsid ’
Note there is a nested User Command, ]OPENWS that creates an "open runtime" which is a workspace that can be loaded into any runtime interpreter or development interpreter. You can modify this User Command to RSAVEOVER type functions if you wish or any other functionally you'd like to add.
Using serially named workspaces also helps me not over write a perfectly good working workspace with new broken code, which is far more likely than having the machine fail during a save. I know!
As for power failures, I have a UPS on my desktop, and a built in UPS in the form of a battery in my laptop. But anything can happen....
What do others do?
A way to combat the "power" problem, would be to have the "RSAVEOVER" function, etc. write the new ws to a temp name first.
"rsave" tmpr
"rename" rws rold
"rename" tmpr rws
"drop" tmpr
I think I remember that is the way )SAVE works (except for saving "rold").
The staff is considering implementing )RSAVEOVER in APL+Win.APL2000 Support