• Re: Arrays in BASIC

    From Harriet Bazley@21:1/5 to Paul Stewart on Sun Jan 2 21:01:45 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Stewart@21:1/5 to All on Sun Jan 2 20:36:06 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Stewart@21:1/5 to Harriet Bazley on Sun Jan 2 21:56:36 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Martin@21:1/5 to Harriet Bazley on Sun Jan 2 22:04:03 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harriet Bazley@21:1/5 to Martin on Sun Jan 2 22:43:55 2022
    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!!!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Stewart@21:1/5 to Paul Stewart on Sun Jan 2 22:18:33 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Martin@21:1/5 to Harriet Bazley on Sun Jan 2 23:18:05 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Steve Drain@21:1/5 to Harriet Bazley on Mon Jan 3 09:46:26 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)