BBC BASIC for Windows
General >> Suggestion Box >> Extension to Array assignment http://bb4w.conforums.com/index.cgi?board=suggestions&action=display&num=1381323990 Extension to Array assignment
Post by BrianM on Jun 30th, 2010, 5:50pm
How about specifying the index to start at when doing an array assignment Currently you can only start at 0 a() = 1,2,3 starts at index 0
How about a(2) = 1,2,3
assigning elements 2 to 4
Brian Matthews
Re: Extension to Array assignment
Post by admin on Jun 30th, 2010, 8:22pm
For small arrays that is OK. But if you want to (say) set elements 90 onwards of an array that is not very practical.
If you want to load just a few elements, starting at index 90, there's no reason why you shouldn't very simply do:
Code:
a(90) = 1 : a(91) = 2 : a(92) = 3
But more typically if you're working with an array that large you'd be better off using a conventional loop to load the relevant elements one at a time (not necessarily using READ/DATA, you could for example read the data from a file).
In any case your suggested syntax couldn't work, because (being an interpreter) BBC BASIC needs to know before it encounters the equals sign that it will be loading multiple elements of an array. That's the case for a()= because the Lvalue (left side of the equals) indicates it will be a whole-array assignment, but with a(2)=1,2,3 it's only when the comma is encountered that it can be distinguished from a regular (scalar) assignment a(2)=1 by which time it's too late.
Many features of BBC BASIC syntax arise from it being an interpreter rather than a compiler.