Concatenating two arrays

Discussions related to mathematics, numerical methods, graph plotting etc.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Concatenating two arrays

Post by Richard Russell »

Have you ever wanted to concatenate two one-dimensional arrays into a single array, without laboriously copying the elements individually? With array slicing you can:

Code: Select all

      DEF PROCconcatenate(a(), b(), RETURN c())
      LOCAL A%, B% : A% = DIM(a(),1) : B% = DIM(b(),1)
      DIM c(A% + B% + 1)
      c(0 TO A%) = a() : c(A% + 1 TO) = b()
      ENDPROC
This code runs now in the Console Mode editions of BBC BASIC (BBCTTY), try it. I will hope to release the array-slicing upgrade for BBCSDL and BB4W once I've received enough feedback to give me confidence that I've not broken anything.