Discussion:
Arrays in BASIC
(too old to reply)
Paul Stewart
2022-01-02 20:36:06 UTC
Permalink
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
Harriet Bazley
2022-01-02 21:01:45 UTC
Permalink
On 2 Jan 2022 as I do recall,
Post by Paul Stewart
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
Post by Paul Stewart
RUN
array hat
Undimensioned array at line 16
--
Harriet Bazley == Loyaulte me lie ==

Nothing is foolproof - to a sufficiently talented fool
Paul Stewart
2022-01-02 21:56:36 UTC
Permalink
Post by Harriet Bazley
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
Paul Stewart
2022-01-02 22:18:33 UTC
Permalink
Post by Paul Stewart
Post by Harriet Bazley
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
Martin
2022-01-02 22:04:03 UTC
Permalink
Post by Harriet Bazley
On 2 Jan 2022 as I do recall,
Post by Paul Stewart
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.
Harriet Bazley
2022-01-02 22:43:55 UTC
Permalink
On 2 Jan 2022 as I do recall,
Post by Martin
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!!!!
Steve Drain
2022-01-03 09:46:26 UTC
Permalink
Post by Harriet Bazley
On 2 Jan 2022 as I do recall,
Post by Martin
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.
Post by Harriet Bazley
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.

Loading...