RISC OS did that since forever!
GavinWraith (26) 1563 posts |
The original version was buggy, which is why I tried using goto. On third thoughts here is a better version, using a coroutine to read in the lines. We need a coroutine so that we can deal with the headers and the content in separate loops. My main mistake in version one was trying to put everything into a single loop. In an email the headers are separated from the content by a blank line. The table keep says which headers are to be retained.
Coroutines are very useful goto-killers. |
Steve Drain (222) 1620 posts |
But the ‘label’ is a subroutine, so where does the End Sub return to?
This really seems like RESTORE ERROR. Never having encountered VB, it lookes clumsy. If it is a ‘modern’ language, why not a sensible try/throw/catch? |
GavinWraith (26) 1563 posts |
Lua has had goto since version 5.2. The third edition of Programming in Lua says:
I have not seen the smallprint about gotos in other languages, but they must have some rules for how gotos interact with scoping. |
Steve Drain (222) 1620 posts |
@Gavin Is there a CASE structure in Lua? I think this needs one, just to simplify things. In BASIC you might do:
That is not rock solid, but reasonably clear, I think. |
Steve Drain (222) 1620 posts |
Not a lot, I fear. ;-) |
GavinWraith (26) 1563 posts |
No. See http://lua-users.org/wiki/SwitchStatement for some long-running discussions on this. One usually uses a table of functions instead. Your BASIC program certainly clear. As I said, my initial effort suffered because I was trying to cram everything into one loop. |
Steve Drain (222) 1620 posts |
On cue. ;-) A major problem of trying to create/simulate structures in BASIC is the available namespace. In user%!status%, status% is a variable holding an offset. So far, so good, but if there is another structure with a status% value at a different offset, then we have a problem. One straightforward solution is to create unique variables for each structure type, perhaps with a prefix: user%!net_status%, but this can get clumsy. There are various ways to get around this, but they each require ‘fiddling’ with BASIC in a non-standard fashion, and the protection against mistakes is minimal. A second problem is the nesting of structures. The indirection operators, such as !, do not work comfortably when nested left-to-right, but do when right-to-left. This may work, but looks awkward. ! and ? are ok for word and byte, but ? and | for string and float are not so convenient, and there is no way do anything else. In conclusion, I do not think you can really do structures in standard BASIC, even though many people have developed their own systems. My own library is on the downloads page of my site. If you need structures, then Basalt provides a way, with a syntax and with types that will be familiar. |
GavinWraith (26) 1563 posts |
@Steve Your BASIC program terminates its WHILE-loop when it encounters an empty line. My Lua program stops looking for headers when it meets a blank line (only spaces and tabs). I tried to find out which is the official terminator for the header section of an email from RFC2821, but became confused by the stuff about period-doubling. That is what comes of dotage, in my case :). |
Steve Drain (222) 1620 posts |
RFC 822 ssys the the header is terminated by a blank line. On the other hand, I have forgotten that lines are CRLF terminated. |
Colin (478) 2433 posts |
You also need to take folding into account ie a header field can be multiline. Steve. The point I was trying to make – obviously badly – was just as you can work around basic’s problems and don’t need to use C, you can work around C’s problems and don’t need you use C++. But just as C features makes things easier than using basic, C++ features make C easier. My reply was in response to Rick asserting that he could do in C what his uncle did using C++. |
Rick Murray (539) 13840 posts |
Steve:
No, the label is a label. Don’t confuse VB with doing anything smart. ;-) The “Exit Sub” above exits the subroutine early. The “End Sub” is the formal end of the subroutine (also exits). The label… in between.
You think that’s bad, have you ever come across a language that cannot binary shift? Welcome to VB, where you must * and / while everybody else can do << or >> – and, of course, you pay the penalty of an expensive operation instead of something that should complete in one cycle (oh, wait, a dozen cycles, it is x86 we’re talking about!). I wrote a program (it’s on my site someplace) that is a bitmap editor for Psion 3a (Acorn PocketBook II) images. Which are two planes (black and grey) of monochrome pixel data. In order to spare myself the abysmal pain of non-stop maths ops, I “unpack” the image to a big int array when I load it, and repack for saving. It is a horrible way to do things, but it is equally horrible to have a language that can’t do something so simple.
Modern as in Windows 95 – XP era. Later versions ( Visual Basic .net ) are akin to VisualBasic more or less only by name. It might have the try/throw/catch. I don’t know. I did download the compiler stuff, but once I realised that there were so many differences that I would need to rewrite substantial amounts of my software, I just uninstalled the later one. This then coincided with the Beagle and the Pi and the return to RISC OS – which, I am pleased to tell all of you, was successful. I have done some minor tinkering with one or two VB projects, but I haven’t written anything new nor released any new versions (that I remember) and…frankly…I don’t really plan to. Anyway. Uh. Where was I? Oh yes. VB is a fairly simple programming language for Windows, but it isn’t that smart. I’ll give you another lovely example. Internally, VB stores strings in Unicode. Internally, VB uses the ANSI version of the Windows API. This leaves us with a situation where you can store Japanese text in VB, you can display Japanese text in Windows (98 or later, IIRC), but there is no way to glue the two together without using strange APIs and passing memory blocks around and hoping like hell it doesn’t crash. All the while you are up against VB’s runtime which will do its damnedest to thunk “wide” strings into something suitable for an eight bit world. Question mark characters abound! Gavin:
Having written a mail fetcher, a mail processor, and a (really basic) email program… The header (usually) begins with some sort of introductory line. In my case, it was “#! rmail” (I think). Address and routing information follows. Do not expect anything to be present. I have had messages with no “To:” but instead an “Envelope-To:”. Period doubling. It’s simple. A single blank line also terminates the body of the email (a blank line is a blank line – a line containing spaces and tabs is not blank). So what is done is that if a message contains blank lines within it (most will, paragraph breaks etc) then the smtp program should replace the blank line "" with a single period “.” which will be stripped out by the pop3 program the receives the message. So:
becomes:
and:
becomes:
Hope this helps. If anything is wrong, blame the fact that I last built my email software in April 2002. ;-) Colin:
Depends what problem you are trying to solve. If a matter of structure, then yes, you can work around it by changing the code – for example, handling situations like a switch case with no break (falls through) can be implemented in BASIC. On the other hand, if you want something to go much faster, you need assembler or a compiled language. I think this was the demographic that software such as ABC was aiming for – familiar BASIC (in a manner of speaking) but with a speed more akin to that which you would expect from a compiled language. |
Steve Drain (222) 1620 posts |
It was not “rock solid” nor intended as a working routine, but the necessary additions should not add too much. My comments about structures had only passing relevance to your points about C anc C++. I am in almost total agreement about the advantages of OOP. |
GavinWraith (26) 1563 posts |
Sorry. Looks like I have been using the word with a different sense. I have been sensitive about tab characters ever since I wasted hours of frustration, during the early 80s, on the university’s mainframe. I had not known that its C compiler’s makefiles absolutely required tabs in certain places, and the only editor I could use displayed tabs as blank spaces. What bright spark dreamed up that gotcha? Yes, I know. Those who had been brought up on the system hardly thought twice about it, but for somebody from the outside trying to learn by trial and error it was not a friendly choice of format. |
Steve Pampling (1551) 8170 posts |
Apropos of which – how about a mod which responds to ALT pressed at boot by entering single step mode? |
Steve Pampling (1551) 8170 posts |
I spent a short while this afternoon explaining the difference between ^$ and ^ $ Eyes glazed1 before I got to anything even vaguely complex. 1 The management guiding newcomers into the office for introductions announce the occupants of the office as “third line support” and “Steve in the corner” – is that less or more? |
Rick Murray (539) 13840 posts |
Huh? If I ask Google “^$ vs ^ $”, the only thing Google can see is “vs” so I now know Victoria’s Secret was founded by Roy Raymond in 1977. 2012 sales were $6.12 billion. And the photo of their last post on Google+ is somewhat pervy.1
More. You are mentioned by name, the rest are just “third line support”.
Perhaps one day (it is an idea I have myself), but I’d require you to hold down F8 to invoke that mode. People as old as me might understand why. ;-) 1 Perhaps I am broken as a man, but I’ve never ever fantasised about getting a girl to do <insert any pervy thing you can thing of>. Some things, not suitable for this audience (go ask Stifler!), I wouldn’t dream of expecting a girl to do. And, by the way, ick! [time to rapidly change the subject] |
Steve Fryatt (216) 2105 posts |
It does. Only the insane (or those saddled with legacy code which needs to be maintained) still use VB6. AFAIK the IDE isn’t even supported by MS on Windows 7 or later.
There’s always BASIC I to BASIC IV, if you’re being pedantic. VB6 also has a rather fun way of handling hex constants, which can cause a lot of pain and anguish. Coupled with its inability to shift numbers, it can make working with bitwise data quite an interesting exercise in obfuscation. |
Rick Murray (539) 13840 posts |
Read ElReg comments sometime. I’m not the only one disappointed with what “VisualBasic” has become. So, yeah, I stuck with v5. It wasn’t broken, it just needed some tweaks to bring it up to spec for the more modern systems.
Well, BASIC I is way older than VB. You can forgive something that old (and soon replaced).
You mean the bit where people didn’t bother to read the docs and don’t realise that:
is not the same as:
? [for non-VBers: the first is -1, the second is 65535, variables in VB are signed, and it prefers 16 bit integer unless you explicitly tell it otherwise (hence the trailing ‘&’)] |
Steve Pampling (1551) 8170 posts |
^$ start of line immediately followed by end of line You of course immediately spotted the regex Re: “vs” – interesting, apart from it not being a product set I’m likely to use, it does demonstrate the priorities of search engines giving the masses what they want though. PS. Slight delay due to early sleep, rising at 04:30 to start at 05:45 finish at 17:00 (some genius booked a meeting running to 17:00 after a firewall change at start of day) |