Loops in Obey Files
Pages: 1 2
Andy S (2979) 504 posts |
It would be handy to be able to code loops inside an Obey file. I did look around to see if this was already supported but couldn’t find anything. I wonder if you could achieve the same effect by having an Obey file run itself recursively, passing in a count of how many times are left to run it, decrementing it, and stopping when it reaches zero. |
Clive Semmens (2335) 3276 posts |
I’m not sure what the advantage would be over the Obey file calling a wee BASIC program, that could do whatever else you wanted to do in the Obey file, and in which loops (and whatever else) would be no problem? |
Andy S (2979) 504 posts |
Yes you’re right that BASIC is the obvious and very powerful solution for scripting on our machines. I suppose I just feel like Obey files can already do a lot and a couple of extra features like loops would make them even more capable and a little closer in functionality to things like Linux shell scripts. |
Rick Murray (539) 13840 posts |
Hmmm, even MS-DOS batch files supported looping (by abusing GOTO). ;) But, it’s perhaps worth pointing out that Obey files (currently) aren’t fault tolerant. If there’s an error, everything will grind to a crashing halt. The current |
Clive Semmens (2335) 3276 posts |
But then A Mess DOS didn’t have a built-in, always-available equivalent of RISCOS’s BASIC. |
Rick Murray (539) 13840 posts |
I said it could do it. I didn’t say it was good (actually, I did reference the abuse if GOTO).
<cough> QBASIC </cough> That’s actually what got me started with C, fiddling around with TurboPascal, because QBASIC was really rather awful. Actually, I swiped TurboPascal from the college server, but found it mildly unpleasant 1 as it seemed to be as much trying to make a point as being a language. It amused me that Borland had to bastardise it greatly in order that it be capable of actually doing stuff. So when my A5000 that I bought second hand came with Cv4, I had some idea of what C was about (namely Pascal without the stick up its arse). It took a while to get used to C even so, because coming from BASIC some parts are mindscrewey. Entire books have been written on the subject of pointers, for instance. There’s a lot of clever stuff one can do, and equally much clever stuff one probably shouldn’t ever do (the language is totally okay with indirections off of negative array subscripts), not to mention the ‘ Anyway, via a torturous route, one can trace my use of C in RISC OS back to how awful QBASIC was on DOS, and my wanting to look for something better. I don’t think too much should be done to Obey. It’s not a shell in the Unix sense. However simple loops (or maybe just named jumps) would be good, as well as treating errors as not the end of the world, so the Obey file could then programatically handle them. Take a look at some larger resource heavy apps and marvel at the hoops the author jumped through in order to check and test in a way that wouldn’t upset things and throw an error. 1 As in mount it’s head on a pole and then set the whole thing on fire. Still far better than QBASIC, mind you. ;) |
Steve Pampling (1551) 8170 posts |
DOS didn’t have a built-in, always-available equivalent of RISCOS’s BASIC. Until you wrote that last bit, I was about to recommend a visit to your local mental health facility, and you totally redeemed yourself with the footnote. |
Clive Semmens (2335) 3276 posts |
Is QBASIC actually built-in and always available in A Mess DOS? If so, was it always? Shows you how little interest I ever took in PCs…before the BBC, we had Exidy Sorcerers running CPM at Shipley College…how A Mess DOS edged CPM out, I’ll never understand. Well, I do really: never mind the quality, feel the marketing… |
Steve Pampling (1551) 8170 posts |
GW Basic in the earlier stuff certainly. Wouldn’t adding to Julies CObey be the thing to do though? If you wanted additional features, that is. |
Rick Murray (539) 13840 posts | |
Dave Higton (1515) 3525 posts |
I found myself wishing, just a few days ago, that Obey files could have loops. My use case is that I can mount a share via either LanMan or LanMan98, but they result in two different paths. I call an Obey file to mount the share (I sometimes edit the Obey file to try the other one). It returns immediately, but the share is not yet mounted, so any attempt to access a file results in an error of course. If I could loop in an Obey file, I could waste time while multi-tasking and loop back until the share is mounted. I could do the whole thing in BASIC, but it would be rather specific to the application, so a looping Obey file would be a simpler and neater solution. |
Paolo Fabio Zaino (28) 1882 posts |
You actually can loop in obey files. I have created a “looper” as a script that one can call to loop through things. Here is the sources on the riscoscommunity on github: Some tests here to see how to use it: Hope this helps, P.S. ObeyLooper also allow the creation of nested loops |
Jon Abbott (1421) 2651 posts |
Multi-line IF statements anyone? From memory Obey performs some interesting tricks around environment handlers so it can intercept errors. It wouldn’t surprise if that breaks horribly when using recursive Obey files to emulate loops, possibly leaking RMA if an error occurs within a recursive Obey. That said I seem to recall it keeps a linked list so it can clean up so it might be okay. |
Andy S (2979) 504 posts |
I have created a “looper” as a script that one can call to loop through things. Nice work! I wanted to experiment with the recursive approach but you’ve just saved me the time and I don’t think I would’ve ever ended up with something so functional. It wouldn’t surprise if that breaks horribly when using recursive Obey files to emulate loops Oh. |
Paolo Fabio Zaino (28) 1882 posts |
@ Jon
Thanks for your suggestion! :) – I have added a test that generates an error in the BASIC tok1 file, to check what happens. Execution stops at the error, which is good, so no damage is done by the loop. I need to check if there is any RMA leakage, but by a quick look there seems to be no issues (however more testing is needed) Thanks againg and if others have ideas or tests to run please let me know :) New test is available in the repository linked on my original post (above). Cheers |
Bryan (8467) 468 posts |
Or, forget having an ‘obey’ file. Just use BASIC. In it’s simplest form, an obey file is a text file which is interpreted – just like BASIC. |
Clive Semmens (2335) 3276 posts |
I’m not at the Pi at the moment, so I can’t check – but doesn’t the OS expect to find !Boot and !Run in !xxxx applications directories, and doesn’t it expect them to be Obey files? Can they be BASIC? If so, I never knew that! Quite handy to set up a few things before the main BASIC program starts anyway, so I’d generally be chaining one BASIC program from the other anyway, but if the main program wasn’t in BASIC, I can see the advantage of chaining a C (or other) program from BASIC. |
Steve Fryatt (216) 2105 posts |
No, and no. It will act upon !Boot, !Run, !Help and !Sprites files (plus treat !RunImage as “special” for some limited things), but they don’t have to be there. The first three don’t have to be Obey files, either: they can be any executable type. I use BASIC for the !Help in my applications, for example, for more or less this reason. However, there has long been concern that this is the case, particularly for !Boot and, maybe to a lesser extent, !Run (and IIRC there was some tutting about my use of !Help back in the ROL days). The Filer will run every Boot file that it finds when folders are opened, so allowing any executable type here is arguably quite a brave design decision. Personally, I’d probably stick with Obey files for !Boot and !Run, and use them to chain small utilities if required along the way. It feels more “correct”, and – given the number of times that “make !Boot have to be an Obey file” comes up as a discussion – it also feels more “future proof”. |
Chris Mahoney (1684) 2165 posts |
!Run has to be there, does it not? Otherwise it won’t know what to do when you double-click on the app. |
Clive Semmens (2335) 3276 posts |
I knew you could omit !Help (often simply a text file in my apps) and !Sprites (although blank iconbar icons are a bit odd!) but it never occurred to me to omit !Boot or !Run 8~) |
Bryan (8467) 468 posts |
The only disadvantage I have found using a !Run file which is BASIC (and is in itself the main program) is that Obey$Dir is not set (and that can set at the start of the BASIC). Otherwise, an application can just consist of one BASIC file named !Run. |
Graeme (8815) 106 posts |
Also, if you omit !Boot, the OS will also do a *iconsprites !Sprites for you. When a !Boot file is included it is expected that you do this yourself as you may wish to load in different ones depending on a condition or have them in a non-standard location. |
Paolo Fabio Zaino (28) 1882 posts |
AFAIK, the only “required” file is !Run and only if one wants to double click on an !App. If one wants to use BASIC (or Lua, or any other language) instead, that is totally possible as long as such language has a Run_file defined and the interpreter is reachable by the Filer or is a module loaded in memory. The replacement language interpreter should be a Module so, if scripts call for an executable (given we are in single task land), things won’t go wrong. |
Rick Murray (539) 13840 posts |
I don’t think it’s a design decision so much as a design omission. The OS will run a file according to some predefined rules depending on type. The Filer will run certain files at certain times. Remember, this comes from an earlier more innocent time when an unvetted SWI to give any code complete kernel level access and putting network passwords on the wire in cleartext were both not considered world ending things.
For an app, yes.
Whether or not I use Boot depends on whether I need anything done when the app is first seen.
All the Obey module does is strip the path from the filespec passed to the *Obey command. A potentially more important issue, depending on use case, is that BASIC 1 has no support for long command lines. Obey… does. 1 BASIC as in the ROM, not Basalt. ;) |
Steve Pampling (1551) 8170 posts |
Exactly my thinking, unless you want a filetype set or variable set before the app is run then surely !Boot has no purpose |
Pages: 1 2