`prev Menu next`

Array parameter ☆
Function definitions and subprograms can take arrays as parameters.
(1) Notation for Parameters
Array parameters are denoted by its name, parentheses and commas.
A() for 1-dimensional array A
A(,) for 2-dimensional array A
A(,,) for 3-dimensional array A
Example.
`EXTERNAL SUB SAMPLE(A())`
(2) Notation for Arguments
Array arguments are denoted by only array names.
Example.
`CALL SAMPLE(A)`
Example. Dot product of vectors

    10 DEF DOT(a(),b())=a(1)*b(1)+a(2)*b(2)
    20 DIM m(2),n(2)
    30 MAT READ m
    35 DATA 1,2
    40 MAT READ n
    45 DATA 3,4
    50 PRINT DOT(m,n)
    60 END

Use a UBOUND function to know the upper bound of indices of an array within a subprogram.
Example. A function that calculate the sum of all elements of an array.

    100 DECLARE EXTERNAL FUNCTION ADD
    110 DIM m(100)
    120 MAT INPUT m(?)
    130 PRINT ADD(m)
    140 END
    200 EXTERNAL FUNCTION ADD(a())
    210 LET t=0
    220 FOR i=1 TO UBOUND(a)
    230    LET t=t+a(i)
    240 NEXT i
    250 LET ADD=t
    260 END FUNCTION

Supplementary Explanation
When the 120-line is executed, enter an arbitrary but not greater than 100 number of numerics separated by commas. Then the upper bound of the array m becomes the number of numeric inputed.
Note.
When a function definition has an array parameter, the array shall be copied to the parameter.
Thus even if the parameter is changed, the argument does not change.
When a subprogram has an array parameter, the array itself is passed to the subprogram.
If the element of the array is changed, the alteration influences the argument.

すると，その変更は実引数に及ぶ。