Help, I want to REPEAT:UNTIL 0=?F%

bbc/electron apps, languages, utils, educational progs, demos + more
Post Reply
User avatar
tricky
Posts: 4992
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Help, I want to REPEAT:UNTIL 0=?F%

Post by tricky »

I have spent hours trying to get one line of code to work :(
I just want basic to wait until the contents of a memory location are zero!

Code: Select all

99 REPEAT:UNTIL 0=?F%
I've tried a few different variations and it works fine at the BASIC prompt, but put it in a program and it just:

Code: Select all

Syntax error at line 99
User avatar
hoglet
Posts: 9823
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by hoglet »

Can you post a complete program?

This line looks fine on it's own, and works when pasted into BeebEm
Last edited by hoglet on Tue Oct 06, 2020 8:48 pm, edited 1 time in total.
User avatar
tricky
Posts: 4992
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by tricky »

I'm certain that something else is causing this!
If I can't crack it tonight, I'm going back to ASM.
I know where I am with poking registers and interrupt handling, but I guess BASIC isn't for that - with good reason!
User avatar
helpful
Posts: 651
Joined: Tue Sep 22, 2009 1:18 pm
Location: London
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by helpful »

In that classic bug report reply - it works when I try it!

Although it is messing with my mind that you put the test that way round rather than UNTIL ?F%=0 :shock:
RISC OS User Group Of London - http://www.rougol.jellybaby.net/
RISC OS London Show - http://www.riscoslondonshow.co.uk/
User avatar
MartinB
Posts: 5359
Joined: Mon Mar 31, 2008 10:04 pm
Location: Obscurity
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by MartinB »

I assume this is a Model B?

I just happened to be real Beeb tinkering so I’ve tried everything in immediate mode and program-borne to make it fail with a Syntax error but I really can’t :? (....without genuinely creating a syntax mistake)

If you are messing with system memory and/or devices therein and if your F% location does take a finite time to become zero such that the Basic program is largely looping at line 99, then a misguided interrupt-driven poke or illegal action that erroneously disrupts Basic’s operating framework could quite plausibly cause Basic to bomb-out and in which case, the error message is likely to be somewhat arbitrary though correctly reporting the correct current line number.

(That was one big sentence..... :shock: :lol: )
User avatar
BeebMaster
Posts: 3866
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by BeebMaster »

Well, I did get Syntax error, after I replaced the space after the line number with a TAB character instead, but I can't replicate it now! The TAB character doesn't show up when listing. Can you do a memory dump to see if some hidden control code has found its way into line 99?
Image
User avatar
BeebMaster
Posts: 3866
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by BeebMaster »

Wait a minute, nothing to do with the TAB...I accidentally introduced a &, maybe you've done that?

Code: Select all

99 REPEAT:UNTIL 0=?&F%
Image
User avatar
tricky
Posts: 4992
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by tricky »

tricky wrote:
Tue Oct 06, 2020 8:01 pm
I'm certain that something else is causing this!
If I can't crack it tonight, I'm going back to ASM.
I know where I am with poking registers and interrupt handling, but I guess BASIC isn't for that - with good reason!
I'm beginning to think that the statement in bold is not true!
Or at least, I must have a bug in my IRQV2 code, although I can't see what it is. It only uses A and reloads it from &FC before continuing the chain.
User avatar
tricky
Posts: 4992
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by tricky »

Thanks, the embarrassment of causing you to spend time on my silly bug made me finally find it just now.
:oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:
The lesson to lean from this is that copy'n'paste may be evil, but copy, delete half the old un-stacking code and pasting the whole copy just after is worse.
Every time ?&8F=1 was set, it was stealing a byte of the stack!
If it had been pure assembler, I would have got it straight away, but only causing BASIC to report a syntax error was making me think it had to be something more subtle and less serious!
User avatar
MartinB
Posts: 5359
Joined: Mon Mar 31, 2008 10:04 pm
Location: Obscurity
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by MartinB »

I wrote:If you are messing with system memory and/or devices therein and if your F% location does take a finite time to become zero such that the Basic program is largely looping at line 99, then a misguided interrupt-driven poke or illegal action that erroneously disrupts Basic’s operating framework could quite plausibly cause Basic to bomb-out and in which case, the error message is likely to be somewhat arbitrary though correctly reporting the correct current line number.
Big sentence wins....! =D> :lol:
User avatar
jgharston
Posts: 4261
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by jgharston »

tricky wrote:
Tue Oct 06, 2020 7:56 pm

Code: Select all

99 REPEAT:UNTIL 0=?F%
While it is semantically identical, it make more sense to the reader as:

Code: Select all

99 REPEAT:UNTIL ?F%=0
The way you've written the code makes the reader wonder what's happening to the zero.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_
julie_m
Posts: 283
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by julie_m »

Putting the constant on the left-hand side of the = test is a common idiom in C-derived languages, to guard against accidentally redefining a variable you are trying to read the value of. This is because in C, Java, JavaScript, Perl &c., one = is "telling" and two == is "asking"; and if you use something like

Code: Select all

if (foo = 1) {
when you really meant

Code: Select all

if (foo == 1) {
what will happen is it will set foo to 1, use 1 as the value it is working with, 1 looks "true" and so the stuff between the posh brackets will happen, whatever foo was before. This is perfectly legitimate syntax; it just probably is not what you meant. However,

Code: Select all

if (1 = foo) {
will throw an error, as you can't redefine a constant.

Mind, another common idiom in C-derived languages is writing

Code: Select all

for (i = 0; i < 10; i++) {
as though you cared what the value of i was immediately before it had one added to it .....
User avatar
tricky
Posts: 4992
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by tricky »

;)
Except c++ where it is ++i
Coeus
Posts: 1948
Joined: Mon Jul 25, 2016 12:05 pm
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by Coeus »

julie_m wrote:
Wed Oct 07, 2020 2:55 pm
Mind, another common idiom in C-derived languages is writing

Code: Select all

for (i = 0; i < 10; i++) {
as though you cared what the value of i was immediately before it had one added to it .....
tricky wrote:
Wed Oct 07, 2020 7:49 pm
;)
Except c++ where it is ++i
Both are valid in C - is that not also true in C++?

But you could also complain that in the for statement above if the operator was changed to pre-increment (++i) the value after incrementing would also not be used - it is tested later in the middle clause of the for statement but that's logically distinct. Both of these are common enough that people reading know that without an assignment this is "increment i" and we hope the compiler will avoid generating anything redundant.
User avatar
tricky
Posts: 4992
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by tricky »

Pre and post are both valid in both C and C++.
In C on nearly all processors, there is no performance difference to either.
In C++ you can override operator ++() or operator ++(int). The int is unused, it just means the i++ version!!!!!
i++ means copy i, then increment it and use the new old value. In C++ copy i could involve lots of work and the copy may not always be optimised away. There have been many changes to C++, partially to reduce the occasions when the copy is required, but I believe that there are still some! i could be a database backup system!
Coeus
Posts: 1948
Joined: Mon Jul 25, 2016 12:05 pm
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by Coeus »

tricky wrote:
Tue Oct 13, 2020 3:58 pm
Pre and post are both valid in both C and C++.
In C on nearly all processors, there is no performance difference to either.
In C++ you can override operator ++() or operator ++(int). The int is unused, it just means the i++ version!!!!!
i++ means copy i, then increment it and use the new old value. In C++ copy i could involve lots of work and the copy may not always be optimised away. There have been many changes to C++, partially to reduce the occasions when the copy is required, but I believe that there are still some! i could be a database backup system!
I had a feeling it may be something like this. It was probably this kind of thing that would have lead to Linus's rant against C++. In this case one can easily avoid it by using ++i but it does seem there is a problem with the language design here. Ideally the compiler should not be considering post increment to be equivalent to copy and then increment the original but an completely separate operator. If you have not overridden that operator on the class of i when writing i++ then it should simply refuse to compile your code.
User avatar
tricky
Posts: 4992
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by tricky »

Well, you can sort of do that by declaring it but not defining it.
If C had made their templates remotely like C++, it might have tempted me back. As it is, i'm on the C++ side of the fence, but still close enough to lean on it ;)
User avatar
TobyLobster
Posts: 28
Joined: Sat Aug 31, 2019 7:58 am
Contact:

Re: Help, I want to REPEAT:UNTIL 0=?F%

Post by TobyLobster »

It should be called ++C :)
Post Reply

Return to “8-bit acorn software: other”