Array concatenation: Difference between revisions

m
imported>J7M
(add example for SmallBASIC)
(7 intermediate revisions by 5 users not shown)
Line 902:
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{works with|Chipmunk Basic}}
<syntaxhighlight lang="gwbasic"> 10 LET X = 4:Y = 5
20 DIM A(X - 1),B(Y - 1),C(X + Y - 1)
Line 909 ⟶ 910:
60 FOR I = 1 TO Y:C(X + I - 1) = B(I - 1): NEXT
70 FOR I = 1 TO X + Y: PRINT MID$ (" ",1,I > 1)C(I - 1);: NEXT</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">100 U1 = 3: U2 = 4
110 DIM A$(3)
120 DATA "The","quick","brown","fox"
130 FOR I = 0 TO U1 : READ A$(I) : NEXT I
140 DIM B$(4)
150 DATA "jumped","over","the","lazy","dog"
160 FOR I = 0 TO U2 : READ B$(I) : NEXT I
170 'SU2 ConcatArrays
180 X = U1 + 1
190 Y = U2 + 1
200 Z = X + Y
210 DIM C$(Z-1)
220 FOR I = 0 TO X-1
230 C$(I) = A$(I)
240 NEXT I
250 FOR I = 0 TO Y-1
260 C$(U1+I+1) = B$(I)
270 NEXT I
280 '
290 FOR I = 0 TO Z-1
300 PRINT C$(I); " ";
310 NEXT I
320 END</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{trans|Applesoft BASIC}}
{{works with|GW-BASIC}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">10 LET X = 4
20 LET Y = 5
30 DIM A(3)
40 DIM B(4)
50 DIM C(8)
60 FOR I = 1 TO X
70 LET A(I-1) = I
80 NEXT I
90 FOR I = 1 TO Y
100 LET B(I-1) = I*10
110 NEXT I
120 FOR I = 1 TO X
130 LET C(I-1) = A(I-1)
140 NEXT I
150 FOR I = 1 TO Y
160 LET C(X+I-1) = B(I-1)
170 NEXT I
180 FOR I = 1 TO X+Y
190 PRINT C(I-1);
200 NEXT I
210 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Quite BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">100 LET U1 = 3
105 LET U2 = 4
110 ARRAY A$
120 DATA "The","quick","brown","fox"
130 FOR I = 0 TO U1 : READ A$(I) : NEXT I
140 ARRAY B$
150 DATA "jumped","over","the","lazy","dog"
160 FOR I = 0 TO U2 : READ B$(I) : NEXT I
170 rem Sub ConcatArrays
180 LET X = U1 + 1
190 LET Y = U2 + 1
200 LET Z = X + Y
210 ARRAY C
220 FOR I = 0 TO X-1
230 LET C$(I) = A$(I)
240 NEXT I
250 FOR I = 0 TO Y-1
260 LET C$(U1 + I + 1) = B$(I)
270 NEXT I
280 rem
290 FOR I = 0 TO Z-1
300 PRINT C$(I);" ";
310 NEXT I
320 END</syntaxhighlight>
 
==={{header|BaCon}}===
<syntaxhighlight lang="bacon">DECLARE a[] = { 1, 2, 3, 4, 5 }
Line 1,007 ⟶ 1,103:
<pre>1, 2, 3, 4, 5, 6, 7, 8, 9, 10</pre>
 
=={{header|Binary Lambda Calculus}}==
 
BLC uses lists instead of arrays. List concatenation is (see also https://github.com/tromp/AIT/blob/master/lists/cat.lam)
 
<pre>00011001000110100000000000010110111100101111001111110111110110</pre>
 
=={{header|BQN}}==
Line 1,827 ⟶ 1,928:
Since FPC (Free Pascal compiler) version 3.2.0., the dynamic array concatenation operator <code>+</code> is available, provided <code>{$modeSwitch arrayOperators+}</code> (which is enabled by default in <code>{$mode Delphi}</code>).
<syntaxhighlight lang="pascal"> array2 := array0 + array1</syntaxhighlight>
Alternatively, one could use <code>concat()</code> which is independent of above modeswitch and mode. Neither option requires the use of any libraries.:
<syntaxhighlight lang="pascal"> array2 := concat(array0, array1);</syntaxhighlight>
 
Both options do not require any libraries.
A more complete example:
<syntaxhighlight lang="pascal">
Program arrayConcat;
 
{$mode delphi}
 
type
TDynArr = array of integer;
 
var
i: integer;
arr1, arr2, arrSum : TDynArr;
 
begin
arr1 := [1, 2, 3];
arr2 := [4, 5, 6];
 
arrSum := arr1 + arr2;
for i in arrSum do
write(i, ' ');
writeln;
end.
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6
</pre>
 
=={{header|FreeBASIC}}==
Line 3,073 ⟶ 3,202:
c[0..5] = a
c[6..10] = b</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
let a = [1 2 3]
let b = [4 5 6]
[$a $b] | flatten
</syntaxhighlight>
{{out}}
<pre>
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
│ 4 │ 5 │
│ 5 │ 6 │
╰───┴───╯
</pre>
 
=={{header|Oberon-2}}==
Line 4,578 ⟶ 4,725:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var arr1 = [1,2,3]
var arr2 = [4,5,6]
System.print(arr1 + arr2)</syntaxhighlight>
56

edits