Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #6302 > unrolled thread

Arrays in BASIC

Started byPaul Stewart <narrowboat-paul@outlook.com>
First post2022-01-02 20:36 +0000
Last post2022-01-03 09:46 +0000
Articles 8 — 4 participants

Back to article view | Back to comp.sys.acorn.programmer


Contents

  Arrays in BASIC Paul Stewart <narrowboat-paul@outlook.com> - 2022-01-02 20:36 +0000
    Re: Arrays in BASIC Harriet Bazley <harriet@bazleyfamily.co.uk> - 2022-01-02 21:01 +0000
      Re: Arrays in BASIC Paul Stewart <narrowboat-paul@outlook.com> - 2022-01-02 21:56 +0000
        Re: Arrays in BASIC Paul Stewart <narrowboat-paul@outlook.com> - 2022-01-02 22:18 +0000
      Re: Arrays in BASIC Martin <News03@avisoft.f9.co.uk> - 2022-01-02 22:04 +0000
        Re: Arrays in BASIC Harriet Bazley <harriet@bazleyfamily.co.uk> - 2022-01-02 22:43 +0000
          Re: Arrays in BASIC Martin <News03@avisoft.f9.co.uk> - 2022-01-02 23:18 +0000
          Re: Arrays in BASIC Steve Drain <steve@kappa.me.uk> - 2022-01-03 09:46 +0000

#6302 — Arrays in BASIC

FromPaul Stewart <narrowboat-paul@outlook.com>
Date2022-01-02 20:36 +0000
SubjectArrays in BASIC
Message-ID<3261a6a459.Paul@outlook.com>
Hi guys,

Need to pick you brains on Arrays.

Looking at Arrays in the Archimedies User Guide (vintage July 1987), I 
have come to the understanding that it is possible to declare an array 
local to a function or procedure.  Having tried to do this, I keep getting 
Syntax Error.

I am trying using: LOCAL DIM a$(1,1)

Also tried different permutations, but all come back with Syntax error.

Am I barking up the wrong tree here or just completely misunderstanding 
the examples provided?

Any advice examples you can give, much appreciated.


-- 
Paul Stewart
Sent from A9home running RISC OS 4.42

[toc] | [next] | [standalone]


#6303

FromHarriet Bazley <harriet@bazleyfamily.co.uk>
Date2022-01-02 21:01 +0000
Message-ID<65baa8a459.harriet@bazleyfamily.co.uk>
In reply to#6302
On 2 Jan 2022 as I do recall,
          Paul Stewart  wrote:

> Hi guys,
> 
> Need to pick you brains on Arrays.
> 
> Looking at Arrays in the Archimedies User Guide (vintage July 1987), I 
> have come to the understanding that it is possible to declare an array 
> local to a function or procedure.  Having tried to do this, I keep getting 
> Syntax Error.
> 
> I am trying using: LOCAL DIM a$(1,1)
> 
> Also tried different permutations, but all come back with Syntax error.
> 
> Am I barking up the wrong tree here or just completely misunderstanding 
> the examples provided?
> 
> Any advice examples you can give, much appreciated.

>L.
   10 PROCarray
   16 PRINT D$(1)
   17 END


   20 DEF PROCarray
   30 LOCAL D$()
   40 DIM D$(7)
   50 D$(1)="hat"
   55 PRINT "array", D$(1)
   60 ENDPROC

>RUN
array     hat
Undimensioned array at line 16

-- 
Harriet Bazley                     ==  Loyaulte me lie ==

Nothing is foolproof - to a sufficiently talented fool

[toc] | [prev] | [next] | [standalone]


#6304

FromPaul Stewart <narrowboat-paul@outlook.com>
Date2022-01-02 21:56 +0000
Message-ID<12c0ada459.Paul@outlook.com>
In reply to#6303
In message <65baa8a459.harriet@bazleyfamily.co.uk>
          Harriet Bazley <harriet@bazleyfamily.co.uk> wrote:

>>L.
>    10 PROCarray
>    16 PRINT D$(1)
>    17 END


>    20 DEF PROCarray
>    30 LOCAL D$()
>    40 DIM D$(7)
>    50 D$(1)="hat"
>    55 PRINT "array", D$(1)
>    60 ENDPROC

>>RUN
> array     hat
> Undimensioned array at line 16

Thanks for this.  Your code works perfectly.
Calling your PROCarray procedure twice, again works as expected.

Trying the same in my code, "Arrays cannot be redimensioned" error.

"Argh"

Something in my code not not right, so will take another look.

Thanks very much for your response.

-- 
Paul Stewart
Sent from A9home running RISC OS 4.42

[toc] | [prev] | [next] | [standalone]


#6306

FromPaul Stewart <narrowboat-paul@outlook.com>
Date2022-01-02 22:18 +0000
Message-ID<6cc2afa459.Paul@outlook.com>
In reply to#6304
In message <12c0ada459.Paul@outlook.com>
          Paul Stewart <narrowboat-paul@outlook.com> wrote:

> In message <65baa8a459.harriet@bazleyfamily.co.uk>
>           Harriet Bazley <harriet@bazleyfamily.co.uk> wrote:

>>>L.
>>    10 PROCarray
>>    16 PRINT D$(1)
>>    17 END


