A case for the BASIC CASE statement
Steve Drain (222) 1620 posts |
OK Rick, I concede your point, but as you know, the code itself is quite simple and there would be no other way the interpreter would do it. The simplicity leads to oddities and bugs. Quite interesting is that a A bug is that the |
Clive Semmens (2335) 3276 posts |
I think it would be rather surprising if it didn’t. The only variation I can really imagine would be one that allowed multiple matches, that would print HMM and then YES! as well – definitely not in spec, but not unreasonable logic. |
Steve Pampling (1551) 8172 posts |
I never thought about it behaving any differently.
Admittedly I’ve never done anything complicated, and only for me anyway, but my programming style probably stop me from discovering that because my early shell setups tend to be of the form DEFPROC and CASE X OF i.e. empty shell elements. |
Clive Semmens (2335) 3276 posts |
I can just about imagine having nested CASE structures and miscounting the ENDCASEs. I’ve done it with nested IF{}s in PHP. Quite recently. |
Steve Drain (222) 1620 posts |
Note that I said next |
Patrick M (2888) 115 posts |
Regarding Rick’s insane troll logic example program, the function with three entry points that modifies a global variable. I don’t know if anyone else in the thread has mentioned this, but I wanted to say that it doesn’t work in the Brandy BBC BASIC interpreter – it stops with an error ‘Program execution has run into a PROC or FN’. I do most of my BASIC programming with the Brandy interpreter on Linux, and when I saw Rick’s example, I expected that it wouldn’t work in Brandy for that reason, which is why I tested it. |
Steve Pampling (1551) 8172 posts |
Quickly tested by using the “fold” feature in an appropriate editor1, properly started and ended procedures etc fold up… 1Edit don’t hack it here. |
Rick Murray (539) 13851 posts |
Patrick:
I believe ABC would choke on that as well. It’s one of those “undefined” areas of something that works, but probably shouldn’t… Steve:
Fixed that for you. (looks best in Firefox! :-) )
I don’t think I’ve ever done such a thing. I know Notepad++ can, as I found the option by mistake (and a brief panic at everything vanishing). My way of dealing with this situation is keeping with a fixed degree of code indentation (two spaces in BASIC, three in C, no tabs EVER); and if the closing element of something is far enough down that the opening element may not be visible, to put a comment afterwards explaining what that closing is actually closing. I’m not so good at remembering this part, but I do try more these days. while ( !feof(scr) ) { ln[0] = '\0'; // this prevents annoying ghost line at EOF fgets(ln, (CLSIZE - 1), scr); ...two screenfuls of stuff... } // end of block: while ( !feof(scr) ) Further down, there are multiple closing braces together in do_prefileexec() so they are described too: } } // end of buffer.type == OBJ_FILE block } // end of r.r[3] != 0 block } while (regs[4] != -1); The first is closing an if…else so doesn’t need any explanation. The last one is a while clause so is self-explanatory. The other two are explained. It takes longer, but helps to make the code more readable and ward off problems with unbalanced braces and such. It is perhaps better in C than BASIC as BASIC will fail during program execution, while C will fail hard during compilation. ;-) |
Steve Pampling (1551) 8172 posts |
Edit don’t hack it here. Well, yes. Not really a great use for Edit when you’ve got StrongED (which does folding).
Presumably it’s not an obvious feature in Zap if you’ve never found yourself using it. NotePad++ is a regular work item, can’t understand people at work who do text file comparison with one utility and edit with another.
That’s just neatness and easier to follow. You’ll be putting in loads of comments next. |
Rick Murray (539) 13851 posts |
<cough> <splutter> http://heyrick.co.uk/random/errorcancel.s.txt |
Rick Murray (539) 13851 posts |
BTW, if anybody wants a copy of the RISC OS build of Brandy v1.20 that works on the Pi2… http://heyrick.ddns.net/files/brandy.ff8 Rename it to be simply “brandy” and set it’s file type to &FF8, then drop it into !Boot.Library so you can BTW, don’t bother trying to mess around with WimpSlot – this Brandy is hardwired to 524288 bytes unless you pass a different size in the command line. For instance, if the default half-megabyte isn’t good enough, try this: Brandy -size 2M for a 2MB version. Or, if you’re a bit insane: Brandy -size 511M Yes, that’s M, not K! And it’s the most you can claim for an application… Works great in the TaskWindow. A mere 535,822,336 bytes free (!). Have fun! |
Clive Semmens (2335) 3276 posts |
I do that when I’m being a good boy, or when I start feeling as though I’m liable to get tangled up.
I would do that if I was being a really good boy. You can tell how often that happens by looking at my code. On second thoughts, probably better for all concerned if you give that option a miss…
Indeed. What exactly IS “folding”? On the Mac (writing PHP) I use Atom. It’s got all sorts of features I’ve no idea how to use, but it does what I want it to do. I’ve never miscounted ENDCASES (or ENDIFs) in BASIC (only said I could imagine doing it), but I have miscounted }s in PHP. It’s just so tempting to put them all on the same line, instead of properly indented on separate lines…and then when you’ve just done a restructuring of a nest by cutting and pasting chunks of code here and there, and not bothered to fix the no-longer-appropriate indenting …ooops! |
Clive Semmens (2335) 3276 posts |
Does it work on the Pi3? |
Rick Murray (539) 13851 posts |
Gah!
Should. It’s just compiled C. Try it. |
Clive Semmens (2335) 3276 posts |
Yeah. So it crashes. So you go and find out why it crashes, fix it. (They’re still all on the same line. Just there’s one fewer of them now, so it doesn’t eat the one that isn’t supposed to have finished yet…)
Will do. And report in due course. Edit: can’t say it’s thoroughly tested yet, but it is installed and it runs, and runs at least a few small programs. Will report again when I’ve run some of my own apps in it. |
Clive Semmens (2335) 3276 posts |
Remember – this is running on Servage’s server in Hamburg, not on my own machine. Happily the server is clever enough not to let my crash cause a system wide crash…didn’t even crash my whole website, just served a few users (possibly – possibly just me) a load of garbage a couple of times. |
Steve Pampling (1551) 8172 posts |
In BASIC imagine clicking on the left edge of the DEF PROC and seeing the full procedure chunk become just the DEF PROC line with a marker at the side of it. If you fold all then all the procedures and functions etc fold up to a start line – great for an overview of the top to bottom code and you can unfold individual subroutines. As I mentioned earlier it’s also handy for subroutine start/finish matching and more. A competent programmer would probably do way more with it than I have ever dreamed of doing. |
Rick Murray (539) 13851 posts |
… In the normal world, a script error should never bring down the entire machine… |
Chris Hall (132) 3559 posts |
I suspect a Zap user would wonder what folding was. It would be more difficult to do in !Zap because it would have to remember all the line numbers of the lines not being shown so that folding and unfolding did not alter any line number. One of the main reasons to edit a BASIC programme is after an ‘error at line 34560’ and StrongEd’s habit of mungling line numbers means it is useless for editing BASIC. |
Clive Semmens (2335) 3276 posts |
Indeed. And it didn’t.
Ah. Atom does that. I didn’t know it was called folding, that’s all. There’s probably a name on a menu for it somewhere, but I discovered by accident that clicking on little arrows at the left does it. |
Clive Semmens (2335) 3276 posts |
There are indeed lots of folding options in menus in Atom. Will investigate what they all do! Zap does have a handy “list functions and procedures” option, which lists them (with line numbers if you have them switched on). |
Fred Graute (114) 645 posts |
Folding is ‘just’ a visual effect, it does not change how things are stored in memory and so line numbers do not play a part in this.
We’ve been over this before. Conclusion: StrongED is perfectly fine for editing BASIC it just doesn’t fit in with what you’re trying to do. |
Chris (121) 472 posts |
Yeah, StrongED has a similar feature using the List of Found window, which I keep open all the time next to the main code window. If I could save the extent of the LoS window, as well as its default opening position, I’d be super-happy ;-)
Not sure I understand this – I use StrongED to edit BASIC files all the time, and it works perfectly well at identifying line numbers after errors: the message reports the line number with |
David Pitt (3386) 1248 posts |
StrongED does not use the embedded BASIC line numbers, it just counts the physical lines. That’s all good with BASIC saved from StrongED with the default (re)numbering of 1,1 as set in Global Choices. It goes wrong with BASIC numbered 10,10, by a factor of 10, divide ERL by 10 to find the right line in StrongED. Save the file and StrongED will renumber to 1,1 matching the physical line numbers and the issue goes away. Zap works directly on tokenised BASIC and uses the BASIC line numbering so there is never an issue. There are some wierd numbering schemes out there in the wild depending on how the BASIC has been edited. Once in a while Zap will be more useful than StrongED. StrongED is fine. If one has not noticed a problem perhaps there is not much of a problem there, mostly. If one wants to be aware or manipulate the BASIC line numbers then use Zap. The point being made is that StrongED “mungles” line numbers which is true but does not matter if one not concerned by the line numbering and is content to let StrongED do what it does HTH. |
Chris (121) 472 posts |
Ah, I see. Thanks for the explanation. |