Task

Show how to concatenate two arrays in your language.



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




 
MODULE ArrayConcat;
IMPORT
  Out;
TYPE
  IntArray = POINTER TO ARRAY OF INTEGER;
VAR
  x, y, z: IntArray;
 
  PROCEDURE InitArray(VAR x: IntArray;from: INTEGER);
  VAR
    i: LONGINT;
  BEGIN
    FOR i := 0 TO LEN(x^) - 1 DO
      x[i] := from;
      INC(from)
    END
  END InitArray;
 
  PROCEDURE Concat(x,y: IntArray; VAR z: IntArray);
  VAR
    i: LONGINT;
  BEGIN
    ASSERT(LEN(x^) + LEN(y^) <= LEN(z^));
    FOR i := 0 TO LEN(x^) - 1 DO z[i] := x[i] END;
    FOR i := 0 TO LEN(y^) - 1 DO z[i + LEN(x^)] := y[i] END
  END Concat;
 
  PROCEDURE Show(x: IntArray);
  VAR
    i: INTEGER;
  BEGIN
    i := 0;
    Out.Char('[');
    WHILE (i < LEN(x^)) DO
      Out.LongInt(x[i],3);IF i < LEN(x^) - 1 THEN Out.Char(',') END;
      INC(i)
    END;
    Out.Char(']');Out.Ln
  END Show;
 
BEGIN
  (* Standard types *)
  NEW(x,5);InitArray(x,1);
  NEW(y,10);InitArray(y,6);
  NEW(z,LEN(x^) + LEN(y^));
 
  Concat(x,y,z);
  Show(z)
 
END ArrayConcat.
 