Task

Show how to concatenate two arrays in your language.



If this is as simple as array1 + array2, so be it.




[indent=4]
/*
   Array concatenation, in Genie
   Tectonics: valac array-concat.gs
*/
 
/* Creates a new array */
def int_array_concat(x:array of int, y:array of int):array of int
    var a = new Array of int(false, true, 0)  /* (zero-terminated, clear, size) */
    a.append_vals (x, x.length)
    a.append_vals (y, y.length)
 
    z:array of int = (owned) a.data
    return z
 
def int_show_array(a:array of int)
    for element in a do stdout.printf("%d ", element)
    stdout.printf("\n")
 
init
    x: array of int = {1, 2, 3}
    y: array of int = {3, 2, 1, 0, -1}
    z: array of int = int_array_concat(x, y)
 
    stdout.printf("x: "); int_show_array(x)
    stdout.printf("y: "); int_show_array(y)
    stdout.printf("z: "); int_show_array(z)
    print "%d elements in new array", z.length