>>    20 DEF PROCarray
>>    30 LOCAL D$()
>>    40 DIM D$(7)
>>    50 D$(1)="hat"
>>    55 PRINT "array", D$(1)
>>    60 ENDPROC

>>>RUN
>> array     hat
>> Undimensioned array at line 16

> Thanks for this.  Your code works perfectly.
> Calling your PROCarray procedure twice, again works as expected.

> Trying the same in my code, "Arrays cannot be redimensioned" error.

> "Argh"

> Something in my code not not right, so will take another look.

> Thanks very much for your response.

Turns out, there were two arrays in the same procedure.
Having fixed the first one by making it local, just got fixated on that
array.  Having looked at the line number again that the error was being
reported against, it was actually the second array it was complaing about.  

Now moved dimensioning of second array out of the procedure, and all is
working as expected.

Again, thanks for your assistance with dimensioning a local array.

-- 
Paul Stewart
Sent from A9home running RISC OS 4.42

[toc] | [prev] | [next] | [standalone]


#6305

FromMartin <News03@avisoft.f9.co.uk>
Date2022-01-02 22:04 +0000
Message-ID<59a4ae6e72News03@avisoft.f9.co.uk>
In reply to#6303
In article <65baa8a459.harriet@bazleyfamily.co.uk>,
   Harriet Bazley <harriet@bazleyfamily.co.uk> wrote:
> On 2 Jan 2022 as I do recall,
>           Paul Stewart  wrote:

> > Need to pick you brains on Arrays.

> > Looking at Arrays in the Archimedies User Guide (vintage July
> > 1987), 

[Snip solution from Harriet]

But that manual is 35 years old (gosh!)

You should download the BASIC manual from
https://www.riscosopen.org/content/downloads/common
which is *much* more up to date!

-- 
Martin Avison 
Note that unfortunately this email address will become invalid
without notice if (when) any spam is received. 

[toc] | [prev] | [next] | [standalone]


#6307

FromHarriet Bazley <harriet@bazleyfamily.co.uk>
Date2022-01-02 22:43 +0000
Message-ID<d014b2a459.harriet@bazleyfamily.co.uk>
In reply to#6305
On 2 Jan 2022 as I do recall,
          Martin  wrote:

> You should download the BASIC manual from
> https://www.riscosopen.org/content/downloads/common
> which is *much* more up to date!
> 
There's certainly stuff in there about arrays that I had no idea about -
I don't know if that's because it's genuinely new since 1987, or because
I never attempted whole-array operations....


10 DIM A(2,2)

60 A() += n%*n%

equates to "square the variable n% and increase each and every element
in the array A() by the result of that calculation"

-- 
Harriet Bazley                     ==  Loyaulte me lie ==

But I don't like Spam!!!!

[toc] | [prev] | [next] | [standalone]


#6308

FromMartin <News03@avisoft.f9.co.uk>
Date2022-01-02 23:18 +0000
Message-ID<59a4b535ebNews03@avisoft.f9.co.uk>
In reply to#6307
In article <d014b2a459.harriet@bazleyfamily.co.uk>,
   Harriet Bazley <harriet@bazleyfamily.co.uk> wrote:
> On 2 Jan 2022 as I do recall,
>           Martin  wrote:

> > You should download the BASIC manual from
> > https://www.riscosopen.org/content/downloads/common
> > which is *much* more up to date!

> There's certainly stuff in there about arrays that I had no idea
> about - I don't know if that's because it's genuinely new since
> 1987, or because I never attempted whole-array operations....

> 10 DIM A(2,2)
> 60 A() += n%*n%

> equates to "square the variable n% and increase each and every
> element in the array A() by the result of that calculation"

I should perhaps have pointed out that the manual I referred to
includes updates for recent versions of BASIC (see section on
changes) and I have noticed that Paul is running RO4.42 ... so may
not have a recent version, though it can be run in ancient versions
of RISC OS.

-- 
Martin Avison 
Note that unfortunately this email address will become invalid
without notice if (when) any spam is received. 

[toc] | [prev] | [next] | [standalone]


#6309

FromSteve Drain <steve@kappa.me.uk>
Date2022-01-03 09:46 +0000
Message-ID<squgo7$nvs$1@gioia.aioe.org>
In reply to#6307
On 02/01/2022 22:43, Harriet Bazley wrote:
> On 2 Jan 2022 as I do recall,
>            Martin  wrote:
> 
>> You should download the BASIC manual from
>> https://www.riscosopen.org/content/downloads/common
>> which is *much* more up to date!
>>
> There's certainly stuff in there about arrays that I had no idea about -
> I don't know if that's because it's genuinely new since 1987, or because
> I never attempted whole-array operations....

Whole array operations have been there from the first BASIC V. I am 
particularly fond of array multiplication, the . operator. This makes 
vector transformations a doddle. It is a pity there are not more matrix 
operations.


> 10 DIM A(2,2)
> 
> 60 A() += n%*n%
> 
> equates to "square the variable n% and increase each and every element
> in the array A() by the result of that calculation"

Just a warning that the apparently similar:

  60 A() = n%*n%

has to be:

  60 A() = (n%*n%)

And do not forget:

  A() = 1,2,3,4,5,6

to fill an array.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.sys.acorn.programmer


csiph-web