BBC BASIC for Windows
« Extension to Array assignment »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:52pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Extension to Array assignment  (Read 973 times)
BrianM
New Member
Image


member is offline

Avatar




PM


Posts: 3
xx 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

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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:
      a() = a(0),a(1),1,2,3 

Richard.
User IP Logged

BrianM
New Member
Image


member is offline

Avatar




PM


Posts: 3
xx 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls