LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Initializing an array from a function

Root / Programming Questions / [.]

NeatNitCreated:
I know that arrays can be assigned like variables, and do so via reference rather than values:
DIM A[2], B[3]
A[1] = 200 ' A = [0, 200]
B[2] = 7 ' B = [0, 0, 7]
A = B ' the array [0, 200] is gone forever
A[0] = 33 ' A = B = [33, 0, 7]
It is also possible to make functions that return an array:
DIM A[0]
A = NEW_ARR(5)

DEF NEW_ARR(N)
  DIM ARR[N]
  VAR I
  FOR I = 0 TO N - 1
    ARR[I] = I
  NEXT
  RETURN ARR
END
But, is it possible to initialize an array from within its declaration (without creating an unused array and immediately reassigning)? None of these work:
DIM A = NEW_ARR(5)
DIM A[] = NEW_ARR(5)
DIM A[5] = NEW_ARR(5)
If they did, I would quite like it for code readability reasons.

It's not possible. You'll have to either do what you were doing before, or in some cases it might be easier to use something like this:
DIM A[7]
NEW A

DEF NEW ARRAY
 FOR I=0 TO LEN(ARRAY)-1
  ARRAY[I]=I
 NEXT
END

It's not possible. SNIP!!!!!!!!!!!!!!!!!!!!
anything is possible with SMILEBASIC!