Acorn BASIC inconsistency

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Richard Russell
Posts: 540
Joined: Tue 18 Jun 2024, 09:32

Acorn BASIC inconsistency

Post by Richard Russell »

Can somebody provide an explanation for why you (seemingly) cannot do this in Acorn's ARM BASIC 5:

Code: Select all

10 DIM p(1)
20 p() += 1,2
This results in a Syntax error, which seems inconsistent to me. You can legitimately do either of these:

Code: Select all

30 p() = 1,2
40 p() += 1
so line 20, which simply merges these two operations, looks as if it ought to be valid, and it is in both BBC BASIC for Windows and BBC BASIC for SDL 2.0 - not because it was coded specifically to allow it but because it naturally followed from the most obvious and straightforward (to me) way of implementing 30 and 40.
DDRM
Posts: 25
Joined: Mon 17 Jun 2024, 08:02

Re: Acorn BASIC inconsistency

Post by DDRM »

I've no inside information, so I don't know, but I suspect that the operator += would normally expect a single value, which it would then apply (in this case) to all elements of the array. Does the formal definition of the syntax for += in BASIC V allow for multiple parameters? I can't find this, despite having the PRMs and user guides....

Ooh, looking in an old book "BASIC V for the Archimedes", by Mike Williams, suggests an interesting alternative possibility: it says of the newly-introduced += that saying X = X+1 is sufficient to declare a variable X with value 0, while X += 1 will NOT do so, and will throw a syntax error. Might that underlie it? It seems surprising, because I'd expect the SIM statement to create an array full of zeroes?

Best wishes (and Happy New Year!)

David
Richard Russell
Posts: 540
Joined: Tue 18 Jun 2024, 09:32

Re: Acorn BASIC inconsistency

Post by Richard Russell »

DDRM wrote: Fri 02 Jan 2026, 09:58 I've no inside information, so I don't know, but I suspect that the operator += would normally expect a single value, which it would then apply (in this case) to all elements of the array.
The way all my BASICs (BB4W, BBCSDL, BBCZ80) implement this is effectively:

Code: Select all

array() <operator> <array-expression>
where <operator> can be a simple assignment = or a compound assignment +=, -= etc. and <array-expression> can be any of the allowed array expressions including a comma-separated list of values. Evaluation of <array-expression> is oblivious to what the <operator> was, so it necessarily follows that since = must accept a list of values so will +=.

To simulate the behaviour of Acorn's BASICs one would need to make the evaluation of <array-expression> behave differently depending on <operator>, so for example if <operator> is a simple assignment a list of values is accepted but if it's a compound assignment a list isn't accepted.

To my way of thinking that adds additional complexity with no benefit, indeed the functionality suffers.
Does the formal definition of the syntax for += in BASIC V allow for multiple parameters? I can't find this, despite having the PRMs and user guides....
BBC BASIC isn't great on "formal definitions" because it's largely documented informally. The closest there is in Acorn's documentation is this:

Code: Select all

array	=	factor, expression, ...	Set several elements
array	+=	expression
This is consistent with the observed behaviour, but is misleading to the extent that the first says that it 'sets several elements' as if to imply that the second doesn't, but of course that 'sets several elements' too - it's an array assignment!
it says of the newly-introduced += that saying X = X+1 is sufficient to declare a variable X with value 0, while X += 1 will NOT do so, and will throw a syntax error.
That's not true of my BASICs: X += 1, where X was not previously defined, will set X to 1, it won't raise an error. I agree that might suggest that internally the simple assignment and compound assignment operations in Acorn's BASICs are quite separate, whereas in my BASICs they share the same code.