hellomike wrote: ↑Thu 20 Feb 2025, 08:56
Even though I myself do not use BBCSDL extensively, I firmly believe that all progress and new functionality is welcome.
As I've explained many times before, I've always valued
stability and
freedom from bugs over
feature bloat, which has afflicted so many other languages (not least Python). This is particularly true of interpreted languages, in which any new feature potentially slows down execution (e.g. because of less efficient cache usage) and increases the size of every 'compiled' application bundle,
even if the program doesn't use that feature.
So, long before my deteriorating health became an additional complication and risk factor, I adopted the policy that I would not consider extending the core BBC BASIC language unless (a) the proposed extension couldn't be satisfactorily achieved by means of a library, (b) it would be of sufficiently general value to benefit a significant number of users and (c) it could be achieved safely with minimal bloat and/or performance hit.
It's difficult to argue that array slicing, at least the limited kind that it's practical to implement, meets those criteria. It
can be achieved reasonably satisfactorily with a library (I've already added the routines to
arraylib) and it's likely that only a tiny number of users would ever make use of it. It would also, inevitably, slightly slow down every program using arrays because of the check for the slicing syntax.
However I've started to question that conclusion for a couple of reasons. Firstly array slicing was identified as one of the major features offered by Python that BBC BASIC doesn't have (albeit that Python's version is much more flexible) and it was clear that one of the benefits was in the clarity offered by having a built-in syntax. Even if a library can provide the functionality, it can't provide the elegant syntax.
Secondly, I was struck by the way DeepSeek came to the false conclusion that BBC BASIC does have array slicing, and used it in its suggested code for Matrix Inversion! How that hallucination arose I have no idea, perhaps it got muddled between BBC BASIC and a similar language, but it does suggest that the absence of that functionality puts BBC BASIC at a disadvantage.
So I'm seriously looking at the possibility of adding it, so long as it can be done easily and safely, and with minimal bloat. To make it as lightweight and fast as possible my current proposal is that there be just one, simple, straightforward syntax (no shortcut syntax for a whole row, for example):
Code: Select all
array(start TO end) : REM For one-dimensional arrays
array(row, start TO end) : REM For two-dimensional arrays
array(row, 0 TO DIM(array(),1)) : REM entire row
In general it would work for multi-dimensional arrays but only the
final dimension can be sliced, because the elements in the slice must be
consecutive in memory and that's only true in those cases.
It would also, unavoidably, suffer from the same limitation as the library implementation that a slice cannot be used in a
dot-product operation. However you would be able to use the other 'whole array' operations on slices (which would for example overcome the current limitation that such operations assume zero-based arrays and include element zero in the calculation):
Code: Select all
PRINT SUM(array(start TO end))
PRINT MOD(array(start TO end))
PRINT MOD(array(1 TO DIM(array(),1) : REM One-based, index zero ignored
And of course you would be able to use array assignment and arithmetic, even to copy data from one region of an array to another:
Code: Select all
DIM array(9)
array() = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
array(6 TO 8) = array(1 TO 3)
FOR I% = 0 TO 9 : PRINT array(I%) : NEXT
which outputs:
I'd welcome more views on this.