Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1 +1 @@
main : { [1 2 3] [4 5 6] cat }
main : { [val 1 2 3] [val 4 5 6] cat }

View file

@ -0,0 +1,12 @@
program Concat_Arrays
implicit none
integer, dimension(3) :: a = [ 1, 2, 3 ]
integer, dimension(3) :: b = [ 4, 5, 6 ]
integer, dimension(:), allocatable :: c
c = [a, b]
write(*,*) c
end program Concat_Arrays

View file

@ -0,0 +1,50 @@
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.

View file

@ -0,0 +1,6 @@
DEFINT A(1 to 4) = {1, 2, 3, 4}
DEFINT B(1 to 4) = {10, 20, 30, 40}
'Append array B to array A
Redim A(1 to 8) as integer
MEMCPY(varptr(A(5)), varptr(B(1)), Sizeof(integer)*4)

View file

@ -0,0 +1,3 @@
Concat({1,2,3}, {4,5,6})
Out> {1, 2, 3, 4, 5, 6}