Array concatenation: Difference between revisions

m
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(35 intermediate revisions by 25 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 961 ⟶ 1,057:
160 : PRINT C(I);
170 NEXT</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
The [[#Liberty BASIC|Liberty BASIC]] solution works without any changes.
 
=={{header|BASIC256}}==
Line 1,002 ⟶ 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,210 ⟶ 1,316:
 
=={{header|COBOL}}==
{{works with|COBOL 2014}}
<syntaxhighlight lang="cobol"> identification division.
<syntaxhighlight lang="cobolfree">IDENTIFICATION DIVISION.
program-id. array-concat.
PROGRAM-ID. array-concat.
 
environment division.
configuration section.
repository.
function all intrinsic.
 
data division.
working-storage section.
01 table-one.
05 int-field pic 999 occurs 0 to 5 depending on t1.
01 table-two.
05 int-field pic 9(4) occurs 0 to 10 depending on t2.
 
77 t1 pic 99.
77 t2 pic 99.
 
77 show pic z(4).
 
DATA DIVISION.
procedure division.
WORKING-STORAGE SECTION.
array-concat-main.
01 table-one.
perform initialize-tables
05 int-field PIC 999 OCCURS 0 TO 5 TIMES DEPENDING ON t1.
perform concatenate-tables
01 table-two.
perform display-result
05 int-field PIC 9(4) OCCURS 0 TO 10 TIMES DEPENDING ON t2.
goback.
77 tally USAGE IS INDEX.
77 t1 PIC 99.
77 t2 PIC 99.
77 show PIC Z(4) USAGE IS DISPLAY.
 
PROCEDURE DIVISION.
initialize-tables.
array-concat-main.
move 4 to t1
PERFORM initialize-tables
perform varying tally from 1 by 1 until tally > t1
PERFORM concatenate-tables
compute int-field of table-one(tally) = tally * 3
PERFORM enddisplay-performresult
GOBACK.
 
initialize-tables.
move 3 to t2
MOVE 4 TO t1
perform varying tally from 1 by 1 until tally > t2
PERFORM VARYING tally FROM 1 BY 1 compute int-field of table-two(tally) =UNTIL tally *> 6t1
COMPUTE int-field OF endtable-performone(tally) = tally * 3
.END-PERFORM
MOVE 3 TO t2
PERFORM VARYING tally FROM 1 BY 1 UNTIL tally > t2
COMPUTE int-field OF table-two(tally) = tally * 6
END-PERFORM.
 
concatenate-tables.
PERFORM perform varyingVARYING tally fromFROM 1 byBY 1 untilUNTIL tally > t1
addADD 1 toTO t2
moveMOVE int-field ofOF table-one(tally)
toTO int-field ofOF table-two(t2)
endEND-performPERFORM.
.
 
display-result.
PERFORM perform varyingVARYING tally fromFROM 1 byBY 1 untilUNTIL tally = t2
moveMOVE int-field ofOF table-two(tally) toTO show
DISPLAY FUNCTION display trimTRIM(show) ", " withWITH noNO advancingADVANCING
endEND-performPERFORM
moveMOVE int-field ofOF table-two(tally) toTO show
DISPLAY FUNCTION display trimTRIM(show).
.
 
END end programPROGRAM array-concat.</syntaxhighlight>
{{out}}
<pre>prompt$ cobc -xjd array-concatenation.cob --std=cobol2014 # COBOL 2014 needed for FUNCTION TRIM
6, 12, 18, 3, 6, 9, 12
</pre>
Line 1,538 ⟶ 1,635:
b[] = [ 4 5 6 ]
c[] = a[]
whilefor ih < lenin b[]
c[] &= b[i]h
i += 1
.
print c[]</syntaxhighlight>
Line 1,570 ⟶ 1,666:
 
C := A + B;</syntaxhighlight>
 
=={{header|Ecstasy}}==
It is as simple as <code><var>array1</var> + <var>array2</var></code>:
<syntaxhighlight lang="java">String[] fruits = ["apples", "oranges"];
String[] grains = ["wheat", "corn"];
String[] all = fruits + grains;</syntaxhighlight>
 
=={{header|Efene}}==
Line 1,664 ⟶ 1,766:
<syntaxhighlight lang="lisp">(vconcat '[1 2 3] '[4 5] '[6 7 8 9])
=> [1 2 3 4 5 6 7 8 9]</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
^|EMal has the concept of list expansion,
|you can expand a list to function arguments
|by prefixing it with the unary plus.
|^
List a = int[1,2,3]
List b = int[4,5,6]
List c = int[+a, +b]
writeLine(c)
</syntaxhighlight>
{{out}}
<pre>
[1,2,3,4,5,6]
</pre>
 
=={{header|Erlang}}==
Line 1,810 ⟶ 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 2,248 ⟶ 2,394:
let B be {4, 5, 6};
add B to A;</syntaxhighlight>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(into [1 2 3] [4 5 6])</syntaxhighlight>
 
<syntaxhighlight lang="insitux">(.. vec [1 2 3] [4 5 6])</syntaxhighlight>
 
=={{header|Ioke}}==
Line 2,301 ⟶ 2,452:
2 3 3</syntaxhighlight>
 
=={{header|JavaJakt}}==
<syntaxhighlight lang="java5jakt">public static Object[] concat(Object[] arr1, Object[] arr2) {
fn main() {
Object[] res = new Object[arr1.length + arr2.length];
let a = ["Apple", "Banana"]
let b = ["Cherry", "Durian"]
mut c: [String] = []
c.push_values(&a)
c.push_values(&b)
println("{}", c)
}
</syntaxhighlight>
 
{{out}}
System.arraycopy(arr1, 0, res, 0, arr1.length);
<pre>
System.arraycopy(arr2, 0, res, arr1.length, arr2.length);
["Apple", "Banana", "Cherry", "Durian"]
</pre>
 
=={{header|Java}}==
return res;
In Java, arrays are immutable, so you'll have to create a new array, and copy the contents of the two arrays into it.<br />
}</syntaxhighlight>
Luckily, Java offers the ''System.arraycopy'' method, which will save you the effort of creating the for-loops.<br />
<syntaxhighlight lang="java">
int[] concat(int[] arrayA, int[] arrayB) {
int[] array = new int[arrayA.length + arrayB.length];
System.arraycopy(arrayA, 0, array, 0, arrayA.length);
System.arraycopy(arrayB, 0, array, arrayA.length, arrayB.length);
return array;
}
</syntaxhighlight>
If you wanted to use for-loops, possibly to mutate the data as it's concatenated, you can use the following.
<syntaxhighlight lang="java">
int[] concat(int[] arrayA, int[] arrayB) {
int[] array = new int[arrayA.length + arrayB.length];
for (int index = 0; index < arrayA.length; index++)
array[index] = arrayA[index];
for (int index = 0; index < arrayB.length; index++)
array[index + arrayA.length] = arrayB[index];
return array;
}
</syntaxhighlight>
A less idiomatic approach would be to use a ''List'', which is a mutable array, similar to a "vector" in other languages.<br />
I have used both arrays and ''List''s extensively and have not noticed any sort of performance degradation, they appear to work equally as fast.<br />
It's worth noting that the Java Collections Framework, which contains the ''List'' class, is built specifically for Objects and not necessarily primitive data-types. Despite this, it's still worth using for primitives, although the conversion to and from arrays is somewhat abstruse.
<syntaxhighlight lang="java">
int[] concat(int[] arrayA, int[] arrayB) {
List<Integer> list = new ArrayList<>();
for (int value : arrayA) list.add(value);
for (int value : arrayB) list.add(value);
int[] array = new int[list.size()];
for (int index = 0; index < list.size(); index++)
array[index] = list.get(index);
return array;
}
</syntaxhighlight>
 
=={{header|JavaScript}}==
Line 2,343 ⟶ 2,538:
 
<pre>["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota"]</pre>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">[1 2 3] [4 5 6] concat.</syntaxhighlight>
 
=={{header|jq}}==
Line 2,431 ⟶ 2,629:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">fun main() {
There is no operator or standard library function for concatenating <code>Array</code> types. One option is to convert to <code>Collection</code>s, concatenate, and convert back:
val a = intArrayOf(1, 2, 3)
<syntaxhighlight lang="kotlin">fun main(args: Array<String>) {
val a: Array<Int>b = arrayOfintArrayOf(14, 25, 36) // initialise a
val c = a + b: Array<Int>// =[1, 2, 3, arrayOf(4, 5, 6) // initialise b]
println(c.contentToString())
val c: Array<Int> = (a.toList() + b.toList()).toTypedArray()
println(c)
}</syntaxhighlight>
 
Alternatively, we can write our own concatenation function:
<syntaxhighlight lang="kotlin">fun arrayConcat(a: Array<Any>, b: Array<Any>): Array<Any> {
return Array(a.size + b.size, { if (it in a.indices) a[it] else b[it - a.size] })
}</syntaxhighlight>
 
When working directly with <code>Collection</code>s, we can simply use the <code>+</code> operator:
<syntaxhighlight lang="kotlin">fun main(args: Array<String>) {
val a: Collection<Int> = listOf(1, 2, 3) // initialise a
val b: Collection<Int> = listOf(4, 5, 6) // initialise b
val c: Collection<Int> = a + b
println(c)
}</syntaxhighlight>
 
Line 2,461 ⟶ 2,645:
{def B {A.new 7 8 9}} -> [7,8,9]
{A.concat {A} {B}} -> [1,2,3,4,5,6,7,8,9]
</syntaxhighlight>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
&a $= [1, 2, 3]
&b $= [4, 5, 6]
&c $= &a ||| &b
fn.println(&c)
</syntaxhighlight>
 
Line 2,489 ⟶ 2,681:
arr3 = array(4, 5, 6)
arr3 = array(1, 2, 3, 4, 5, 6)</syntaxhighlight>
 
=={{header|LDPL}}==
{{libheader|ldpl-std}}
<syntaxhighlight lang="ldpl">include "std-list.ldpl"
 
data:
arr1 is number list
arr2 is number list
 
procedure:
push 1 to arr1
push 2 to arr1
push 3 to arr2
push 4 to arr2
append list arr2 to list arr1
display list arr1
</syntaxhighlight>
{{out}}
<pre>
[1, 2, 3, 4]
</pre>
 
=={{header|LFE}}==
Line 2,499 ⟶ 2,712:
 
=={{header|Liberty BASIC}}==
{{works with|Just BASIC}}
{{works with|Run BASIC}}
<syntaxhighlight lang="lb"> x=10
y=20
Line 2,632 ⟶ 2,847:
1 1
1 1
6 6
</pre >
 
Adding 2 dimension arrays using OLE clause
 
<syntaxhighlight lang="m2000 interpreter">
Dim OLE Base 0, A(2,2)=1, B(1,2)=6
A()=Cons(A(), B(), A(), B())
\\ Restore the dimensions (without erasing items)
Dim A(Dimension(A(),1)/2, 2)
For I=0 to Dimension(A(),1)-1 {
For j=0 to Dimension(A(),2)-1 {
Print A(i, j),
}
Print
}
</syntaxhighlight>
{{out}}
<pre>
1 1
1 1
1 1
1 1
6 6
6 6
</pre >
Line 2,963 ⟶ 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 3,085 ⟶ 3,342:
# let array1and2 = Array.append array1 array2;;
val array1and2 : int array = [|1; 2; 3; 4; 5; 6|]</syntaxhighlight>
 
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
 
import "core:fmt"
import "core:slice"
 
main :: proc() {
x: [3]int = {1, 2, 3}
y: [3]int = {4, 5, 6}
 
xy: [len(x) + len(y)]int
copy(xy[:], x[:])
copy(xy[len(x):], y[:])
 
fmt.println(xy)
}</syntaxhighlight>
===Using slices===
<syntaxhighlight lang="odin">package main
 
import "core:fmt"
import "core:slice"
 
main :: proc() {
x: [3]int = {1, 2, 3}
y: [3]int = {4, 5, 6}
 
xy := slice.concatenate([][]int{x[:], y[:]})
defer delete(xy)
 
fmt.println(xy)
}</syntaxhighlight>
 
=={{header|Oforth}}==
Line 3,308 ⟶ 3,597:
0 0 0 0 15 16
 
</syntaxhighlight>
 
=={{header|Plain English}}==
Plain English has these functions for concatenating two sets of things:
<syntaxhighlight lang="text">
To append some things to some other things:
Put the things' first into a thing.
If the thing is nil, exit.
Remove the thing from the things.
Append the thing to the other things.
Repeat.
 
To prepend some things to some other things:
Get a thing from the things (backwards).
If the thing is nil, exit.
Remove the thing from the things.
Prepend the thing to the other things.
Repeat.
</syntaxhighlight>
 
Line 3,736 ⟶ 4,043:
>>
</syntaxhighlight>
 
=={{header|RPL}}==
In RPL, what is called arrays are actually vectors. Sets of numbers can be stored either in such data structures or in lists, depending on the planned use. Vectors are great for arithmetics, but lists are more versatile.
{{works with|Halcyon Calc|4.2.7}}
=== Vector concatenation===
≪ SWAP ARRY→ LIST→ DROP → n
≪ n 1 + ROLL ARRY→ LIST→ DROP
n + 1 →LIST →ARRY
≫ ≫ 'CONCAT' STO
 
 
[1 2 3] [4 5] CONCAT
{{out}}
<pre>
1: [1 2 3 4 5]
</pre>
A shorter version, without any local variable:
≪ SWAP ARRY→ 1 GET →LIST
SWAP ARRY→ 1 GET →LIST
+ LIST→ { } + →ARRY
≫ 'CONCAT' STO
 
=== List concatenation===
No need for a program to do that:
{1 2 3} {4 5} +
{{out}}
<pre>
1: {1 2 3 4 5}
</pre>
 
=={{header|Ruby}}==
Line 4,013 ⟶ 4,349:
 
<syntaxhighlight lang="slope">(list-join [1 2 3] [4 5 6])</syntaxhighlight>
 
=={{header|SmallBASIC}}==
<syntaxhighlight lang="SmallBASIC">
A = [1,2,3]
B = [4,5,6]
 
for i in B do A << i
 
print A
</syntaxhighlight>
 
=={{header|Smalltalk}}==
Line 4,054 ⟶ 4,400:
6 7 8 9 10
1 2 3 4 5 6 7 8 9 10</pre>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "arraycat" )
@( description, "Show how to concatenate two arrays in your language." )
@( category, "tutorials" )
@( author, "Ken O. Burtch" )
@( see_also, "http://rosettacode.org/wiki/Array_concatenation" );
pragma license( unrestricted );
 
pragma software_model( nonstandard );
pragma restriction( no_external_commands );
 
procedure arraycat is
type arrayOf3 is array(1..3) of integer;
a1 : constant arrayOf3 := (1, 2, 3);
a2 : constant arrayOf3 := (4, 5, 6);
type arrayOf6 is array(1..6) of integer;
a3 : arrayOf6;
p : natural := arrays.first(a3);
begin
-- In SparForte, & only works on strings and there's no indefinite ranges
-- or array slicing. We have to do this the hard way, one element at a
-- time.
for i in arrays.first(a1)..arrays.last(a1) loop
a3(p) := a1(i);
p := @+1;
end loop;
for i in arrays.first(a2)..arrays.last(a2) loop
a3(p) := a2(i);
p := @+1;
end loop;
-- show the array
for i in arrays.first(a3)..arrays.last(a3) loop
put( a3(i) );
end loop;
new_line;
end arraycat;</syntaxhighlight>
 
=={{header|Standard ML}}==
Line 4,340 ⟶ 4,725:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var arr1 = [1,2,3]
var arr2 = [4,5,6]
System.print(arr1 + arr2)</syntaxhighlight>
{{Out}}
<pre>[1, 2, 3, 4, 5, 6]</pre>
 
=={{header|XPL0}}==
{{trans|C}}
A way to concatenate two XPL0 arrays when you know their size (and usually it is so).
Works on Raspberry Pi. MAlloc works differently in other versions.
<syntaxhighlight lang "XPL0">func Array_concat(A, AN, B, BN, S);
int A, AN, B, BN, S;
int P;
[
P:= MAlloc(S * (AN + BN));
CopyMem(P, A, AN*S);
CopyMem(P + AN*S, B, BN*S);
return P;
];
 
\ testing
int A, B, C, I, SizeOf;
[
A:= [ 1, 2, 3, 4, 5 ];
B:= [ 6, 7, 8, 9, 0 ];
 
SizeOf:= @B - @A;
 
C:= Array_concat(A, 5, B, 5, SizeOf);
 
for I:= 0 to 10-1 do
[IntOut(0, C(I)); ChOut(0, ^ )];
 
Release(C);
]</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 0 </pre>
 
=={{header|Yabasic}}==
Line 4,434 ⟶ 4,852:
801D:
AA BB CC DD EE FF 23 45 67 89
</pre>
 
=={{header|Zig}}==
There are no hidden memory allocations in Zig.
<syntaxhighlight lang="zig">
const std = @import("std");
 
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
 
const allocator = gpa.allocator();
 
var array1 = [_]u32{ 1, 2, 3, 4, 5 };
var array2 = [_]u32{ 6, 7, 8, 9, 10, 11, 12 };
 
const slice3 = try std.mem.concat(allocator, u32, &[_][]const u32{ &array1, &array2 });
defer allocator.free(slice3);
 
// Same result, alternative syntax
const slice4 = try std.mem.concat(allocator, u32, &[_][]const u32{ array1[0..], array2[0..] });
defer allocator.free(slice4);
 
std.debug.print(
"Array 1: {any}\nArray 2: {any}\nSlice 3: {any}\nSlice 4: {any}\n",
.{ array1, array2, slice3, slice4 },
);
}
</syntaxhighlight>
{{out}}
<pre>
Array 1: { 1, 2, 3, 4, 5 }
Array 2: { 6, 7, 8, 9, 10, 11, 12 }
Slice 3: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
Slice 4: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
</pre>
 
56

edits