Author |
Topic: Extension to Array assignment (Read 974 times) |
|
BrianM
New Member
member is offline


Posts: 3
|
 |
Extension to Array assignment
« Thread started 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
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Extension to Array assignment
« Reply #1 on: Jun 30th, 2010, 8:22pm » |
|
on Jun 30th, 2010, 5:50pm, BrianM wrote:How about a(2) = 1,2,3 assigning elements 2 to 4 |
|
You can achieve that as follows:
Code: Richard.
|
|
Logged
|
|
|
|
BrianM
New Member
member is offline


Posts: 3
|
 |
Re: Extension to Array assignment
« Reply #2 on: Jun 30th, 2010, 8:48pm » |
|
For small arrays that is OK. But if you want to (say) set elements 90 onwards of an array that is not very practical.
I have to admit that I have only wanted to do this a few times but it would be neater than using DATA and READ statements.
Brian Matthews
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Extension to Array assignment
« Reply #3 on: Jun 30th, 2010, 10:24pm » |
|
on Jun 30th, 2010, 8:48pm, BrianM wrote: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.
Richard.
|
|
Logged
|
|
|
|
|