BBC BASIC string slicing
BBC BASIC string slicing
I've only recently become aware of a rather surprising difference between 6502 BBC BASIC and ARM BBC BASIC in respect of how negative numbers are handled in the RIGHT$() string slicing function. For example in BASIC 2 RIGHT$("Hello world!",-1) returns the string unmodified, whereas in BASIC 5 it returns an empty string. Seemingly, one is treating the value internally as an unsigned number and the other as a signed number.
Even stranger, perhaps, BASIC 5 treats negative numbers in LEFT$() and RIGHT$() differently. LEFT$("Hello world!",-1) returns the string unmodified, as BASIC 2 does, but RIGHT$("Hello world!",-1) returns an empty string! I have no recollection of Sophie proposing this change (as the early Archimedes models were branded 'BBC' there was a contractual obligation to obtain our approval). If she had I think it would have raised some eyebrows.
Not surprisingly, since I wasn't even aware of the change, my BASICs (from Z80 BBC BASIC to the latest SDL and Console Mode editions) have never followed suit. They all consistently treat the 'length' value as unsigned, in LEFT$, MID$ and RIGHT$, as 6502 BASIC does. Brandy BASIC however seems to follow the BASIC 5 behaviour.
So the question is, when and why did this change happen? Was it deliberate or an accident? Is there some 'logic' to RIGHT$ behaving differently from LEFT$ and MID$? Can anybody shed any light on this?
Even stranger, perhaps, BASIC 5 treats negative numbers in LEFT$() and RIGHT$() differently. LEFT$("Hello world!",-1) returns the string unmodified, as BASIC 2 does, but RIGHT$("Hello world!",-1) returns an empty string! I have no recollection of Sophie proposing this change (as the early Archimedes models were branded 'BBC' there was a contractual obligation to obtain our approval). If she had I think it would have raised some eyebrows.
Not surprisingly, since I wasn't even aware of the change, my BASICs (from Z80 BBC BASIC to the latest SDL and Console Mode editions) have never followed suit. They all consistently treat the 'length' value as unsigned, in LEFT$, MID$ and RIGHT$, as 6502 BASIC does. Brandy BASIC however seems to follow the BASIC 5 behaviour.
So the question is, when and why did this change happen? Was it deliberate or an accident? Is there some 'logic' to RIGHT$ behaving differently from LEFT$ and MID$? Can anybody shed any light on this?
- flaxcottage
- Posts: 5723
- Joined: Thu Dec 13, 2012 8:46 pm
- Location: Derbyshire
- Contact:
Re: BBC BASIC string slicing
Wowzers!
I've been using BBC BASIC since the start and have never used a negative number in LEFT$, RIGHT$ or MID$. Why would one want to?
I never knew that.
I've been using BBC BASIC since the start and have never used a negative number in LEFT$, RIGHT$ or MID$. Why would one want to?
I never knew that.
Re: BBC BASIC string slicing
It's unlikely that one would choose to use a negative value when it's specified as a constant, but when the value is calculated in the program it might end up negative 'naturally'. I'm sure I have encountered a few programs like that.
I would actually prefer that negative values were treated as zero, because that is generally more useful, but BBC BASIC has never worked that way. Some other BASICs do adopt that convention, and some use a more generalised form of slicing in which positive values count from the beginning of the string and negative values from the end.
But I digress. Perhaps somebody could ask Sophie at her forthcoming appearance at ROUGOL.
Re: BBC BASIC string slicing
That's a surprise, as for decades I've use a logical expression in LEFT$() to do IF/ELSE processing on strings, eg PRINT ;num;" item";LEFT$("s",num<>1), the underlying assumption that the numeric parameter is treated modulo the maximum string length as an 8-bit value (internally, the interpreter just fetches byte 0 from the numeric accumulator) and so resolves to 0 or 255 - and LEFT$(...,255) gives the whole string - which also works with 16-bit strings; and I made sure it worked in PDP11 BASIC. I've clearly never used RIGHT$(s$,test) and consequently seen it blow up on different BASICs.
It could be a parallel to the non-symmetry between LEFT$(s$) and RIGHT$(s$). You would expect them to be symetrical, LEFT$(s$) giving the one leftmost character and RIGHT$(s$) giving the one rightmost character, or LEFT$(s$) doing LEFT$(s$,LENs$-1) and RIGHT$(s$) doing RIGHT$(s$,LENs$-1), but they don't.
I always have to look them up to check, but:
LEFT$(s$) is LEFT$(s$,LENs$-1)
RIGHT$(s$) is RIGHT$(s$,1)
It could be a parallel to the non-symmetry between LEFT$(s$) and RIGHT$(s$). You would expect them to be symetrical, LEFT$(s$) giving the one leftmost character and RIGHT$(s$) giving the one rightmost character, or LEFT$(s$) doing LEFT$(s$,LENs$-1) and RIGHT$(s$) doing RIGHT$(s$,LENs$-1), but they don't.
I always have to look them up to check, but:
LEFT$(s$) is LEFT$(s$,LENs$-1)
RIGHT$(s$) is RIGHT$(s$,1)
Code: Select all
$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
Re: BBC BASIC string slicing
Indeed, but I've just noticed an incompatibility between ARM BASIC V and my BASICs. I assumed (reasonably enough I think) that those identities also apply when assigning to a substring. So for example in my BASICs:
Code: Select all
a$ = "Hello world!"
RIGHT$(a$) = "Test"
Admittedly this is documented in the RISC OS BBC BASIC manual where it states that in the case of assignment to a substring RIGHT$(a$) is equivalent to RIGHT$(a$,255). I don't know why.
I won't be changing my BASICs however. They have worked the same way for 20 years and nobody has drawn this difference to my attention, so it's more important that they continue to work how they always have.
Re: BBC BASIC string slicing
Just for a quick point of comparison, assignment to a substring (at least with RIGHT$) is not permitted on BASIC 2 or BASIC 4, having just attempted it in JSBeeb, and PRINT RIGHT$(a$) results in Missing ,Richard Russell wrote: ↑Tue Apr 13, 2021 5:20 pm So for example in my BASICs:results in a$ being set to "Hello worldT", exactly as it would had I specified RIGHT$(a$,1). But in ARM BASIC it sets a$ to "Hello woTest"!Code: Select all
a$ = "Hello world!" RIGHT$(a$) = "Test"
Admittedly this is documented in the RISC OS BBC BASIC manual where it states that in the case of assignment to a substring RIGHT$(a$) is equivalent to RIGHT$(a$,255). I don't know why.
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Re: BBC BASIC string slicing
These are some of the (many) extensions in ARM BASIC V; to be fair it probably wouldn't have been possible to support them in 6502 BBC BASIC and remain within the 16 Kbyte ROM size limit.
I haven't been that concerned about minor incompatibilities between my BASICs and Sophie's, not least because there has been no overlap between the platforms on which they run. However I must admit that the existence of Matrix Brandy, which runs on the same platforms as mine but achieves almost perfect compatibility with BASIC V (and VI), has made me question the legitimacy of my BASICs.
One possibility I am contemplating is to discontinue all my products on the 20th anniversary of the original release of BBC BASIC for Windows (which corresponds almost exactly to the 40th anniversary of the original 6502 BBC BASIC) later this year. I suspect this would please a majority of members here.
Re: BBC BASIC string slicing
Goodness me, no, that would not please this member at all. And I would think that's true for most Basic fans, and anyone with an interest in history, preservation, and continuity.
Re: BBC BASIC string slicing
My experience over the years has been that Acorn enthusiasts are generally of the opinion that the only 'legitimate' BBC BASICs are those created by Sophie. A search of the RISC OS forum archives will find that view expressed, with some force.
Brandy is tolerated because it was developed by a RISC OS enthusiast and goes to extreme lengths to be compatible with Sophie's BASICs, warts and all. But I consciously introduced differences from the very start, in Z80 BBC BASIC, for which I have never been forgiven!
Re: BBC BASIC string slicing
I'm fairly sure it's just a few strident voices, and by no means a majority opinion.
- daveejhitchins
- Posts: 7888
- Joined: Wed Jun 13, 2012 6:23 pm
- Location: Newton Aycliffe, County Durham
- Contact:
Re: BBC BASIC string slicing
Ah! . . .Richard - I see you have it wrong, again . . . I've taken the liberty of correcting your errorRichard Russell wrote: ↑Wed Apr 14, 2021 3:43 pm suspect this would please a majority minority of members here.
Dave H
Available: ARA II : ARA III-JR/PR : ABR : AP5 : AP6 : ABE : ATI : MGC : Plus 1 Support ROM : Plus 3 2nd DA : Prime's Plus 3 ROM/RAM : Pegasus 400 : Prime's MRB : ARCIN32 : Cross-32
Re: BBC BASIC string slicing
Perhaps I should have said 'a majority of those who have expressed an opinion', I cannot know about anybody else.
What I do know is that my health will suffer if I have to continue to support and maintain my software products indefinitely.
Re: BBC BASIC string slicing
Fair point about your limited ability to support. So, freezing something (rather than retiring it) might well be something coming up.
It's a perennial problem that we can only judge a group by its posts, and it does tend to put the worst complexion on things. When people like something or are in support of it, they will often be silent. I think the best we can do is try not to generalise - in effect, we have too little data, and it's too skewed.
It's a perennial problem that we can only judge a group by its posts, and it does tend to put the worst complexion on things. When people like something or are in support of it, they will often be silent. I think the best we can do is try not to generalise - in effect, we have too little data, and it's too skewed.
- daveejhitchins
- Posts: 7888
- Joined: Wed Jun 13, 2012 6:23 pm
- Location: Newton Aycliffe, County Durham
- Contact:
Re: BBC BASIC string slicing
Richard - Your health is way more important than continuing support, even for something so important in your life.Richard Russell wrote: ↑Wed Apr 14, 2021 6:59 pm What I do know is that my health will suffer if I have to continue to support and maintain my software products indefinitely.
Just a thought!
Would you consider handing over the reins to someone else (I'm not offering!) You could than act as advisor/monitor . . . ? Perhaps less stressful!
Dave H
Available: ARA II : ARA III-JR/PR : ABR : AP5 : AP6 : ABE : ATI : MGC : Plus 1 Support ROM : Plus 3 2nd DA : Prime's Plus 3 ROM/RAM : Pegasus 400 : Prime's MRB : ARCIN32 : Cross-32
- flaxcottage
- Posts: 5723
- Joined: Thu Dec 13, 2012 8:46 pm
- Location: Derbyshire
- Contact:
Re: BBC BASIC string slicing
I've used BBC BASIC in all its forms ever since it came out. One of the things I have liked about it has been its compatibility across platforms and its compatibility to the 'real' BASIC on Beebs and Arcs. It did not matter on which platform I programmed (within reason); my code could be further developed then on any other.
It is easy to be critical if one has a narrow viewpoint.
I for one, however, am very grateful for all the work you have done over the years and am a staunch supporter of your BASICs.
It is easy to be critical if one has a narrow viewpoint.
I for one, however, am very grateful for all the work you have done over the years and am a staunch supporter of your BASICs.
Re: BBC BASIC string slicing
That's unfortunate, but I think it just goes to show that Risc OS forums and Stardot are not the same thing, and are very different in their outlook. Although I don't have a need to use your Basics, I think they are a very good thing and I don't hesitate to make people aware of them.Richard Russell wrote: ↑Wed Apr 14, 2021 5:09 pm A search of the RISC OS forum archives will find that view expressed, with some force.
Re: BBC BASIC string slicing
Believe me I've tried! Indeed the main reason for releasing the source code of BBC BASIC for SDL 2.0 at GitHub is that I was advised - here at StarDot as it happens - that it would be the best way of encouraging others to take an interest in supporting and contributing to it. But there have been no takers since.daveejhitchins wrote: ↑Thu Apr 15, 2021 8:12 am Would you consider handing over the reins to someone else (I'm not offering!)
It's true that there are complications, including that the right to call my products 'BBC BASIC' was conferred on me by the BBC (many years ago) and is not transferrable, so if somebody were to take it over and I was no longer actively involved it would have to be called something else (much as Brandy BASIC and Owl BASIC are also not called 'BBC BASIC').
So what would be of most value to me, which is for one or more other people to share the load rather than taking over the project completely, is probably not sufficiently attractive. I have only recently received an offer to 'buy me out', that is to purchase the bbcbasic.* domains that I own and all the rights to my BASICs, but that's too drastic for me to be interested.
- Kecske Bak
- Posts: 753
- Joined: Wed Jul 13, 2005 8:03 am
- Location: Mélykút, Hungary
- Contact:
Re: BBC BASIC string slicing
No, not at all. When I think of BBC BASIC I immediately think of you. I owned a Z88 so I have enjoyed using one of your BBC BASICs almost as long as one of Sophie's.Richard Russell wrote: ↑Wed Apr 14, 2021 5:09 pmMy experience over the years has been that Acorn enthusiasts are generally of the opinion that the only 'legitimate' BBC BASICs are those created by Sophie.
[url]https://kecskebak.hu]
Re: BBC BASIC string slicing
That's nice to know, but you would have to admit that it puts you in a tiny minority of members of this forum!Kecske Bak wrote: ↑Fri Apr 16, 2021 10:05 amI have enjoyed using one of your BBC BASICs almost as long as one of Sophie's.
Re: BBC BASIC string slicing
Are you looking for string tactics using existing facilities, Richard, or looking for ideas on extending BBC Basic? Putting MID$() on the LHS seems quite interesting to me: I've a feeling ZX Basic did this kind of string slicing.
From here:
From here:
For string variables, we can not only extract substrings, but also assign to them. For instance, type
and thenCode: Select all
LET a$="l'm the ZX Spectrum"
andCode: Select all
LET a$(5 TO 8)="******"
Code: Select all
PRINT a$
Re: BBC BASIC string slicing
Not extending BBC BASIC any further, no.
My interest (and surprise) was in discovering that BASIC V doesn't work the same way as my BASICs. I fully admit that the fault is mine - I assumed that LEFT$() and RIGHT$() with the second parameter omitted had the same meaning whether used to the right or the left of the equals sign, and therefore in my BASICs they do. But in ARM BASIC V (and VI) they mean different things, and are documented thus.
I still think my assumption was not unreasonable, but I should have checked. A major problem for me was that 20 years ago, when initial development of BBC BASIC for Windows was coming to an end, I had no way of testing what happened in Sophie's BASICs. I didn't own any RISC OS hardware - and never have - and I don't think emulators like Red Squirrel yet existed, although I might be wrong. I certainly wasn't aware of them.
Yes, fully supported in ARM BASIC V & VI, Brandy, BB4W, BBCSDL and my Console Mode editions. Particularly useful, in my experience, is being able to change a single character of a string 'in situ':Putting MID$() on the LHS seems quite interesting to me
Code: Select all
MID$(s$, n%, 1) = "x"
Code: Select all
f% = OPENUP(file$)
s$ = GET$#f% BY EXT#f%
MID$(s$, n%, 1) = CHR$(&AB)
PTR#f% = 0
BPUT#f%, s$;
CLOSE #f%
Re: BBC BASIC string slicing
If the reception of your talk earlier in the year on BBC Basic in the 21st Century you presented for ABug is anything to go by, then I believe nothing is further from the truth.Richard Russell wrote: ↑Wed Apr 14, 2021 3:43 pm I suspect this would please a majority of members here.
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
- 1024MAK
- Posts: 12806
- Joined: Mon Apr 18, 2011 5:46 pm
- Location: Looking forward to summer in Somerset, UK...
- Contact:
Re: BBC BASIC string slicing
As far as I’m concerned, a negative parameter value in a LEFT$, MID$ or RIGHT$ is invalid.
Microsoft versions of BASIC (at least, the version that I tried on a Radio Shack TRS-80 Model 100) stop with an error if the parameter value is negative.
Mark
Microsoft versions of BASIC (at least, the version that I tried on a Radio Shack TRS-80 Model 100) stop with an error if the parameter value is negative.
Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
- 1024MAK
- Posts: 12806
- Joined: Mon Apr 18, 2011 5:46 pm
- Location: Looking forward to summer in Somerset, UK...
- Contact:
Re: BBC BASIC string slicing
As others have said, your health and well-being should come first. If you are however, happy to continue to make your products available, that would be really good.Richard Russell wrote: ↑Wed Apr 14, 2021 3:43 pm One possibility I am contemplating is to discontinue all my products on the 20th anniversary of the original release of BBC BASIC for Windows (which corresponds almost exactly to the 40th anniversary of the original 6502 BBC BASIC) later this year. I suspect this would please a majority of members here.
I don’t think many members here would be pleased if you discontinued all your products. Although, as a lot of members here are either users rather than programmers, or prefer to use machine code or use the native versions of BASIC that were originally supplied with the relevant machine, these members may not have a strong opinion either way.
Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
- 1024MAK
- Posts: 12806
- Joined: Mon Apr 18, 2011 5:46 pm
- Location: Looking forward to summer in Somerset, UK...
- Contact:
Re: BBC BASIC string slicing
The version of Microsoft BASIC on the Commodore 64 and Microsoft QBASIC on a PC also stop with an error if the parameter value is negative.
Mark
Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
Re: BBC BASIC string slicing
It's difficult. I will inevitably, sooner or later (probably sooner), have to give up developing and supporting my products, and maintaining the website. That will happen either because I die or because my mental faculties deteriorate too much.
There's a school of thought that it's better to do it in an advertised and planned way, before either of those events force an uncontrolled hiatus. That's why I am thinking about it now, and why the coincidence of the two anniversaries seemed a possible occasion.
As I've said, I'd far rather a gradual transition took place, with me initially sharing responsibility with one or more others. That would be far less dramatic than any of the other options. But it requires somebody to be interested in such a collaboration, and there isn't anybody.
- daveejhitchins
- Posts: 7888
- Joined: Wed Jun 13, 2012 6:23 pm
- Location: Newton Aycliffe, County Durham
- Contact:
Re: BBC BASIC string slicing
This is so sad . . . How many people don't use BASIC?Richard Russell wrote: ↑Sun Apr 18, 2021 10:55 am As I've said, I'd far rather a gradual transition took place, with me initially sharing responsibility with one or more others. That would be far less dramatic than any of the other options. But it requires somebody to be interested in such a collaboration, and there isn't anybody.
Dave H.
Available: ARA II : ARA III-JR/PR : ABR : AP5 : AP6 : ABE : ATI : MGC : Plus 1 Support ROM : Plus 3 2nd DA : Prime's Plus 3 ROM/RAM : Pegasus 400 : Prime's MRB : ARCIN32 : Cross-32
Re: BBC BASIC string slicing
Lots of people use it, very few have the time, motivation and commitment to help support it.daveejhitchins wrote: ↑Sun Apr 18, 2021 11:17 am This is so sad . . . How many people don't use BASIC?