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 ENDBut, 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.