Array concatenation: Difference between revisions

Content added Content deleted
(Array concatenation in Rapira)
m (syntax highlighting fixup automation)
Line 10: Line 10:


=={{header|11l}}==
=={{header|11l}}==
<lang 11l>V arr1 = [1, 2, 3]
<syntaxhighlight lang=11l>V arr1 = [1, 2, 3]
V arr2 = [4, 5, 6]
V arr2 = [4, 5, 6]
print(arr1 [+] arr2)</lang>
print(arr1 [+] arr2)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 21: Line 21:
In order for this to work, you'll either need to use <code>malloc()</code> or know a memory location of "free space" at compile time. This example shall use the latter.
In order for this to work, you'll either need to use <code>malloc()</code> or know a memory location of "free space" at compile time. This example shall use the latter.


<lang 68000devpac>ArrayRam equ $00FF2000 ;this label points to 4k of free space.
<syntaxhighlight lang=68000devpac>ArrayRam equ $00FF2000 ;this label points to 4k of free space.


;concatenate Array1 + Array2
;concatenate Array1 + Array2
Line 43: Line 43:
DC.W 1,2,3,4,5
DC.W 1,2,3,4,5
Array2:
Array2:
DC.W 6,7,8,9,10</lang>
DC.W 6,7,8,9,10</syntaxhighlight>


=={{header|8th}}==
=={{header|8th}}==
<lang Forth>
<syntaxhighlight lang=Forth>
[1,2,3] [4,5,6] a:+ .
[1,2,3] [4,5,6] a:+ .
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 56: Line 56:
=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<lang AArch64 Assembly>
<syntaxhighlight lang=AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program concAreaString.s */
/* program concAreaString.s */
Line 158: Line 158:
/* for this file see task include a file in language AArch64 assembly */
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>


=={{header|ABAP}}==
=={{header|ABAP}}==
The concept of arrays does not exist in ABAP, instead internal tables are used. This works in ABAP version 7.40 and above.
The concept of arrays does not exist in ABAP, instead internal tables are used. This works in ABAP version 7.40 and above.


<lang ABAP>
<syntaxhighlight lang=ABAP>
report z_array_concatenation.
report z_array_concatenation.


Line 174: Line 174:
write <line>.
write <line>.
endloop.
endloop.
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 184: Line 184:
=={{header|ACL2}}==
=={{header|ACL2}}==
This is for lists, not arrays; ACL2's array support is limited.
This is for lists, not arrays; ACL2's array support is limited.
<lang Lisp>(append xs ys)</lang>
<syntaxhighlight lang=Lisp>(append xs ys)</syntaxhighlight>


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>BYTE FUNC Concat(INT ARRAY src1,src2,dst BYTE size1,size2)
<syntaxhighlight lang=Action!>BYTE FUNC Concat(INT ARRAY src1,src2,dst BYTE size1,size2)
BYTE i
BYTE i


Line 237: Line 237:
Test(a2,a1,6,4)
Test(a2,a1,6,4)
Test(a3,a2,5,4)
Test(a3,a2,5,4)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Array_concatenation.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Array_concatenation.png Screenshot from Atari 8-bit computer]
Line 249: Line 249:


=={{header|ActionScript}}==
=={{header|ActionScript}}==
<lang ActionScript>var array1:Array = new Array(1, 2, 3);
<syntaxhighlight lang=ActionScript>var array1:Array = new Array(1, 2, 3);
var array2:Array = new Array(4, 5, 6);
var array2:Array = new Array(4, 5, 6);
var array3:Array = array1.concat(array2); //[1, 2, 3, 4, 5, 6]</lang>
var array3:Array = array1.concat(array2); //[1, 2, 3, 4, 5, 6]</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
In [[Ada]] arrays are concatenated using the operation &. It works with any one dimensioned array:
In [[Ada]] arrays are concatenated using the operation &. It works with any one dimensioned array:
<lang Ada>type T is array (Positive range <>) of Integer;
<syntaxhighlight lang=Ada>type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6); -- Concatenate X and (4, 5, 6)</lang>
Y : T := X & (4, 5, 6); -- Concatenate X and (4, 5, 6)</syntaxhighlight>


=={{header|Aime}}==
=={{header|Aime}}==
<lang aime>ac(list a, b)
<syntaxhighlight lang=aime>ac(list a, b)
{
{
list o;
list o;
Line 282: Line 282:


0;
0;
}</lang>
}</syntaxhighlight>
{{Out}}
{{Out}}
<pre> 1 2 3 4 5 6 7 8</pre>
<pre> 1 2 3 4 5 6 7 8</pre>
Line 293: Line 293:
<!-- {{not tested with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8.8d.fc9.i386]}} -->
<!-- {{not tested with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8.8d.fc9.i386]}} -->
Includes operators for ''appending'' and ''prefixing'' an array to an existing flexible array:
Includes operators for ''appending'' and ''prefixing'' an array to an existing flexible array:
<lang Algol68>MODE ARGTYPE = INT;
<syntaxhighlight lang=Algol68>MODE ARGTYPE = INT;
MODE ARGLIST = FLEX[0]ARGTYPE;
MODE ARGLIST = FLEX[0]ARGTYPE;


Line 322: Line 322:


VOID(a +=: b);
VOID(a +=: b);
print(("a +=: b", b, new line))</lang>
print(("a +=: b", b, new line))</syntaxhighlight>
<pre>
<pre>
a + b +1 +2 +3 +4 +5
a + b +1 +2 +3 +4 +5
Line 331: Line 331:
=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
Algol W does not allow procedures to return arrays and has no mechanism for procedures to find the bounds of their parameters, so the caller must supply an array to concatenate into and the bounds of the arrays.
Algol W does not allow procedures to return arrays and has no mechanism for procedures to find the bounds of their parameters, so the caller must supply an array to concatenate into and the bounds of the arrays.
<lang algolw>begin
<syntaxhighlight lang=algolw>begin
integer array a ( 1 :: 5 );
integer array a ( 1 :: 5 );
integer array b ( 2 :: 4 );
integer array b ( 2 :: 4 );
Line 366: Line 366:
for cPos := 1 until 8 do writeon( i_w := 1, s_w := 1, c( cPos ) )
for cPos := 1 until 8 do writeon( i_w := 1, s_w := 1, c( cPos ) )


end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 373: Line 373:


=={{header|Amazing Hopper}}==
=={{header|Amazing Hopper}}==
<lang Amazing Hopper>
<syntaxhighlight lang=Amazing Hopper>
#include <hbasic.h>
#include <hbasic.h>
Begin
Begin
Line 382: Line 382:
Concat (a1, a2) and Print ( a2, Newl )
Concat (a1, a2) and Print ( a2, Newl )
End
End
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 389: Line 389:


=={{header|AntLang}}==
=={{header|AntLang}}==
<lang AntLang>a:<1; <2; 3>>
<syntaxhighlight lang=AntLang>a:<1; <2; 3>>
b: <"Hello"; 42>
b: <"Hello"; 42>
c: a,b</lang>
c: a,b</syntaxhighlight>


=={{header|Apex}}==
=={{header|Apex}}==
<lang apex>List<String> listA = new List<String> { 'apple' };
<syntaxhighlight lang=apex>List<String> listA = new List<String> { 'apple' };
List<String> listB = new List<String> { 'banana' };
List<String> listB = new List<String> { 'banana' };
listA.addAll(listB);
listA.addAll(listB);
System.debug(listA); // Prints (apple, banana)</lang>
System.debug(listA); // Prints (apple, banana)</syntaxhighlight>


=={{header|APL}}==
=={{header|APL}}==
<lang apl>
<syntaxhighlight lang=apl>
1 2 3 , 4 5 6
1 2 3 , 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
</syntaxhighlight>
</lang>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<lang AppleScript>
<syntaxhighlight lang=AppleScript>
set listA to {1, 2, 3}
set listA to {1, 2, 3}
set listB to {4, 5, 6}
set listB to {4, 5, 6}
return listA & listB
return listA & listB
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 422: Line 422:
{{trans|JavaScript}}
{{trans|JavaScript}}


<lang applescript>on run
<syntaxhighlight lang=applescript>on run


concat([["alpha", "beta", "gamma"], ¬
concat([["alpha", "beta", "gamma"], ¬
Line 440: Line 440:
end concat
end concat


</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 448: Line 448:
=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<lang ARM Assembly>
<syntaxhighlight lang=ARM Assembly>
/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
/* program concAreaString.s */
/* program concAreaString.s */
Line 620: Line 620:
.Ls_magic_number_10: .word 0x66666667
.Ls_magic_number_10: .word 0x66666667


</syntaxhighlight>
</lang>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>arr1: [1 2 3]
<syntaxhighlight lang=rebol>arr1: [1 2 3]
arr2: ["four" "five" "six"]
arr2: ["four" "five" "six"]
print arr1 ++ arr2</lang>
print arr1 ++ arr2</syntaxhighlight>
{{out}}
{{out}}
Line 636: Line 636:
The following may seem frightening. However, it probably compiles down to two calls to __builtin_memcpy. All the complexity is to make sure those calls are done ''correctly''.
The following may seem frightening. However, it probably compiles down to two calls to __builtin_memcpy. All the complexity is to make sure those calls are done ''correctly''.


<lang ats>(* The Rosetta Code array concatenation task, in ATS2. *)
<syntaxhighlight lang=ats>(* The Rosetta Code array concatenation task, in ATS2. *)


(* In a way, the task is misleading: in a language such as ATS, one
(* In a way, the task is misleading: in a language such as ATS, one
Line 757: Line 757:
free lst (* The list is linear and must be freed. *)
free lst (* The list is linear and must be freed. *)
end
end
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 772: Line 772:
=== True Arrays ===
=== True Arrays ===
{{works with|AutoHotkey_L}}
{{works with|AutoHotkey_L}}
<lang AHK>List1 := [1, 2, 3]
<syntaxhighlight lang=AHK>List1 := [1, 2, 3]
List2 := [4, 5, 6]
List2 := [4, 5, 6]
cList := Arr_concatenate(List1, List2)
cList := Arr_concatenate(List1, List2)
Line 789: Line 789:
res .= ", " value
res .= ", " value
return "[" SubStr(res, 3) "]"
return "[" SubStr(res, 3) "]"
}</lang>
}</syntaxhighlight>
=== Legacy versions ===
=== Legacy versions ===
[[AutoHotkey_Basic]] does not have real Arrays, but the user can implement them quite easily. For example:
[[AutoHotkey_Basic]] does not have real Arrays, but the user can implement them quite easily. For example:
<lang AutoHotkey>List1 = 1,2,3
<syntaxhighlight lang=AutoHotkey>List1 = 1,2,3
List2 = 4,5,6
List2 = 4,5,6


Line 828: Line 828:
List .= (A_Index = 1 ? "" : ",") %Array%%A_Index%
List .= (A_Index = 1 ? "" : ",") %Array%%A_Index%
Return, List
Return, List
}</lang>
}</syntaxhighlight>
Message box shows:
Message box shows:
<pre>1,2,3,4,5,6</pre>
<pre>1,2,3,4,5,6</pre>
Line 838: Line 838:


<lang AutoIt>
<syntaxhighlight lang=AutoIt>
_ArrayConcatenate($avArray, $avArray2)
_ArrayConcatenate($avArray, $avArray2)
Func _ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource, $iStart = 0)
Func _ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource, $iStart = 0)
Line 857: Line 857:
Return $iUBoundTarget + $iUBoundSource
Return $iUBoundTarget + $iUBoundSource
EndFunc ;==>_ArrayConcatenate
EndFunc ;==>_ArrayConcatenate
</syntaxhighlight>
</lang>


=={{header|Avail}}==
=={{header|Avail}}==
<lang Avail><1, 2, 3> ++ <¢a, ¢b, ¢c></lang>
<syntaxhighlight lang=Avail><1, 2, 3> ++ <¢a, ¢b, ¢c></syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>#!/usr/bin/awk -f
<syntaxhighlight lang=AWK>#!/usr/bin/awk -f
BEGIN {
BEGIN {
split("cul-de-sac",a,"-")
split("cul-de-sac",a,"-")
Line 881: Line 881:
c[++nc]=b[i]
c[++nc]=b[i]
}
}
}</lang>
}</syntaxhighlight>


=={{header|Babel}}==
=={{header|Babel}}==
<lang babel>[1 2 3] [4 5 6] cat ;</lang>
<syntaxhighlight lang=babel>[1 2 3] [4 5 6] cat ;</syntaxhighlight>


{{Out}}
{{Out}}
Line 890: Line 890:


=={{header|bash}}==
=={{header|bash}}==
<lang bash>x=("1 2" "3 4")
<syntaxhighlight lang=bash>x=("1 2" "3 4")
y=(5 6)
y=(5 6)
sum=( "${x[@]}" "${y[@]}" )
sum=( "${x[@]}" "${y[@]}" )
Line 898: Line 898:
3 4
3 4
5
5
6</lang>
6</syntaxhighlight>


=={{header|BASIC}}==
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<lang gwbasic> 10 LET X = 4:Y = 5
<syntaxhighlight lang=gwbasic> 10 LET X = 4:Y = 5
20 DIM A(X - 1),B(Y - 1),C(X + Y - 1)
20 DIM A(X - 1),B(Y - 1),C(X + Y - 1)
30 FOR I = 1 TO X:A(I - 1) = I: NEXT
30 FOR I = 1 TO X:A(I - 1) = I: NEXT
Line 908: Line 908:
50 FOR I = 1 TO X:C(I - 1) = A(I - 1): NEXT
50 FOR I = 1 TO X:C(I - 1) = A(I - 1): NEXT
60 FOR I = 1 TO Y:C(X + I - 1) = B(I - 1): NEXT
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</lang>
70 FOR I = 1 TO X + Y: PRINT MID$ (" ",1,I > 1)C(I - 1);: NEXT</syntaxhighlight>
==={{header|BaCon}}===
==={{header|BaCon}}===
<lang bacon>DECLARE a[] = { 1, 2, 3, 4, 5 }
<syntaxhighlight lang=bacon>DECLARE a[] = { 1, 2, 3, 4, 5 }
DECLARE b[] = { 6, 7, 8, 9, 10 }
DECLARE b[] = { 6, 7, 8, 9, 10 }


Line 918: Line 918:
c[x] = a[x]
c[x] = a[x]
c[x+5] = b[x]
c[x+5] = b[x]
NEXT</lang>
NEXT</syntaxhighlight>


==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> DIM a(3), b(4)
<syntaxhighlight lang=bbcbasic> DIM a(3), b(4)
a() = 1, 2, 3, 4
a() = 1, 2, 3, 4
b() = 5, 6, 7, 8, 9
b() = 5, 6, 7, 8, 9
Line 940: Line 940:
SYS "RtlMoveMemory", ^c(0), ^a(0), s%*na%
SYS "RtlMoveMemory", ^c(0), ^a(0), s%*na%
SYS "RtlMoveMemory", ^c(na%), ^b(0), s%*nb%
SYS "RtlMoveMemory", ^c(na%), ^b(0), s%*nb%
ENDPROC</lang>
ENDPROC</syntaxhighlight>


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
(Based on ZX Spectrum BASIC version)
(Based on ZX Spectrum BASIC version)
<lang basic>10 X=4 : Y=5
<syntaxhighlight lang=basic>10 X=4 : Y=5
20 DIM A(X) : DIM B(Y) : DIM C(X+Y)
20 DIM A(X) : DIM B(Y) : DIM C(X+Y)
30 FOR I=1 TO X
30 FOR I=1 TO X
Line 960: Line 960:
150 FOR I=1 TO X+Y
150 FOR I=1 TO X+Y
160 : PRINT C(I);
160 : PRINT C(I);
170 NEXT</lang>
170 NEXT</syntaxhighlight>


=={{header|BASIC256}}==
=={{header|BASIC256}}==
<lang basic256>arraybase 1
<syntaxhighlight lang=basic256>arraybase 1
global c
global c


Line 998: Line 998:


return nt
return nt
end function</lang>
end function</syntaxhighlight>
{{out}}
{{out}}
<pre>1, 2, 3, 4, 5, 6, 7, 8, 9, 10</pre>
<pre>1, 2, 3, 4, 5, 6, 7, 8, 9, 10</pre>
Line 1,004: Line 1,004:


=={{header|BQN}}==
=={{header|BQN}}==
<lang bqn>1‿2‿3 ∾ 4‿5‿6</lang>
<syntaxhighlight lang=bqn>1‿2‿3 ∾ 4‿5‿6</syntaxhighlight>


=={{header|Bracmat}}==
=={{header|Bracmat}}==
Line 1,028: Line 1,028:
=={{header|Burlesque}}==
=={{header|Burlesque}}==


<lang burlesque>
<syntaxhighlight lang=burlesque>
blsq ) {1 2 3}{4 5 6}_+
blsq ) {1 2 3}{4 5 6}_+
{1 2 3 4 5 6}
{1 2 3 4 5 6}
</syntaxhighlight>
</lang>


=={{header|C}}==
=={{header|C}}==
A way to concatenate two C arrays when you know their size (and usually so it is)
A way to concatenate two C arrays when you know their size (and usually so it is)
<lang c>#include <stdlib.h>
<syntaxhighlight lang=c>#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
Line 1,066: Line 1,066:
free(c);
free(c);
return EXIT_SUCCCESS;
return EXIT_SUCCCESS;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang=csharp>using System;


namespace RosettaCode
namespace RosettaCode
Line 1,090: Line 1,090:
}
}
}
}
}</lang>
}</syntaxhighlight>


Alternatively, using LINQ extension methods:
Alternatively, using LINQ extension methods:


{{works with|C sharp|C#|3}}
{{works with|C sharp|C#|3}}
<lang csharp>using System.Linq;
<syntaxhighlight lang=csharp>using System.Linq;


class Program
class Program
Line 1,106: Line 1,106:
int[] c = a.Concat(b).ToArray();
int[] c = a.Concat(b).ToArray();
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <vector>
<syntaxhighlight lang=cpp>#include <vector>
#include <iostream>
#include <iostream>


Line 1,122: Line 1,122:
for (int i = 0; i < a.size(); ++i)
for (int i = 0; i < a.size(); ++i)
std::cout << "a[" << i << "] = " << a[i] << "\n";
std::cout << "a[" << i << "] = " << a[i] << "\n";
}</lang>
}</syntaxhighlight>


{{works with|C++11}}
{{works with|C++11}}
Similar to above but using initialization schematics.
Similar to above but using initialization schematics.


<lang cpp>#include <vector>
<syntaxhighlight lang=cpp>#include <vector>
#include <iostream>
#include <iostream>


Line 1,139: Line 1,139:
std::cout << std::endl;
std::cout << std::endl;
return 0;
return 0;
}</lang>
}</syntaxhighlight>


This is another solution with function level templates and pointers.
This is another solution with function level templates and pointers.


<lang cpp>#include <iostream>
<syntaxhighlight lang=cpp>#include <iostream>


using namespace std;
using namespace std;
Line 1,192: Line 1,192:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|Ceylon}}==
=={{header|Ceylon}}==
<lang ceylon>shared void arrayConcatenation() {
<syntaxhighlight lang=ceylon>shared void arrayConcatenation() {
value a = Array {1, 2, 3};
value a = Array {1, 2, 3};
value b = Array {4, 5, 6};
value b = Array {4, 5, 6};
value c = concatenate(a, b);
value c = concatenate(a, b);
print(c);
print(c);
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(concat [1 2 3] [4 5 6])</lang>
<syntaxhighlight lang=clojure>(concat [1 2 3] [4 5 6])</syntaxhighlight>
The inputs can be any collection, including Java arrays, and returns a lazy sequence of the elements.
The inputs can be any collection, including Java arrays, and returns a lazy sequence of the elements.


A vector is the closest Clojure thing to an array. If a vector is wanted, then use
A vector is the closest Clojure thing to an array. If a vector is wanted, then use
<lang clojure>(into [1 2 3] [4 5 6])</lang>
<syntaxhighlight lang=clojure>(into [1 2 3] [4 5 6])</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
<lang COBOL> identification division.
<syntaxhighlight lang=COBOL> identification division.
program-id. array-concat.
program-id. array-concat.


Line 1,266: Line 1,266:
.
.


end program array-concat.</lang>
end program array-concat.</syntaxhighlight>
{{out}}
{{out}}
<pre>prompt$ cobc -xjd array-concatenation.cob
<pre>prompt$ cobc -xjd array-concatenation.cob
Line 1,273: Line 1,273:


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
<lang coffeescript>
<syntaxhighlight lang=coffeescript>
# like in JavaScript
# like in JavaScript
a = [1, 2, 3]
a = [1, 2, 3]
b = [4, 5, 6]
b = [4, 5, 6]
c = a.concat b
c = a.concat b
</syntaxhighlight>
</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<code>[http://www.lispworks.com/documentation/HyperSpec/Body/f_concat.htm concatenate]</code> is a general function for concatenating any type of sequence. It takes the type of sequence to produce, followed by any number of sequences of any type.
<code>[http://www.lispworks.com/documentation/HyperSpec/Body/f_concat.htm concatenate]</code> is a general function for concatenating any type of sequence. It takes the type of sequence to produce, followed by any number of sequences of any type.
<lang lisp>(concatenate 'vector #(0 1 2 3) #(4 5 6 7))
<syntaxhighlight lang=lisp>(concatenate 'vector #(0 1 2 3) #(4 5 6 7))
=> #(0 1 2 3 4 5 6 7)</lang>
=> #(0 1 2 3 4 5 6 7)</syntaxhighlight>
===Alternate solution===
===Alternate solution===
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]


<lang lisp>
<syntaxhighlight lang=lisp>
(setf arr1 (make-array '(3) :initial-contents '(1 2 3)))
(setf arr1 (make-array '(3) :initial-contents '(1 2 3)))
(setf arr2 (make-array '(3) :initial-contents '(4 5 6)))
(setf arr2 (make-array '(3) :initial-contents '(4 5 6)))
Line 1,301: Line 1,301:
(write arr5)
(write arr5)
(terpri)
(terpri)
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 1,310: Line 1,310:
=={{header|Component Pascal}}==
=={{header|Component Pascal}}==
BlackBox Component Builder
BlackBox Component Builder
<lang oberon2>
<syntaxhighlight lang=oberon2>
MODULE ArrayConcat;
MODULE ArrayConcat;
IMPORT StdLog;
IMPORT StdLog;
Line 1,366: Line 1,366:


END ArrayConcat.
END ArrayConcat.
</syntaxhighlight>
</lang>
Execute: ^Q ArrayConcat.Do <br/>
Execute: ^Q ArrayConcat.Do <br/>
{{out}}
{{out}}
Line 1,377: Line 1,377:


=={{header|Crystal}}==
=={{header|Crystal}}==
<lang ruby>arr1 = [1, 2, 3]
<syntaxhighlight lang=ruby>arr1 = [1, 2, 3]
arr2 = ["foo", "bar", "baz"]
arr2 = ["foo", "bar", "baz"]
arr1 + arr2 #=> [1, 2, 3, "foo", "bar", "baz"]</lang>
arr1 + arr2 #=> [1, 2, 3, "foo", "bar", "baz"]</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<lang d>import std.stdio: writeln;
<syntaxhighlight lang=d>import std.stdio: writeln;
void main() {
void main() {
Line 1,389: Line 1,389:
writeln(a, " ~ ", b, " = ", a ~ b);
writeln(a, " ~ ", b, " = ", a ~ b);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>[1, 2] ~ [4, 5, 6] = [1, 2, 4, 5, 6]</pre>
<pre>[1, 2] ~ [4, 5, 6] = [1, 2, 4, 5, 6]</pre>
Line 1,395: Line 1,395:
=={{header|Delphi}}==
=={{header|Delphi}}==
2022/07/13
2022/07/13
<lang delphi>
<syntaxhighlight lang=delphi>
// This example works on stuff as old as Delphi 5 (maybe older)
// This example works on stuff as old as Delphi 5 (maybe older)
// Modern Delphi / Object Pascal has both
// Modern Delphi / Object Pascal has both
Line 1,449: Line 1,449:
Writeln( #13#10, Join(names, #13#10 ) );
Writeln( #13#10, Join(names, #13#10 ) );
end.
end.
</syntaxhighlight>
</lang>
Output:
Output:
Korra Asami Bolin Mako
Korra Asami Bolin Mako
Line 1,467: Line 1,467:
It has running commentary about memory management that isn’t exactly correct.<br>
It has running commentary about memory management that isn’t exactly correct.<br>
Delphi handles dynamic array memory very well.
Delphi handles dynamic array memory very well.
<lang delphi>type
<syntaxhighlight lang=delphi>type
TReturnArray = array of integer; //you need to define a type to be able to return it
TReturnArray = array of integer; //you need to define a type to be able to return it


Line 1,504: Line 1,504:
Finalize(r1); //IMPORTANT!
Finalize(r1); //IMPORTANT!
ShowMessage(IntToStr(High(r1)));
ShowMessage(IntToStr(High(r1)));
end;</lang>
end;</syntaxhighlight>


=={{header|Diego}}==
=={{header|Diego}}==
<lang diego>set_namespace(rosettacode)_me();
<syntaxhighlight lang=diego>set_namespace(rosettacode)_me();


add_ary(a)_values(1,2,3);
add_ary(a)_values(1,2,3);
Line 1,515: Line 1,515:
me_msg()_calc([a]+[b]); // alternative
me_msg()_calc([a]+[b]); // alternative


reset_namespace[];</lang>
reset_namespace[];</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang dyalect>var xs = [1,2,3]
<syntaxhighlight lang=dyalect>var xs = [1,2,3]
var ys = [4,5,6]
var ys = [4,5,6]
var alls = Array.Concat(xs, ys)
var alls = Array.Concat(xs, ys)
print(alls)</lang>
print(alls)</syntaxhighlight>


{{out}}
{{out}}
Line 1,530: Line 1,530:
=={{header|E}}==
=={{header|E}}==


<lang e>? [1,2] + [3,4]
<syntaxhighlight lang=e>? [1,2] + [3,4]
# value: [1, 2, 3, 4]</lang>
# value: [1, 2, 3, 4]</syntaxhighlight>


=={{header|EasyLang}}==
=={{header|EasyLang}}==
Line 1,542: Line 1,542:
i += 1
i += 1
.
.
print c[]</lang>
print c[]</syntaxhighlight>


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
The native operators are '''append''' for lists, and '''vector-append''' for vectors (1-dim arrays).
The native operators are '''append''' for lists, and '''vector-append''' for vectors (1-dim arrays).
<lang scheme>
<syntaxhighlight lang=scheme>
;;;; VECTORS
;;;; VECTORS
(vector-append (make-vector 6 42) (make-vector 4 666))
(vector-append (make-vector 6 42) (make-vector 4 666))
Line 1,561: Line 1,561:




</syntaxhighlight>
</lang>


=={{header|ECL}}==
=={{header|ECL}}==
Line 1,569: Line 1,569:
B := [5, 6, 7, 8];
B := [5, 6, 7, 8];


C := A + B;</lang>
C := A + B;</syntaxhighlight>


=={{header|Efene}}==
=={{header|Efene}}==
Line 1,575: Line 1,575:
using the ++ operator and the lists.append function
using the ++ operator and the lists.append function


<lang efene>
<syntaxhighlight lang=efene>
@public
@public
run = fn () {
run = fn () {
Line 1,586: Line 1,586:
io.format("~p~n", [C])
io.format("~p~n", [C])
io.format("~p~n", [D])
io.format("~p~n", [D])
}</lang>
}</syntaxhighlight>


=={{header|EGL}}==
=={{header|EGL}}==
{{works with|EDT}}
{{works with|EDT}}
<lang EGL>
<syntaxhighlight lang=EGL>
program ArrayConcatenation
program ArrayConcatenation
function main()
function main()
Line 1,604: Line 1,604:
end
end
end
end
</syntaxhighlight>
</lang>


=={{header|Ela}}==
=={{header|Ela}}==
<lang ela>xs = [1,2,3]
<syntaxhighlight lang=ela>xs = [1,2,3]
ys = [4,5,6]
ys = [4,5,6]
xs ++ ys</lang>
xs ++ ys</syntaxhighlight>
{{out}}<pre>[1,2,3,4,5,6]</pre>
{{out}}<pre>[1,2,3,4,5,6]</pre>


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 5.0 :
ELENA 5.0 :
<lang elena>import extensions;
<syntaxhighlight lang=elena>import extensions;


public program()
public program()
Line 1,624: Line 1,624:
"(",a.asEnumerable(),") + (",b.asEnumerable(),
"(",a.asEnumerable(),") + (",b.asEnumerable(),
") = (",(a + b).asEnumerable(),")").readChar();
") = (",(a + b).asEnumerable(),")").readChar();
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,631: Line 1,631:


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>iex(1)> [1, 2, 3] ++ [4, 5, 6]
<syntaxhighlight lang=elixir>iex(1)> [1, 2, 3] ++ [4, 5, 6]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
iex(2)> Enum.concat([[1, [2], 3], [4], [5, 6]])
iex(2)> Enum.concat([[1, [2], 3], [4], [5, 6]])
[1, [2], 3, 4, 5, 6]
[1, [2], 3, 4, 5, 6]
iex(3)> Enum.concat([1..3, [4,5,6], 7..9])
iex(3)> Enum.concat([1..3, [4,5,6], 7..9])
[1, 2, 3, 4, 5, 6, 7, 8, 9]</lang>
[1, 2, 3, 4, 5, 6, 7, 8, 9]</syntaxhighlight>


=={{header|Elm}}==
=={{header|Elm}}==
<lang elm>import Element exposing (show, toHtml) -- elm-package install evancz/elm-graphics
<syntaxhighlight lang=elm>import Element exposing (show, toHtml) -- elm-package install evancz/elm-graphics
import Html.App exposing (beginnerProgram)
import Html.App exposing (beginnerProgram)
import Array exposing (Array, append, initialize)
import Array exposing (Array, append, initialize)
Line 1,657: Line 1,657:
}
}


-- Array.fromList [0,1,2,3,4,5]</lang>
-- Array.fromList [0,1,2,3,4,5]</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
The ''vconcat'' function returns a new array containing all the elements of it's arguments.
The ''vconcat'' function returns a new array containing all the elements of it's arguments.


<lang lisp>(vconcat '[1 2 3] '[4 5] '[6 7 8 9])
<syntaxhighlight lang=lisp>(vconcat '[1 2 3] '[4 5] '[6 7 8 9])
=> [1 2 3 4 5 6 7 8 9]</lang>
=> [1 2 3 4 5 6 7 8 9]</syntaxhighlight>


=={{header|Erlang}}==
=={{header|Erlang}}==
Line 1,670: Line 1,670:


On the shell,
On the shell,
<lang erlang>
<syntaxhighlight lang=erlang>
1> [1, 2, 3] ++ [4, 5, 6].
1> [1, 2, 3] ++ [4, 5, 6].
[1,2,3,4,5,6]
[1,2,3,4,5,6]
Line 1,676: Line 1,676:
[1,2,3,4,5,6]
[1,2,3,4,5,6]
3>
3>
</syntaxhighlight>
</lang>


=={{header|ERRE}}==
=={{header|ERRE}}==
Line 1,711: Line 1,711:


END PROGRAM
END PROGRAM
</syntaxhighlight>
</lang>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<lang Euphoria>sequence s1,s2,s3
<syntaxhighlight lang=Euphoria>sequence s1,s2,s3
s1 = {1,2,3}
s1 = {1,2,3}
s2 = {4,5,6}
s2 = {4,5,6}
s3 = s1 & s2
s3 = s1 & s2
? s3</lang>
? s3</syntaxhighlight>


{{out}}
{{out}}
Line 1,725: Line 1,725:
=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
Array concatenation.
Array concatenation.
<lang fsharp>let a = [|1; 2; 3|]
<syntaxhighlight lang=fsharp>let a = [|1; 2; 3|]
let b = [|4; 5; 6;|]
let b = [|4; 5; 6;|]
let c = Array.append a b</lang>
let c = Array.append a b</syntaxhighlight>
List concatenation (@ and List.append are equivalent).
List concatenation (@ and List.append are equivalent).
<lang fsharp>let x = [1; 2; 3]
<syntaxhighlight lang=fsharp>let x = [1; 2; 3]
let y = [4; 5; 6]
let y = [4; 5; 6]
let z1 = x @ y
let z1 = x @ y
let z2 = List.append x y</lang>
let z2 = List.append x y</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>append</lang>
<syntaxhighlight lang=factor>append</syntaxhighlight>


'''Example''':
'''Example''':
<lang factor>( scratchpad ) USE: sequences
<syntaxhighlight lang=factor>( scratchpad ) USE: sequences
( scratchpad ) { 1 2 } { 3 4 } append .
( scratchpad ) { 1 2 } { 3 4 } append .
{ 1 2 3 4 }</lang>
{ 1 2 3 4 }</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==
Line 1,746: Line 1,746:
In fansh:
In fansh:


<lang fantom>
<syntaxhighlight lang=fantom>
> a := [1,2,3]
> a := [1,2,3]
> b := [4,5,6]
> b := [4,5,6]
Line 1,752: Line 1,752:
> a
> a
[1,2,3,4,5,6]
[1,2,3,4,5,6]
</syntaxhighlight>
</lang>


Note 'addAll' is destructive. Write 'a.dup.addAll(b)' to create a fresh list.
Note 'addAll' is destructive. Write 'a.dup.addAll(b)' to create a fresh list.
Line 1,758: Line 1,758:
=={{header|FBSL}}==
=={{header|FBSL}}==
Array concatenation:
Array concatenation:
<lang qbasic>#APPTYPE CONSOLE
<syntaxhighlight lang=qbasic>#APPTYPE CONSOLE


DIM aint[] ={1, 2, 3}, astr[] ={"one", "two", "three"}, asng[] ={!1, !2, !3}
DIM aint[] ={1, 2, 3}, astr[] ={"one", "two", "three"}, asng[] ={!1, !2, !3}
Line 1,766: Line 1,766:
NEXT
NEXT


PAUSE</lang>
PAUSE</syntaxhighlight>
{{out}}
{{out}}
<pre>1 2 3 one two three 1.000000 2.000000 3.000000
<pre>1 2 3 one two three 1.000000 2.000000 3.000000
Line 1,772: Line 1,772:


=={{header|Forth}}==
=={{header|Forth}}==
<lang Forth>: $!+ ( a u a' -- a'+u )
<syntaxhighlight lang=Forth>: $!+ ( a u a' -- a'+u )
2dup + >r swap move r> ;
2dup + >r swap move r> ;
: cat ( a2 u2 a1 u1 -- a3 u1+u2 )
: cat ( a2 u2 a1 u1 -- a3 u1+u2 )
Line 1,785: Line 1,785:
801842600: 03 00 00 00 00 00 00 00 - 04 00 00 00 00 00 00 00 ................
801842600: 03 00 00 00 00 00 00 00 - 04 00 00 00 00 00 00 00 ................
801842610: 05 00 00 00 00 00 00 00 - ........
801842610: 05 00 00 00 00 00 00 00 - ........
</syntaxhighlight>
</lang>


=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
{{works with|Fortran|90 and later}}
<lang fortran>program Concat_Arrays
<syntaxhighlight lang=fortran>program Concat_Arrays
implicit none
implicit none


Line 1,805: Line 1,805:
d = [a, b] ! (/a, b/)
d = [a, b] ! (/a, b/)
print*, d
print*, d
end program Concat_Arrays</lang>
end program Concat_Arrays</syntaxhighlight>


=={{header|Free Pascal}}==
=={{header|Free Pascal}}==
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>).
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>).
<lang pascal> array2 := array0 + array1</lang>
<syntaxhighlight lang=pascal> array2 := array0 + array1</syntaxhighlight>
Alternatively, one could use <code>concat()</code> which is independent of above modeswitch and mode:
Alternatively, one could use <code>concat()</code> which is independent of above modeswitch and mode:
<lang pascal> array2 := concat(array0, array1);</lang>
<syntaxhighlight lang=pascal> array2 := concat(array0, array1);</syntaxhighlight>
Both options do not require any libraries.
Both options do not require any libraries.


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>
<syntaxhighlight lang=freebasic>
' FB 1.05.0 Win64
' FB 1.05.0 Win64


Line 1,842: Line 1,842:
Print "Press any key to quit the program"
Print "Press any key to quit the program"
Sleep
Sleep
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,850: Line 1,850:


=={{header|Frink}}==
=={{header|Frink}}==
<lang frink>
<syntaxhighlight lang=frink>
a = [1,2]
a = [1,2]
b = [3,4]
b = [3,4]
a.pushAll[b]
a.pushAll[b]
</syntaxhighlight>
</lang>


=={{header|FunL}}==
=={{header|FunL}}==
<lang funl>arr1 = array( [1, 2, 3] )
<syntaxhighlight lang=funl>arr1 = array( [1, 2, 3] )
arr2 = array( [4, 5, 6] )
arr2 = array( [4, 5, 6] )
arr3 = array( [7, 8, 9] )
arr3 = array( [7, 8, 9] )


println( arr1 + arr2 + arr3 )</lang>
println( arr1 + arr2 + arr3 )</syntaxhighlight>


{{out}}
{{out}}
Line 1,873: Line 1,873:
Array concatenation is done with the built-in function <code>concat</code>, which can take any number of arguments:
Array concatenation is done with the built-in function <code>concat</code>, which can take any number of arguments:


<lang Futhark>
<syntaxhighlight lang=Futhark>
concat as bs cd
concat as bs cd
</syntaxhighlight>
</lang>


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==


<lang FutureBasic>void local fn DoIt
<syntaxhighlight lang=FutureBasic>void local fn DoIt
CFArrayRef array = @[@"Alpha",@"Bravo",@"Charlie"]
CFArrayRef array = @[@"Alpha",@"Bravo",@"Charlie"]
print array
print array
Line 1,891: Line 1,891:
fn DoIt
fn DoIt


HandleEvents</lang>
HandleEvents</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 1,911: Line 1,911:
=={{header|Gambas}}==
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=314bea6fba7f177a1cfaec8a7a8b5ccb Click this link to run this code]'''
'''[https://gambas-playground.proko.eu/?gist=314bea6fba7f177a1cfaec8a7a8b5ccb Click this link to run this code]'''
<lang gambas>Public Sub Main()
<syntaxhighlight lang=gambas>Public Sub Main()
Dim sString1 As String[] = ["The", "quick", "brown", "fox"]
Dim sString1 As String[] = ["The", "quick", "brown", "fox"]
Dim sString2 As String[] = ["jumped", "over", "the", "lazy", "dog"]
Dim sString2 As String[] = ["jumped", "over", "the", "lazy", "dog"]
Line 1,919: Line 1,919:
Print sString1.Join(" ")
Print sString1.Join(" ")


End</lang>
End</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 1,926: Line 1,926:


=={{header|GAP}}==
=={{header|GAP}}==
<lang gap># Concatenate arrays
<syntaxhighlight lang=gap># Concatenate arrays
Concatenation([1, 2, 3], [4, 5, 6], [7, 8, 9]);
Concatenation([1, 2, 3], [4, 5, 6], [7, 8, 9]);
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
Line 1,935: Line 1,935:
Append(a, [7, 8, 9]);
Append(a, [7, 8, 9]);
a;
a;
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]</lang>
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]</syntaxhighlight>


=={{header|Genie}}==
=={{header|Genie}}==
<lang genie>[indent=4]
<syntaxhighlight lang=genie>[indent=4]
/*
/*
Array concatenation, in Genie
Array concatenation, in Genie
Line 1,965: Line 1,965:
stdout.printf("y: "); int_show_array(y)
stdout.printf("y: "); int_show_array(y)
stdout.printf("z: "); int_show_array(z)
stdout.printf("z: "); int_show_array(z)
print "%d elements in new array", z.length</lang>
print "%d elements in new array", z.length</syntaxhighlight>


{{out}}
{{out}}
Line 1,977: Line 1,977:
=={{header|GLSL}}==
=={{header|GLSL}}==
This macro concatenates two arrays to form a new array. The first parameter is the type of the array:
This macro concatenates two arrays to form a new array. The first parameter is the type of the array:
<lang glsl>
<syntaxhighlight lang=glsl>
#define array_concat(T,a1,a2,returned) \
#define array_concat(T,a1,a2,returned) \
T[a1.length()+a2.length()] returned; \
T[a1.length()+a2.length()] returned; \
Line 1,988: Line 1,988:
} \
} \
}
}
</syntaxhighlight>
</lang>
The macro can be used like this:
The macro can be used like this:
<lang glsl>
<syntaxhighlight lang=glsl>
array_concat(float,float[](1.,2.,3.),float[](4.,5.,6.),returned);
array_concat(float,float[](1.,2.,3.),float[](4.,5.,6.),returned);
int i = returned.length();
int i = returned.length();
</syntaxhighlight>
</lang>


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang=go>package main


import "fmt"
import "fmt"
Line 2,030: Line 2,030:
fmt.Println(n)
fmt.Println(n)


}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,038: Line 2,038:
</pre>
</pre>
Array concatenation needs can vary. Here is another set of examples that illustrate different techniques.
Array concatenation needs can vary. Here is another set of examples that illustrate different techniques.
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 2,094: Line 2,094:
test2_c := ArrayConcat(test2_a, test2_b).([]string)
test2_c := ArrayConcat(test2_a, test2_b).([]string)
fmt.Println(test2_a, " + ", test2_b, " = ", test2_c)
fmt.Println(test2_a, " + ", test2_b, " = ", test2_c)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,103: Line 2,103:
=={{header|Gosu}}==
=={{header|Gosu}}==


<lang gosu>
<syntaxhighlight lang=gosu>
var listA = { 1, 2, 3 }
var listA = { 1, 2, 3 }
var listB = { 4, 5, 6 }
var listB = { 4, 5, 6 }
Line 2,110: Line 2,110:


print( listC ) // prints [1, 2, 3, 4, 5, 6]
print( listC ) // prints [1, 2, 3, 4, 5, 6]
</syntaxhighlight>
</lang>


=={{header|Groovy}}==
=={{header|Groovy}}==
Solution:
Solution:
<lang groovy>def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"]</lang>
<syntaxhighlight lang=groovy>def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"]</syntaxhighlight>


Test:
Test:
<lang groovy>println list</lang>
<syntaxhighlight lang=groovy>println list</syntaxhighlight>


{{out}}
{{out}}
Line 2,124: Line 2,124:
=={{header|Haskell}}==
=={{header|Haskell}}==
A list is in Haskell one of the most common composite data types (constructed from other types). In the documentation we read for the append operation ++:
A list is in Haskell one of the most common composite data types (constructed from other types). In the documentation we read for the append operation ++:
<lang haskell>(++) :: [a] -> [a] -> [a]</lang>
<syntaxhighlight lang=haskell>(++) :: [a] -> [a] -> [a]</syntaxhighlight>
Append two lists, i.e.:<pre>
Append two lists, i.e.:<pre>
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
Line 2,131: Line 2,131:


This operator could be defined from the scratch using explicit recursion:
This operator could be defined from the scratch using explicit recursion:
<lang haskell>
<syntaxhighlight lang=haskell>
[] ++ x = x
[] ++ x = x
(h:t) ++ y = h : (t ++ y)
(h:t) ++ y = h : (t ++ y)
</syntaxhighlight>
</lang>
or folding
or folding
<lang haskell>
<syntaxhighlight lang=haskell>
x ++ y = foldr (:) y x
x ++ y = foldr (:) y x
</syntaxhighlight>
</lang>


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang HicEst>REAL :: a(7), b(3), c(10)
<syntaxhighlight lang=HicEst>REAL :: a(7), b(3), c(10)


c = a
c = a
DO i = 1, LEN(b)
DO i = 1, LEN(b)
c(i + LEN(a)) = b(i)
c(i + LEN(a)) = b(i)
ENDDO</lang>
ENDDO</syntaxhighlight>


=={{header|Hy}}==
=={{header|Hy}}==
<lang hy>=> (setv a [1 2 3])
<syntaxhighlight lang=hy>=> (setv a [1 2 3])
=> a
=> a
[1, 2, 3]
[1, 2, 3]
Line 2,163: Line 2,163:


=> (+ [1 2] [3 4] [5 6]) ; can accept multiple arguments
=> (+ [1 2] [3 4] [5 6]) ; can accept multiple arguments
[1, 2, 3, 4, 5, 6]</lang>
[1, 2, 3, 4, 5, 6]</syntaxhighlight>


=={{header|i}}==
=={{header|i}}==
<lang i>main
<syntaxhighlight lang=i>main
a $= [1, 2, 3]
a $= [1, 2, 3]
b $= [4, 5, 6]
b $= [4, 5, 6]
print(a + b)
print(a + b)
}</lang>
}</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Both languages have list concatenation built in. Lists are fully dynamic arrays which can be truncated or extended at either end.
Both languages have list concatenation built in. Lists are fully dynamic arrays which can be truncated or extended at either end.
<lang icon>
<syntaxhighlight lang=icon>
procedure main()
procedure main()
L1 := [1, 2, 3, 4]
L1 := [1, 2, 3, 4]
Line 2,186: Line 2,186:
write()
write()
end
end
</syntaxhighlight>
</lang>


=={{header|IDL}}==
=={{header|IDL}}==


Array concatenation can mean different things, depending on the number of dimensions of the arguments and the result. In the simplest case, with 1-dimensional arrays to begin with, there are two obvious ways to concatenate them. If my arrays are these:
Array concatenation can mean different things, depending on the number of dimensions of the arguments and the result. In the simplest case, with 1-dimensional arrays to begin with, there are two obvious ways to concatenate them. If my arrays are these:
<lang IDL>
<syntaxhighlight lang=IDL>
> a = [1,2,3]
> a = [1,2,3]
> b = [4,5,6]
> b = [4,5,6]
Line 2,202: Line 2,202:
> print,b
> print,b
4 5 6
4 5 6
</syntaxhighlight>
</lang>
Then they can be concatenated "at the ends":
Then they can be concatenated "at the ends":
<lang IDL>
<syntaxhighlight lang=IDL>
> help,[a,b]
> help,[a,b]
<Expression> INT = Array[6]
<Expression> INT = Array[6]
> print,[a,b]
> print,[a,b]
1 2 3 4 5 6
1 2 3 4 5 6
</syntaxhighlight>
</lang>
or "at the sides":
or "at the sides":
<lang IDL>
<syntaxhighlight lang=IDL>
> help,[[a],[b]]
> help,[[a],[b]]
<Expression> INT = Array[3, 2]
<Expression> INT = Array[3, 2]
Line 2,217: Line 2,217:
1 2 3
1 2 3
4 5 6
4 5 6
</syntaxhighlight>
</lang>
Note that this requires that the arrays have the same size at the side at which they are concatenated:
Note that this requires that the arrays have the same size at the side at which they are concatenated:
<lang IDL>
<syntaxhighlight lang=IDL>
> b = transpose(b)
> b = transpose(b)
> help,b
> help,b
Line 2,233: Line 2,233:
Unable to concatenate variables because the dimensions do not agree: B.
Unable to concatenate variables because the dimensions do not agree: B.
Execution halted at: $MAIN$
Execution halted at: $MAIN$
</syntaxhighlight>
</lang>
This can get a lot more complicated as a 3x4x5-element three-dimensional array can be concatenated with a 5x2x3-element array at exactly two "surfaces".
This can get a lot more complicated as a 3x4x5-element three-dimensional array can be concatenated with a 5x2x3-element array at exactly two "surfaces".


Line 2,245: Line 2,245:


=={{header|Inform 7}}==
=={{header|Inform 7}}==
<lang inform7>let A be {1, 2, 3};
<syntaxhighlight lang=inform7>let A be {1, 2, 3};
let B be {4, 5, 6};
let B be {4, 5, 6};
add B to A;</lang>
add B to A;</syntaxhighlight>


=={{header|Ioke}}==
=={{header|Ioke}}==
<lang ioke>iik> [1,2,3] + [3,2,1]
<syntaxhighlight lang=ioke>iik> [1,2,3] + [3,2,1]
[1,2,3] + [3,2,1]
[1,2,3] + [3,2,1]
+> [1, 2, 3, 3, 2, 1]</lang>
+> [1, 2, 3, 3, 2, 1]</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
Line 2,258: Line 2,258:


'''Example''':
'''Example''':
<lang j> array1 =: 1 2 3
<syntaxhighlight lang=j> array1 =: 1 2 3
array2 =: 4 5 6
array2 =: 4 5 6
array1 , array2
array1 , array2
1 2 3 4 5 6</lang>
1 2 3 4 5 6</syntaxhighlight>


Of course, in J, array concatenation works (consistently) on arrays of any rank or dimension.
Of course, in J, array concatenation works (consistently) on arrays of any rank or dimension.
Line 2,267: Line 2,267:
The verb <code>,</code> concatenates by treating the argument array with the largest number of dimensions as a list. Other primary verbs concatenate along other axes.
The verb <code>,</code> concatenates by treating the argument array with the largest number of dimensions as a list. Other primary verbs concatenate along other axes.


<lang j> ]ab=: 3 3 $ 'aaabbbccc'
<syntaxhighlight lang=j> ]ab=: 3 3 $ 'aaabbbccc'
aaa
aaa
bbb
bbb
Line 2,299: Line 2,299:
3 6
3 6
$ ab ,: wx NB. applies to new (higher) axis
$ ab ,: wx NB. applies to new (higher) axis
2 3 3</lang>
2 3 3</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang java5>public static Object[] concat(Object[] arr1, Object[] arr2) {
<syntaxhighlight lang=java5>public static Object[] concat(Object[] arr1, Object[] arr2) {
Object[] res = new Object[arr1.length + arr2.length];
Object[] res = new Object[arr1.length + arr2.length];


Line 2,309: Line 2,309:


return res;
return res;
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
The <code>Array.concat()</code> method returns a new array comprised of this array joined with other array(s) and/or value(s).
The <code>Array.concat()</code> method returns a new array comprised of this array joined with other array(s) and/or value(s).
<lang javascript>var a = [1,2,3],
<syntaxhighlight lang=javascript>var a = [1,2,3],
b = [4,5,6],
b = [4,5,6],
c = a.concat(b); //=> [1,2,3,4,5,6]</lang>
c = a.concat(b); //=> [1,2,3,4,5,6]</syntaxhighlight>




Line 2,323: Line 2,323:
See, for a function with an analogous type signature, '''concat''' in the Haskell Prelude.
See, for a function with an analogous type signature, '''concat''' in the Haskell Prelude.


<lang javascript>(function () {
<syntaxhighlight lang=javascript>(function () {
'use strict';
'use strict';


Line 2,338: Line 2,338:
);
);


})();</lang>
})();</syntaxhighlight>


{{Out}}
{{Out}}
Line 2,350: Line 2,350:
To concatenate the component arrays of an array, A, the <tt>add</tt> filter can be used: <tt>A|add</tt>
To concatenate the component arrays of an array, A, the <tt>add</tt> filter can be used: <tt>A|add</tt>


jq also supports streams, which are somewhat array-like, so it may be worth mentioning that the concatenation of two or more streams can be accomplished using "," instead of "+". <lang jq>[1,2] + [3] + [null] # => [1,2,3,null]
jq also supports streams, which are somewhat array-like, so it may be worth mentioning that the concatenation of two or more streams can be accomplished using "," instead of "+". <syntaxhighlight lang=jq>[1,2] + [3] + [null] # => [1,2,3,null]


[range(1;3), 3, null] # => [1,2,3,null]
[range(1;3), 3, null] # => [1,2,3,null]
</syntaxhighlight>
</lang>


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>a = [1,2,3]
<syntaxhighlight lang=julia>a = [1,2,3]
b = [4,5,6]
b = [4,5,6]
ab = [a;b]
ab = [a;b]
Line 2,364: Line 2,364:
ab = hcat(a,b) #ab -> 3x2 matrix
ab = hcat(a,b) #ab -> 3x2 matrix
# the append!(a,b) method is mutating, appending `b` to `a`
# the append!(a,b) method is mutating, appending `b` to `a`
append!(a,b) # a now equals [1,2,3,4,5,6]</lang>
append!(a,b) # a now equals [1,2,3,4,5,6]</syntaxhighlight>


=={{header|K}}==
=={{header|K}}==
<syntaxhighlight lang=K>
<lang K>
a: 1 2 3
a: 1 2 3
b: 4 5 6
b: 4 5 6
a,b
a,b
1 2 3 4 5 6</lang>
1 2 3 4 5 6</syntaxhighlight>


Concatenations on larger dimensions also use ",", often combined with other operations.
Concatenations on larger dimensions also use ",", often combined with other operations.


<syntaxhighlight lang=K>
<lang K>
ab:3 3#"abcdefghi"
ab:3 3#"abcdefghi"
("abc"
("abc"
Line 2,407: Line 2,407:
("abc036"
("abc036"
"def147"
"def147"
"ghi258")</lang>
"ghi258")</syntaxhighlight>


=={{header|Klingphix}}==
=={{header|Klingphix}}==
<lang Klingphix>include ..\Utilitys.tlhy
<syntaxhighlight lang=Klingphix>include ..\Utilitys.tlhy


( 1.0 "Hello" 3 2 / 4 2.1 power ) ( 5 6 7 8 ) chain print
( 1.0 "Hello" 3 2 / 4 2.1 power ) ( 5 6 7 8 ) chain print


" " input</lang>
" " input</syntaxhighlight>
{{out}}
{{out}}
<pre>(1, "Hello", 1.5, 18.379173679952562, 5, 6, 7, 8)</pre>
<pre>(1, "Hello", 1.5, 18.379173679952562, 5, 6, 7, 8)</pre>


=={{header|Klong}}==
=={{header|Klong}}==
<syntaxhighlight lang=K>
<lang K>
[1 2 3],[4 5 6] :" join "
[1 2 3],[4 5 6] :" join "
[1 2 3 4 5 6]
[1 2 3 4 5 6]
Line 2,428: Line 2,428:
[1 2],:/[[3 4] [5 6] [7 8]] :" join each-right "
[1 2],:/[[3 4] [5 6] [7 8]] :" join each-right "
[[3 4 1 2] [5 6 1 2] [7 8 1 2]]
[[3 4 1 2] [5 6 1 2] [7 8 1 2]]
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
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:
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:
<lang kotlin>fun main(args: Array<String>) {
<syntaxhighlight lang=kotlin>fun main(args: Array<String>) {
val a: Array<Int> = arrayOf(1, 2, 3) // initialise a
val a: Array<Int> = arrayOf(1, 2, 3) // initialise a
val b: Array<Int> = arrayOf(4, 5, 6) // initialise b
val b: Array<Int> = arrayOf(4, 5, 6) // initialise b
val c: Array<Int> = (a.toList() + b.toList()).toTypedArray()
val c: Array<Int> = (a.toList() + b.toList()).toTypedArray()
println(c)
println(c)
}</lang>
}</syntaxhighlight>


Alternatively, we can write our own concatenation function:
Alternatively, we can write our own concatenation function:
<lang kotlin>fun arrayConcat(a: Array<Any>, b: Array<Any>): Array<Any> {
<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] })
return Array(a.size + b.size, { if (it in a.indices) a[it] else b[it - a.size] })
}</lang>
}</syntaxhighlight>


When working directly with <code>Collection</code>s, we can simply use the <code>+</code> operator:
When working directly with <code>Collection</code>s, we can simply use the <code>+</code> operator:
<lang kotlin>fun main(args: Array<String>) {
<syntaxhighlight lang=kotlin>fun main(args: Array<String>) {
val a: Collection<Int> = listOf(1, 2, 3) // initialise a
val a: Collection<Int> = listOf(1, 2, 3) // initialise a
val b: Collection<Int> = listOf(4, 5, 6) // initialise b
val b: Collection<Int> = listOf(4, 5, 6) // initialise b
val c: Collection<Int> = a + b
val c: Collection<Int> = a + b
println(c)
println(c)
}</lang>
}</syntaxhighlight>


=={{header|LabVIEW}}==
=={{header|LabVIEW}}==
Line 2,457: Line 2,457:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang=scheme>
{def A {A.new 1 2 3 4 5 6}} -> [1,2,3,4,5,6]
{def A {A.new 1 2 3 4 5 6}} -> [1,2,3,4,5,6]
{def B {A.new 7 8 9}} -> [7,8,9]
{def B {A.new 7 8 9}} -> [7,8,9]
{A.concat {A} {B}} -> [1,2,3,4,5,6,7,8,9]
{A.concat {A} {B}} -> [1,2,3,4,5,6,7,8,9]
</syntaxhighlight>
</lang>


=={{header|Lang5}}==
=={{header|Lang5}}==
<lang Lang5>[1 2] [3 4] append collapse .</lang>
<syntaxhighlight lang=Lang5>[1 2] [3 4] append collapse .</syntaxhighlight>


=={{header|langur}}==
=={{header|langur}}==
<lang langur>val .a = [1, 2, 3]
<syntaxhighlight lang=langur>val .a = [1, 2, 3]
val .b = [7, 8, 9]
val .b = [7, 8, 9]
val .c = .a ~ .b
val .c = .a ~ .b
writeln .c</lang>
writeln .c</syntaxhighlight>


{{out}}
{{out}}
Line 2,476: Line 2,476:


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>
<syntaxhighlight lang=Lasso>
local(arr1 = array(1, 2, 3))
local(arr1 = array(1, 2, 3))
local(arr2 = array(4, 5, 6))
local(arr2 = array(4, 5, 6))
Line 2,488: Line 2,488:
arr2 = array(4, 5, 6)
arr2 = array(4, 5, 6)
arr3 = array(4, 5, 6)
arr3 = array(4, 5, 6)
arr3 = array(1, 2, 3, 4, 5, 6)</lang>
arr3 = array(1, 2, 3, 4, 5, 6)</syntaxhighlight>


=={{header|LFE}}==
=={{header|LFE}}==
<lang lisp>
<syntaxhighlight lang=lisp>
> (++ '(1 2 3) '(4 5 6))
> (++ '(1 2 3) '(4 5 6))
(1 2 3 4 5 6)
(1 2 3 4 5 6)
> (: lists append '(1 2 3) '(4 5 6))
> (: lists append '(1 2 3) '(4 5 6))
(1 2 3 4 5 6)
(1 2 3 4 5 6)
</syntaxhighlight>
</lang>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<lang lb> x=10
<syntaxhighlight lang=lb> x=10
y=20
y=20
dim array1(x)
dim array1(x)
Line 2,516: Line 2,516:
for i = 1 to x + y
for i = 1 to x + y
print array3(i)
print array3(i)
next</lang>
next</syntaxhighlight>


=={{header|LIL}}==
=={{header|LIL}}==
LIL uses lists instead of arrays. The builtin '''append''' command could be used as '''append a $b'''. That would add the entire list in variable '''b''' as one item to list '''a'''. Below '''quote''' is used to flatten the lists into a single new list of all items.
LIL uses lists instead of arrays. The builtin '''append''' command could be used as '''append a $b'''. That would add the entire list in variable '''b''' as one item to list '''a'''. Below '''quote''' is used to flatten the lists into a single new list of all items.


<lang tcl>##
<syntaxhighlight lang=tcl>##
Array concatenation in LIL
Array concatenation in LIL
##
##
Line 2,529: Line 2,529:


print $c
print $c
print "[index $c 0] [index $c 3]"</lang>
print "[index $c 0] [index $c 3]"</syntaxhighlight>


{{out}}
{{out}}
Line 2,537: Line 2,537:


=={{header|Limbo}}==
=={{header|Limbo}}==
<lang limbo>implement Command;
<syntaxhighlight lang=limbo>implement Command;


include "sys.m";
include "sys.m";
Line 2,559: Line 2,559:
for (i := 0; i < len c; i++)
for (i := 0; i < len c; i++)
sys->print("%d\n", c[i]);
sys->print("%d\n", c[i]);
}</lang>
}</syntaxhighlight>


=={{header|Lingo}}==
=={{header|Lingo}}==
<lang lingo>a = [1,2]
<syntaxhighlight lang=lingo>a = [1,2]
b = [3,4,5]
b = [3,4,5]


Line 2,570: Line 2,570:


put a
put a
-- [1, 2, 3, 4, 5]</lang>
-- [1, 2, 3, 4, 5]</syntaxhighlight>


=={{header|Little}}==
=={{header|Little}}==
<lang C>void main() {
<syntaxhighlight lang=C>void main() {
int a[] = {0, 1, 2, 3, 4};
int a[] = {0, 1, 2, 3, 4};
int b[] = {5, 6, 7, 8, 9};
int b[] = {5, 6, 7, 8, 9};
int c[] = {(expand)a, (expand)b};
int c[] = {(expand)a, (expand)b};
puts(c);
puts(c);
}</lang>
}</syntaxhighlight>


=={{header|Logo}}==
=={{header|Logo}}==
COMBINE is used to combine lists or words. SENTENCE is used to combine lists and words into a single list.
COMBINE is used to combine lists or words. SENTENCE is used to combine lists and words into a single list.
<lang logo>
<syntaxhighlight lang=logo>
to combine-arrays :a1 :a2
to combine-arrays :a1 :a2
output listtoarray sentence arraytolist :a1 arraytolist :a2
output listtoarray sentence arraytolist :a1 arraytolist :a2
end
end
show combine-arrays {1 2 3} {4 5 6} ; {1 2 3 4 5 6}
show combine-arrays {1 2 3} {4 5 6} ; {1 2 3 4 5 6}
</syntaxhighlight>
</lang>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>a = {1, 2, 3}
<syntaxhighlight lang=lua>a = {1, 2, 3}
b = {4, 5, 6}
b = {4, 5, 6}


Line 2,597: Line 2,597:
end
end


print(table.concat(a, ", "))</lang>
print(table.concat(a, ", "))</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,604: Line 2,604:


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
<syntaxhighlight lang=M2000 Interpreter>
a=(1,2,3,4,5)
a=(1,2,3,4,5)
b=Cons(a, (6,7,8),a)
b=Cons(a, (6,7,8),a)
Print b
Print b
1 2 3 4 5 6 7 8 1 2 3 4 5
1 2 3 4 5 6 7 8 1 2 3 4 5
</syntaxhighlight>
</lang>


Adding 2 dimension arrays
Adding 2 dimension arrays


<lang M2000 Interpreter>
<syntaxhighlight lang=M2000 Interpreter>
Dim Base 0, A(2,2)=1, B(1,2)=6
Dim Base 0, A(2,2)=1, B(1,2)=6
A()=Cons(A(), B(), A(), B())
A()=Cons(A(), B(), A(), B())
Line 2,624: Line 2,624:
Print
Print
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,637: Line 2,637:
=={{header|Maple}}==
=={{header|Maple}}==
There is a built-in procedure for concatenating arrays (and similar objects such as matrices or vectors). Arrays can be concatenated along any given dimension, which is specified as the first argument.
There is a built-in procedure for concatenating arrays (and similar objects such as matrices or vectors). Arrays can be concatenated along any given dimension, which is specified as the first argument.
<lang Maple>
<syntaxhighlight lang=Maple>
> A := Array( [ 1, 2, 3 ] );
> A := Array( [ 1, 2, 3 ] );
A := [1, 2, 3]
A := [1, 2, 3]
Line 2,663: Line 2,663:
[ ]
[ ]
[1 2 3]
[1 2 3]
</syntaxhighlight>
</lang>
Of course, the order of the arguments is important.
Of course, the order of the arguments is important.
<lang Maple>
<syntaxhighlight lang=Maple>
> ArrayTools:-Concatenate( 1, A, M );
> ArrayTools:-Concatenate( 1, A, M );
[1 2 3]
[1 2 3]
Line 2,672: Line 2,672:
[ ]
[ ]
[d e f]
[d e f]
</syntaxhighlight>
</lang>
Lists, in Maple, might be considered to be a kind of "array" (in the sense that they look like arrays in memory), though they are actually immutable objects. However, they can be concatenated as follows.
Lists, in Maple, might be considered to be a kind of "array" (in the sense that they look like arrays in memory), though they are actually immutable objects. However, they can be concatenated as follows.
<lang Maple>
<syntaxhighlight lang=Maple>
> L1 := [ 1, 2, 3 ];
> L1 := [ 1, 2, 3 ];
L1 := [1, 2, 3]
L1 := [1, 2, 3]
Line 2,686: Line 2,686:
> [ L1[], L2[] ]; # equivalent, just different syntax
> [ L1[], L2[] ]; # equivalent, just different syntax
[1, 2, 3, a, b, c]
[1, 2, 3, a, b, c]
</syntaxhighlight>
</lang>


=={{header|Mathcad}}==
=={{header|Mathcad}}==
Line 2,702: Line 2,702:
augment concatenates arrays column-wise. The two (or more) arrays must have the same number of rows, and the resulting array column count is equal to the total number of columns in the augmented arrays.
augment concatenates arrays column-wise. The two (or more) arrays must have the same number of rows, and the resulting array column count is equal to the total number of columns in the augmented arrays.


<lang Mathcad>
<syntaxhighlight lang=Mathcad>
create a pair of arbitrary array:
create a pair of arbitrary array:
a:=matrix(2,2,max) b:=a+3
a:=matrix(2,2,max) b:=a+3
Line 2,718: Line 2,718:
|1 1 3 4|
|1 1 3 4|


</syntaxhighlight>
</lang>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>Join[{1,2,3}, {4,5,6}]
<syntaxhighlight lang=Mathematica>Join[{1,2,3}, {4,5,6}]


-> {1, 2, 3, 4, 5, 6}</lang>
-> {1, 2, 3, 4, 5, 6}</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
Two arrays are concatenated by placing the two arrays between a pair of square brackets. A space between the two array names will concatenate them horizontally, and a semi-colon between array names will concatenate vertically.
Two arrays are concatenated by placing the two arrays between a pair of square brackets. A space between the two array names will concatenate them horizontally, and a semi-colon between array names will concatenate vertically.
<lang MATLAB>>> a = [1 2 3];
<syntaxhighlight lang=MATLAB>>> a = [1 2 3];
>> b = [4 5 6];
>> b = [4 5 6];
>> c = [a b]
>> c = [a b]
Line 2,735: Line 2,735:
c =
c =
1 2 3
1 2 3
4 5 6</lang>
4 5 6</syntaxhighlight>


For concatenation along higher dimensions, use cat():
For concatenation along higher dimensions, use cat():
<lang MATLAB>>> a = randn([3 4 5]);
<syntaxhighlight lang=MATLAB>>> a = randn([3 4 5]);
>> b = randn([3 4 7]);
>> b = randn([3 4 7]);
>> c = cat(3,a,b);
>> c = cat(3,a,b);
>> size(c)
>> size(c)
ans =
ans =
3 4 12</lang>
3 4 12</syntaxhighlight>


=={{header|Maxima}}==
=={{header|Maxima}}==
Line 2,768: Line 2,768:
[1, 0, 0],
[1, 0, 0],
[0, 1, 0],
[0, 1, 0],
[0, 0, 1]) */</lang>
[0, 0, 1]) */</syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==


<lang Mercury>A `append` B = C</lang>
<syntaxhighlight lang=Mercury>A `append` B = C</syntaxhighlight>


It ''could'' be "as simple as array1 + array2", but the 'array' module names the operation 'append' rather than '+'. It's tempting to just say that Mercury supports ad-hoc polymorphism - it can infer that a bare '+' refers to 'float.+' or 'int.+' (or that the 'append' above is array.append, rather than list.append), by the types involved - but it also handles other ambiguities in the same way. For instance, Mercury (like Prolog and Erlang) treats the arity of a function as part of its name, where ''a(1, 2)'' and ''a(1)'' involve the distinct functions a/2 and a/1. But Mercury also (unlike Prolog and Erlang) supports [[currying]], where ''a(1)'' is a function that accepts a/2's second argument. So, is ''[a(X), a(Y), a(Z)]'' a list of whatever type a/1 evaluates to, or is it a list of curried a/2?
It ''could'' be "as simple as array1 + array2", but the 'array' module names the operation 'append' rather than '+'. It's tempting to just say that Mercury supports ad-hoc polymorphism - it can infer that a bare '+' refers to 'float.+' or 'int.+' (or that the 'append' above is array.append, rather than list.append), by the types involved - but it also handles other ambiguities in the same way. For instance, Mercury (like Prolog and Erlang) treats the arity of a function as part of its name, where ''a(1, 2)'' and ''a(1)'' involve the distinct functions a/2 and a/1. But Mercury also (unlike Prolog and Erlang) supports [[currying]], where ''a(1)'' is a function that accepts a/2's second argument. So, is ''[a(X), a(Y), a(Z)]'' a list of whatever type a/1 evaluates to, or is it a list of curried a/2?
Line 2,778: Line 2,778:
=={{header|min}}==
=={{header|min}}==
{{works with|min|0.19.3}}
{{works with|min|0.19.3}}
<lang min>(1 2 3) (4 "apple" 6) concat print</lang>
<syntaxhighlight lang=min>(1 2 3) (4 "apple" 6) concat print</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,785: Line 2,785:


=={{header|MiniScript}}==
=={{header|MiniScript}}==
<lang MiniScript>
<syntaxhighlight lang=MiniScript>
arrOne = [1, 2, 3]
arrOne = [1, 2, 3]
arrTwo = [4, 5, 6]
arrTwo = [4, 5, 6]
print arrOne + arrTwo
print arrOne + arrTwo
</syntaxhighlight>
</lang>


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
Assuming a and b are array or list objects, they may concatenated using the '+' operator.
Assuming a and b are array or list objects, they may concatenated using the '+' operator.
<lang Nanoquery>a + b</lang>
<syntaxhighlight lang=Nanoquery>a + b</syntaxhighlight>
The '*' operator may also be used to create a specific number of copies of a list or array.
The '*' operator may also be used to create a specific number of copies of a list or array.
<pre>% a = list()
<pre>% a = list()
Line 2,803: Line 2,803:


=={{header|Neko}}==
=={{header|Neko}}==
<lang ActionScript>/*
<syntaxhighlight lang=ActionScript>/*
Array concatenation, in Neko
Array concatenation, in Neko
*/
*/
Line 2,812: Line 2,812:
/* $array(a1, a2) creates an array of two arrays, $aconcat merges to one */
/* $array(a1, a2) creates an array of two arrays, $aconcat merges to one */
var ac = $aconcat($array(a1, a2))
var ac = $aconcat($array(a1, a2))
$print(ac, "\n")</lang>
$print(ac, "\n")</syntaxhighlight>


{{out}}
{{out}}
Line 2,820: Line 2,820:


=={{header|Nemerle}}==
=={{header|Nemerle}}==
<lang Nemerle>using System.Console;
<syntaxhighlight lang=Nemerle>using System.Console;
using Nemerle.Collections;
using Nemerle.Collections;


Line 2,831: Line 2,831:
foreach (i in arr12) Write($"$i ");
foreach (i in arr12) Write($"$i ");
}
}
}</lang>
}</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
NetRexx arrays are identical to [[Java|Java's]] so all the techniques described in the [[#Java|Java]] section apply to NetRexx too. This example uses the <tt>Collection</tt> classes to merge two arrays.
NetRexx arrays are identical to [[Java|Java's]] so all the techniques described in the [[#Java|Java]] section apply to NetRexx too. This example uses the <tt>Collection</tt> classes to merge two arrays.
<lang netrexx>/* NetRexx */
<syntaxhighlight lang=netrexx>/* NetRexx */
options replace format comments java crossref nobinary
options replace format comments java crossref nobinary


Line 2,862: Line 2,862:
loop m_ = 0 to merged.length - 1
loop m_ = 0 to merged.length - 1
say m_ merged[m_]
say m_ merged[m_]
end m_</lang>
end m_</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,879: Line 2,879:


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang NewLISP>; file: arraycon.lsp
<syntaxhighlight lang=NewLISP>; file: arraycon.lsp
; url: http://rosettacode.org/wiki/Array_concatenation
; url: http://rosettacode.org/wiki/Array_concatenation
; author: oofoe 2012-01-28
; author: oofoe 2012-01-28
Line 2,894: Line 2,894:
(append '((x 56) (b 99)) '((z 34) (c 23) (r 88))))
(append '((x 56) (b 99)) '((z 34) (c 23) (r 88))))


(exit)</lang>
(exit)</syntaxhighlight>


{{out}}
{{out}}
Line 2,905: Line 2,905:
Examples tested to work with Q'Nial7
Examples tested to work with Q'Nial7


<lang Nial> a:= 1 2 3
<syntaxhighlight lang=Nial> a:= 1 2 3
+-+-+-+
+-+-+-+
|1|2|3|
|1|2|3|
Line 2,912: Line 2,912:
+-+-+-+
+-+-+-+
|4|5|6|
|4|5|6|
+-+-+-+</lang>
+-+-+-+</syntaxhighlight>


Table of lists:
Table of lists:


<lang Nial> a b
<syntaxhighlight lang=Nial> a b


+-------+-------+
+-------+-------+
Line 2,922: Line 2,922:
||1|2|3|||4|5|6||
||1|2|3|||4|5|6||
|+-+-+-+|+-+-+-+|
|+-+-+-+|+-+-+-+|
+-------+-------+</lang>
+-------+-------+</syntaxhighlight>


Simple concatenation of two arrays/lists:
Simple concatenation of two arrays/lists:


<lang Nial> link a b
<syntaxhighlight lang=Nial> link a b
+-+-+-+-+-+-+
+-+-+-+-+-+-+
|1|2|3|4|5|6|
|1|2|3|4|5|6|
+-+-+-+-+-+-+</lang>
+-+-+-+-+-+-+</syntaxhighlight>


Convert list of lists to table:
Convert list of lists to table:


<lang Nial> mix a b
<syntaxhighlight lang=Nial> mix a b
+-+-+-+
+-+-+-+
|1|2|3|
|1|2|3|
+-+-+-+
+-+-+-+
|4|5|6|
|4|5|6|
+-+-+-+</lang>
+-+-+-+</syntaxhighlight>


Interchange levels of a list of lists:
Interchange levels of a list of lists:
<lang Nial> pack a b
<syntaxhighlight lang=Nial> pack a b
+-----+-----+-----+
+-----+-----+-----+
|+-+-+|+-+-+|+-+-+|
|+-+-+|+-+-+|+-+-+|
||1|4|||2|5|||3|6||
||1|4|||2|5|||3|6||
|+-+-+|+-+-+|+-+-+|
|+-+-+|+-+-+|+-+-+|
+-----+-----+-----+</lang>
+-----+-----+-----+</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
Dynamic sized Sequences can simply be concatenated:
Dynamic sized Sequences can simply be concatenated:
<lang nim>var
<syntaxhighlight lang=nim>var
x = @[1,2,3,4,5,6]
x = @[1,2,3,4,5,6]
y = @[7,8,9,10,11]
y = @[7,8,9,10,11]
z = x & y</lang>
z = x & y</syntaxhighlight>


Static sized Arrays:
Static sized Arrays:
<lang nim>var
<syntaxhighlight lang=nim>var
a = [1,2,3,4,5,6]
a = [1,2,3,4,5,6]
b = [7,8,9,10,11]
b = [7,8,9,10,11]
Line 2,962: Line 2,962:


c[0..5] = a
c[0..5] = a
c[6..10] = b</lang>
c[6..10] = b</syntaxhighlight>


=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
<lang oberon2>
<syntaxhighlight lang=oberon2>
MODULE ArrayConcat;
MODULE ArrayConcat;
IMPORT
IMPORT
Line 3,016: Line 3,016:
END ArrayConcat.
END ArrayConcat.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 3,023: Line 3,023:


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>
<syntaxhighlight lang=objeck>
bundle Default {
bundle Default {
class Arithmetic {
class Arithmetic {
Line 3,055: Line 3,055:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Objective-C}}==
=={{header|Objective-C}}==
with immutable arrays:
with immutable arrays:
<lang objc>NSArray *arr1 = @[@1, @2, @3];
<syntaxhighlight lang=objc>NSArray *arr1 = @[@1, @2, @3];
NSArray *arr2 = @[@4, @5, @6];
NSArray *arr2 = @[@4, @5, @6];
NSArray *arr3 = [arr1 arrayByAddingObjectsFromArray:arr2];</lang>
NSArray *arr3 = [arr1 arrayByAddingObjectsFromArray:arr2];</syntaxhighlight>


or adding onto a mutable array:
or adding onto a mutable array:
<lang objc>NSArray *arr1 = @[@1, @2, @3];
<syntaxhighlight lang=objc>NSArray *arr1 = @[@1, @2, @3];
NSArray *arr2 = @[@4, @5, @6];
NSArray *arr2 = @[@4, @5, @6];
NSMutableArray *arr3 = [NSMutableArray arrayWithArray:arr1];
NSMutableArray *arr3 = [NSMutableArray arrayWithArray:arr1];
[arr3 addObjectsFromArray:arr2];</lang>
[arr3 addObjectsFromArray:arr2];</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
It is more natural in OCaml to use lists instead of arrays:
It is more natural in OCaml to use lists instead of arrays:
<lang ocaml># let list1 = [1; 2; 3];;
<syntaxhighlight lang=ocaml># let list1 = [1; 2; 3];;
val list1 : int list = [1; 2; 3]
val list1 : int list = [1; 2; 3]
# let list2 = [4; 5; 6];;
# let list2 = [4; 5; 6];;
val list2 : int list = [4; 5; 6]
val list2 : int list = [4; 5; 6]
# let list1and2 = list1 @ list2;;
# let list1and2 = list1 @ list2;;
val list1and2 : int list = [1; 2; 3; 4; 5; 6]</lang>
val list1and2 : int list = [1; 2; 3; 4; 5; 6]</syntaxhighlight>


If you want to use arrays:
If you want to use arrays:
<lang ocaml># let array1 = [|1; 2; 3|];;
<syntaxhighlight lang=ocaml># let array1 = [|1; 2; 3|];;
val array1 : int array = [|1; 2; 3|]
val array1 : int array = [|1; 2; 3|]
# let array2 = [|4; 5; 6|];;
# let array2 = [|4; 5; 6|];;
val array2 : int array = [|4; 5; 6|]
val array2 : int array = [|4; 5; 6|]
# let array1and2 = Array.append array1 array2;;
# let array1and2 = Array.append array1 array2;;
val array1and2 : int array = [|1; 2; 3; 4; 5; 6|]</lang>
val array1and2 : int array = [|1; 2; 3; 4; 5; 6|]</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>import: mapping
<syntaxhighlight lang=Oforth>import: mapping


[1, 2, 3 ] [ 4, 5, 6, 7 ] + </lang>
[1, 2, 3 ] [ 4, 5, 6, 7 ] + </syntaxhighlight>


=={{header|Onyx}}==
=={{header|Onyx}}==


<lang onyx># With two arrays on the stack, cat pops
<syntaxhighlight lang=onyx># With two arrays on the stack, cat pops
# them, concatenates them, and pushes the result back
# them, concatenates them, and pushes the result back
# on the stack. This works with arrays of integers,
# on the stack. This works with arrays of integers,
Line 3,106: Line 3,106:


[1 true `a'] [2 false `b'] [`3rd array'] 3 ncat
[1 true `a'] [2 false `b'] [`3rd array'] 3 ncat
# leaves [1 true `a' 2 false `b' `3rd array'] on the stack</lang>
# leaves [1 true `a' 2 false `b' `3rd array'] on the stack</syntaxhighlight>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
<lang ooRexx>a = .array~of(1,2,3)
<syntaxhighlight lang=ooRexx>a = .array~of(1,2,3)
say "Array a has " a~items "items"
say "Array a has " a~items "items"
b = .array~of(4,5,6)
b = .array~of(4,5,6)
say "Array b has " b~items "items"
say "Array b has " b~items "items"
a~appendall(b) -- adds all items from b to a
a~appendall(b) -- adds all items from b to a
say "Array a now has " a~items "items"</lang>
say "Array a now has " a~items "items"</syntaxhighlight>
{{out}}
{{out}}
<pre>Array a has 3 items
<pre>Array a has 3 items
Line 3,122: Line 3,122:
=={{header|Order}}==
=={{header|Order}}==
Order supports two main aggregate types: tuples and sequences (similar to lists in other languages). Most "interesting" operations are limited to sequences, but both support an append operation, and each can be converted to the other.
Order supports two main aggregate types: tuples and sequences (similar to lists in other languages). Most "interesting" operations are limited to sequences, but both support an append operation, and each can be converted to the other.
<lang c>#include <order/interpreter.h>
<syntaxhighlight lang=c>#include <order/interpreter.h>


ORDER_PP( 8tuple_append(8tuple(1, 2, 3), 8tuple(4, 5, 6), 8pair(7, 8)) )
ORDER_PP( 8tuple_append(8tuple(1, 2, 3), 8tuple(4, 5, 6), 8pair(7, 8)) )
Line 3,128: Line 3,128:


ORDER_PP( 8seq_append(8seq(1, 2, 3), 8seq(4, 5, 6), 8seq(7, 8)) )
ORDER_PP( 8seq_append(8seq(1, 2, 3), 8seq(4, 5, 6), 8seq(7, 8)) )
// -> (1)(2)(3)(4)(5)(6)(7)(8)</lang>
// -> (1)(2)(3)(4)(5)(6)(7)(8)</syntaxhighlight>


=={{header|OxygenBasic}}==
=={{header|OxygenBasic}}==
<lang oxygenbasic>
<syntaxhighlight lang=oxygenbasic>
'CREATE DYNAMIC ARRAY SPACES USING STRINGS
'CREATE DYNAMIC ARRAY SPACES USING STRINGS


Line 3,154: Line 3,154:


print a[7] 'result 70
print a[7] 'result 70
</syntaxhighlight>
</lang>


=={{header|Oz}}==
=={{header|Oz}}==
List are concatenated with <code>List.append</code> (shortcut: <code>Append</code>). Tuples are concatened with <code>Tuple.append</code>. Arrays do exist in Oz, but are rarely used.
List are concatenated with <code>List.append</code> (shortcut: <code>Append</code>). Tuples are concatened with <code>Tuple.append</code>. Arrays do exist in Oz, but are rarely used.
<lang oz>%% concatenating 2 lists
<syntaxhighlight lang=oz>%% concatenating 2 lists
{Append [a b] [c d]} = [a b c d]
{Append [a b] [c d]} = [a b c d]


%% concatenating 2 tuples
%% concatenating 2 tuples
{Tuple.append t(1 2 3) u(4 5 6)} = u(1 2 3 4 5 6)</lang>
{Tuple.append t(1 2 3) u(4 5 6)} = u(1 2 3 4 5 6)</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>concat(u,v)</lang>
<syntaxhighlight lang=parigp>concat(u,v)</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 3,172: Line 3,172:
=={{header|Perl}}==
=={{header|Perl}}==
In Perl, arrays placed into list context are flattened:
In Perl, arrays placed into list context are flattened:
<lang perl>my @arr1 = (1, 2, 3);
<syntaxhighlight lang=perl>my @arr1 = (1, 2, 3);
my @arr2 = (4, 5, 6);
my @arr2 = (4, 5, 6);
my @arr3 = (@arr1, @arr2);</lang>
my @arr3 = (@arr1, @arr2);</syntaxhighlight>


The <code>[http://perldoc.perl.org/functions/push.html push]</code> function appends elements onto an existing array:
The <code>[http://perldoc.perl.org/functions/push.html push]</code> function appends elements onto an existing array:
<lang perl>my @arr1 = (1, 2, 3);
<syntaxhighlight lang=perl>my @arr1 = (1, 2, 3);
my @arr2 = (4, 5, 6);
my @arr2 = (4, 5, 6);
push @arr1, @arr2;
push @arr1, @arr2;
print "@arr1\n"; # prints "1 2 3 4 5 6"</lang>
print "@arr1\n"; # prints "1 2 3 4 5 6"</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/basics}}
<!--<lang Phix>-->
<!--<syntaxhighlight lang=Phix>-->
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s1</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #000000;">2<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">}<span style="color: #0000FF;">,</span> <span style="color: #000000;">s2</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #000000;">4<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">,<span style="color: #000000;">6<span style="color: #0000FF;">}</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s1</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #000000;">2<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">}<span style="color: #0000FF;">,</span> <span style="color: #000000;">s2</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #000000;">4<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">,<span style="color: #000000;">6<span style="color: #0000FF;">}</span>
<span style="color: #0000FF;">?</span> <span style="color: #000000;">s1</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">s2
<span style="color: #0000FF;">?</span> <span style="color: #000000;">s1</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">s2
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 3,194: Line 3,194:


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<lang Phixmonti>1.0 "Hello" 3 2 / 4 2.1 power 4 tolist 5 6 7 8 4 tolist chain print</lang>
<syntaxhighlight lang=Phixmonti>1.0 "Hello" 3 2 / 4 2.1 power 4 tolist 5 6 7 8 4 tolist chain print</syntaxhighlight>
With syntactic sugar
With syntactic sugar
<lang Phixmonti>include ..\Utilitys.pmt
<syntaxhighlight lang=Phixmonti>include ..\Utilitys.pmt
( 1.0 "Hello" 3 2 / 4 2.1 power ) ( 5 6 7 8 ) chain print</lang>
( 1.0 "Hello" 3 2 / 4 2.1 power ) ( 5 6 7 8 ) chain print</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==


<lang php>$arr1 = array(1, 2, 3);
<syntaxhighlight lang=php>$arr1 = array(1, 2, 3);
$arr2 = array(4, 5, 6);
$arr2 = array(4, 5, 6);
$arr3 = array_merge($arr1, $arr2);</lang>
$arr3 = array_merge($arr1, $arr2);</syntaxhighlight>


=={{header|Picat}}==
=={{header|Picat}}==
Line 3,210: Line 3,210:
and back again with to_array/1.
and back again with to_array/1.


<lang Picat>go =>
<syntaxhighlight lang=Picat>go =>
L1 = {1,2,3,4,5}, % define an array with {}
L1 = {1,2,3,4,5}, % define an array with {}
L2 = {6,7,8,9},
L2 = {6,7,8,9},
Line 3,221: Line 3,221:
append(L1.to_list,L2.to_list,L3),
append(L1.to_list,L2.to_list,L3),
println(L3.to_array),
println(L3.to_array),
nl.</lang>
nl.</syntaxhighlight>


{{out}}
{{out}}
Line 3,232: Line 3,232:


There are destructive concatenations:
There are destructive concatenations:
<lang PicoLisp>: (setq A (1 2 3) B '(a b c))
<syntaxhighlight lang=PicoLisp>: (setq A (1 2 3) B '(a b c))
-> (a b c)
-> (a b c)
: (conc A B) # Concatenate lists in 'A' and 'B'
: (conc A B) # Concatenate lists in 'A' and 'B'
-> (1 2 3 a b c)
-> (1 2 3 a b c)
: A
: A
-> (1 2 3 a b c) # Side effect: List in 'A' is modified!</lang>
-> (1 2 3 a b c) # Side effect: List in 'A' is modified!</syntaxhighlight>
and non-destructive concatenations:
and non-destructive concatenations:
<lang PicoLisp>: (setq A (1 2 3) B '(a b c))
<syntaxhighlight lang=PicoLisp>: (setq A (1 2 3) B '(a b c))
-> (a b c)
-> (a b c)
: (append A B) # Append lists in 'A' and 'B'
: (append A B) # Append lists in 'A' and 'B'
Line 3,246: Line 3,246:
-> (1 2 3)
-> (1 2 3)
: B
: B
-> (a b c) # Arguments are not modified</lang>
-> (a b c) # Arguments are not modified</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang Pike>int main() {
<syntaxhighlight lang=Pike>int main() {
array arr1 = ({1, 2, 3});
array arr1 = ({1, 2, 3});
array arr2 = ({4, 5, 6});
array arr2 = ({4, 5, 6});
array arr3 = arr1 + arr2;
array arr3 = arr1 + arr2;
}</lang>
}</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
Trivial example requires no computational statement.
Trivial example requires no computational statement.
Note that the arrays are not in static storage:
Note that the arrays are not in static storage:
<lang PL/I>
<syntaxhighlight lang=PL/I>
declare x(12) fixed;
declare x(12) fixed;
declare b(5) fixed defined x;
declare b(5) fixed defined x;
declare c(7) fixed defined x(1sub+5);
declare c(7) fixed defined x(1sub+5);
</syntaxhighlight>
</lang>
A more general example using dynamic bounds.
A more general example using dynamic bounds.
Again, no computation statement is required.
Again, no computation statement is required.
Line 3,269: Line 3,269:
declare b(m) fixed defined x;
declare b(m) fixed defined x;
declare c(n) fixed defined x(1sub+hbound(b,1));
declare c(n) fixed defined x(1sub+hbound(b,1));
</syntaxhighlight>
</lang>


An alternative, that can be used to advantage for matrices
An alternative, that can be used to advantage for matrices
Line 3,291: Line 3,291:
put skip list ('Composite matrix:');
put skip list ('Composite matrix:');
put skip edit (a) ( skip, (hbound(a,2)) f(5,0) );
put skip edit (a) ( skip, (hbound(a,2)) f(5,0) );
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<lang>
<lang>
Line 3,308: Line 3,308:
0 0 0 0 15 16
0 0 0 0 15 16


</syntaxhighlight>
</lang>


=={{header|Pony}}==
=={{header|Pony}}==
<lang pony>
<syntaxhighlight lang=pony>
actor Main
actor Main
new create(env:Env)=>
new create(env:Env)=>
Line 3,326: Line 3,326:
env.out.print(i.string())
env.out.print(i.string())
end
end
</syntaxhighlight>
</lang>


=={{header|PostScript}}==
=={{header|PostScript}}==
{{libheader|initlib}}
{{libheader|initlib}}
<lang postscript>
<syntaxhighlight lang=postscript>
[1 2 3 4] [5 6 7 8] concat
[1 2 3 4] [5 6 7 8] concat
</syntaxhighlight>
</lang>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>$a = 1,2,3
<syntaxhighlight lang=powershell>$a = 1,2,3
$b = 4,5,6
$b = 4,5,6


$c = $a + $b
$c = $a + $b
Write-Host $c</lang>
Write-Host $c</syntaxhighlight>


=={{header|Processing}}==
=={{header|Processing}}==
<lang processing>
<syntaxhighlight lang=processing>
int[] a = {1, 2, 3}, b = {4, 5, 6};
int[] a = {1, 2, 3}, b = {4, 5, 6};


int[] c = concat(a, b);
int[] c = concat(a, b);
</syntaxhighlight>
</lang>


=={{header|Prolog}}==
=={{header|Prolog}}==
<lang prolog>
<syntaxhighlight lang=prolog>
?- append([1,2,3],[4,5,6],R).
?- append([1,2,3],[4,5,6],R).
R = [1, 2, 3, 4, 5, 6].
R = [1, 2, 3, 4, 5, 6].
</syntaxhighlight>
</lang>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>Procedure displayArray(Array a(1), msg.s)
<syntaxhighlight lang=PureBasic>Procedure displayArray(Array a(1), msg.s)
Protected i
Protected i
Print(msg + " [")
Print(msg + " [")
Line 3,401: Line 3,401:
Input()
Input()
CloseConsole()
CloseConsole()
EndIf</lang>
EndIf</syntaxhighlight>
{{out}}
{{out}}
<pre>a: [5, 2, -4, -1, -2]
<pre>a: [5, 2, -4, -1, -2]
Line 3,410: Line 3,410:
The <code>[http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange +]</code> operator concatenates two lists and returns a new list.
The <code>[http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange +]</code> operator concatenates two lists and returns a new list.
The <code>[http://docs.python.org/library/stdtypes.html#mutable-sequence-types list.extend]</code> method appends elements of another list to the receiver.
The <code>[http://docs.python.org/library/stdtypes.html#mutable-sequence-types list.extend]</code> method appends elements of another list to the receiver.
<lang python>arr1 = [1, 2, 3]
<syntaxhighlight lang=python>arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr3 = [7, 8, 9]
Line 3,416: Line 3,416:
assert arr4 == [1, 2, 3, 4, 5, 6]
assert arr4 == [1, 2, 3, 4, 5, 6]
arr4.extend(arr3)
arr4.extend(arr3)
assert arr4 == [1, 2, 3, 4, 5, 6, 7, 8, 9]</lang>
assert arr4 == [1, 2, 3, 4, 5, 6, 7, 8, 9]</syntaxhighlight>


Note: list.extend is normally accomplished using the += operator like this:
Note: list.extend is normally accomplished using the += operator like this:
<lang python>arr5 = [4, 5, 6]
<syntaxhighlight lang=python>arr5 = [4, 5, 6]
arr6 = [7, 8, 9]
arr6 = [7, 8, 9]
arr6 += arr5
arr6 += arr5
assert arr6 == [7, 8, 9, 4, 5, 6]</lang>
assert arr6 == [7, 8, 9, 4, 5, 6]</syntaxhighlight>


=={{header|Q}}==
=={{header|Q}}==
<lang q>list1:1 2 3
<syntaxhighlight lang=q>list1:1 2 3
list2:4 5 6
list2:4 5 6
list1,list2</lang>
list1,list2</syntaxhighlight>




Line 3,433: Line 3,433:
{{works with|QBasic|1.1}}
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{works with|QuickBasic|4.5}}
<lang qbasic>FUNCTION ConcatArrays(a(), b())
<syntaxhighlight lang=qbasic>FUNCTION ConcatArrays(a(), b())
ta = UBOUND(a)
ta = UBOUND(a)
tb = UBOUND(b)
tb = UBOUND(b)
Line 3,461: Line 3,461:
IF i < nt THEN PRINT ", ";
IF i < nt THEN PRINT ", ";
NEXT i
NEXT i
</syntaxhighlight>
</lang>


=={{header|QB64}}==
=={{header|QB64}}==


<lang QB64>
<syntaxhighlight lang=QB64>


Dim As Integer First, Second
Dim As Integer First, Second
Line 3,511: Line 3,511:
End Sub
End Sub


</syntaxhighlight>
</lang>
=={{header|Quackery}}==
=={{header|Quackery}}==


Line 3,538: Line 3,538:
=={{header|R}}==
=={{header|R}}==


<syntaxhighlight lang=R>
<lang R>
a1 <- c(1, 2, 3)
a1 <- c(1, 2, 3)
a2 <- c(3, 4, 5)
a2 <- c(3, 4, 5)
a3 <- c(a1, a2)
a3 <- c(a1, a2)
</syntaxhighlight>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>
<syntaxhighlight lang=racket>
(vector-append #(1 2 3 4) #(5 6 7) #(8 9 10))
(vector-append #(1 2 3 4) #(5 6 7) #(8 9 10))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 3,556: Line 3,556:
(formerly Perl 6)
(formerly Perl 6)
{{works with|Rakudo|2018.06}}
{{works with|Rakudo|2018.06}}
<lang perl6>my @array1 = 1, 2, 3;
<syntaxhighlight lang=perl6>my @array1 = 1, 2, 3;
my @array2 = 4, 5, 6;
my @array2 = 4, 5, 6;


Line 3,573: Line 3,573:
# of the second array to the first, use the .append method.
# of the second array to the first, use the .append method.


say @array1.append: @array2;</lang>
say @array1.append: @array2;</syntaxhighlight>
{{Out}}
{{Out}}
<pre>[1 2 3 4 5 6]
<pre>[1 2 3 4 5 6]
Line 3,580: Line 3,580:


=={{header|RapidQ}}==
=={{header|RapidQ}}==
<syntaxhighlight lang=vb>
<lang vb>
DEFINT A(1 to 4) = {1, 2, 3, 4}
DEFINT A(1 to 4) = {1, 2, 3, 4}
DEFINT B(1 to 4) = {10, 20, 30, 40}
DEFINT B(1 to 4) = {10, 20, 30, 40}
Line 3,587: Line 3,587:
Redim A(1 to 8) as integer
Redim A(1 to 8) as integer
MEMCPY(varptr(A(5)), varptr(B(1)), Sizeof(integer)*4)
MEMCPY(varptr(A(5)), varptr(B(1)), Sizeof(integer)*4)
</syntaxhighlight>
</lang>


=={{header|Rapira}}==
=={{header|Rapira}}==
<lang Rapira>arr1 := <* 1, 2, 3 *>
<syntaxhighlight lang=Rapira>arr1 := <* 1, 2, 3 *>
arr2 := <* 4, 5, 6 *>
arr2 := <* 4, 5, 6 *>
output: arr1 + arr2</lang>
output: arr1 + arr2</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<lang REBOL>
<syntaxhighlight lang=REBOL>
a1: [1 2 3]
a1: [1 2 3]
a2: [4 5 6]
a2: [4 5 6]
Line 3,603: Line 3,603:


append/only a1 a3 ; -> [1 2 3 4 5 6 [7 8 9]]
append/only a1 a3 ; -> [1 2 3 4 5 6 [7 8 9]]
</syntaxhighlight>
</lang>


=={{header|Red}}==
=={{header|Red}}==
<lang Red>>> arr1: ["a" "b" "c"]
<syntaxhighlight lang=Red>>> arr1: ["a" "b" "c"]
>> arr2: ["d" "e" "f"]
>> arr2: ["d" "e" "f"]
>> append arr1 arr2
>> append arr1 arr2
Line 3,617: Line 3,617:
== [22 33 44]
== [22 33 44]
>> append/only arr1 arr4
>> append/only arr1 arr4
== [1 2 3 "a" "b" "c" "d" "e" "f" [22 33 44]]</lang>
== [1 2 3 "a" "b" "c" "d" "e" "f" [22 33 44]]</syntaxhighlight>


=={{header|ReScript}}==
=={{header|ReScript}}==
<lang ReScript>Js.Array2.concat(["a", "b"], ["c", "d", "e"]) == ["a", "b", "c", "d", "e"]</lang>
<syntaxhighlight lang=ReScript>Js.Array2.concat(["a", "b"], ["c", "d", "e"]) == ["a", "b", "c", "d", "e"]</syntaxhighlight>


=={{header|Retro}}==
=={{header|Retro}}==
<lang Retro>{ #1 #2 #3 } { #4 #5 #6 } a:append</lang>
<syntaxhighlight lang=Retro>{ #1 #2 #3 } { #4 #5 #6 } a:append</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 3,636: Line 3,636:


Consider:
Consider:
<lang rexx>a.1 = 10
<syntaxhighlight lang=rexx>a.1 = 10
a.2 = 22.7
a.2 = 22.7
a.7 = -12</lang>
a.7 = -12</syntaxhighlight>
where now we have three "elements", and they are disjointed (another word for ''sparse'').
where now we have three "elements", and they are disjointed (another word for ''sparse'').
<br>There are ways to handle this in REXX however.
<br>There are ways to handle this in REXX however.
Line 3,644: Line 3,644:
<br>assuming that the stemmed variables are sequential.
<br>assuming that the stemmed variables are sequential.
<br><br>'''example:'''
<br><br>'''example:'''
<lang rexx>fact.0=8
<syntaxhighlight lang=rexx>fact.0=8
fact.1= 1
fact.1= 1
fact.2= 2
fact.2= 2
Line 3,652: Line 3,652:
fact.6= 720
fact.6= 720
fact.7= 5040
fact.7= 5040
fact.8=40320</lang>
fact.8=40320</syntaxhighlight>
To concat two "arrays" in REXX, the following assumes that the stemmed variables are in order, with no gaps, and none have a "null" value.
To concat two "arrays" in REXX, the following assumes that the stemmed variables are in order, with no gaps, and none have a "null" value.
<lang rexx>/*REXX program to demonstrates how to perform array concatenation.*/
<syntaxhighlight lang=rexx>/*REXX program to demonstrates how to perform array concatenation.*/


p.= /*(below) a short list of primes.*/
p.= /*(below) a short list of primes.*/
Line 3,675: Line 3,675:
say 'c.'m"="c.m /*show a "merged" C array nums.*/
say 'c.'m"="c.m /*show a "merged" C array nums.*/
end /*m*/
end /*m*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,706: Line 3,706:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang=ring>
arr1 = [1, 2, 3]
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr2 = [4, 5, 6]
Line 3,715: Line 3,715:
arr5 = arr4 + arr3
arr5 = arr4 + arr3
see arr5
see arr5
</syntaxhighlight>
</lang>


=={{header|RLaB}}==
=={{header|RLaB}}==
Line 3,721: Line 3,721:
In RLaB the matrices can be appended (column-wise) or stacked (row-wise).
In RLaB the matrices can be appended (column-wise) or stacked (row-wise).
Consider few examples:
Consider few examples:
<lang RLaB>
<syntaxhighlight lang=RLaB>
>> x = [1, 2, 3]
>> x = [1, 2, 3]
>> y = [4, 5, 6]
>> y = [4, 5, 6]
Line 3,735: Line 3,735:
4 5 6
4 5 6
>>
>>
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
The <code>[http://www.ruby-doc.org/core/classes/Array.html#M002209 Array#+]</code> method concatenates two arrays and returns a new array. The <code>[http://www.ruby-doc.org/core/classes/Array.html#M002166 Array#concat]</code> method appends elements of another array to the receiver.
The <code>[http://www.ruby-doc.org/core/classes/Array.html#M002209 Array#+]</code> method concatenates two arrays and returns a new array. The <code>[http://www.ruby-doc.org/core/classes/Array.html#M002166 Array#concat]</code> method appends elements of another array to the receiver.
<lang ruby>arr1 = [1, 2, 3]
<syntaxhighlight lang=ruby>arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr3 = [7, 8, 9]
arr4 = arr1 + arr2 # => [1, 2, 3, 4, 5, 6]
arr4 = arr1 + arr2 # => [1, 2, 3, 4, 5, 6]
arr4.concat(arr3) # => [1, 2, 3, 4, 5, 6, 7, 8, 9]</lang>
arr4.concat(arr3) # => [1, 2, 3, 4, 5, 6, 7, 8, 9]</syntaxhighlight>


Or use flatten(1):
Or use flatten(1):
<lang ruby>
<syntaxhighlight lang=ruby>
# concat multiple arrays:
# concat multiple arrays:
[arr1,arr2,arr3].flatten(1)
[arr1,arr2,arr3].flatten(1)
# ignore nil:
# ignore nil:
[arr1,arr2,arr3].compact.flatten(1)
[arr1,arr2,arr3].compact.flatten(1)
</syntaxhighlight>
</lang>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>fn main() {
<syntaxhighlight lang=rust>fn main() {
let a_vec = vec![1, 2, 3, 4, 5];
let a_vec = vec![1, 2, 3, 4, 5];
let b_vec = vec![6; 5];
let b_vec = vec![6; 5];
Line 3,769: Line 3,769:
concat
concat
}
}
</syntaxhighlight>
</lang>


Or, with iterators:
Or, with iterators:


<lang rust>fn concatenate_arrays<T: Clone>(x: &[T], y: &[T]) -> Vec<T> {
<syntaxhighlight lang=rust>fn concatenate_arrays<T: Clone>(x: &[T], y: &[T]) -> Vec<T> {
x.iter().chain(y).cloned().collect()
x.iter().chain(y).cloned().collect()
}
}
</syntaxhighlight>
</lang>


=={{header|S-lang}}==
=={{header|S-lang}}==
<lang S-lang>variable a = [1, 2, 3];
<syntaxhighlight lang=S-lang>variable a = [1, 2, 3];
variable b = [4, 5, 6], c;</lang>
variable b = [4, 5, 6], c;</syntaxhighlight>


a+b is perfectly valid in S-Lang, but instead of the problem's desired effect,
a+b is perfectly valid in S-Lang, but instead of the problem's desired effect,
Line 3,786: Line 3,786:
But because arrays automatically 'flatten' when defined, concatenation is as
But because arrays automatically 'flatten' when defined, concatenation is as
simple as:
simple as:
<lang S-lang>c = [a, b];</lang>
<syntaxhighlight lang=S-lang>c = [a, b];</syntaxhighlight>
Use of lists is more traditional; lists don't 'flatten', so we use either
Use of lists is more traditional; lists don't 'flatten', so we use either
list_concat() to create a new concatenated array:
list_concat() to create a new concatenated array:
<lang S-lang>a = {1, 2, 3};
<syntaxhighlight lang=S-lang>a = {1, 2, 3};
b = {4, 5, 6};
b = {4, 5, 6};
c = list_concat(a, b);</lang>
c = list_concat(a, b);</syntaxhighlight>


or list_join():
or list_join():
<lang S-lang>list_join(a, b);</lang>
<syntaxhighlight lang=S-lang>list_join(a, b);</syntaxhighlight>
which adds the elements of b onto a.
which adds the elements of b onto a.


=={{header|SASL}}==
=={{header|SASL}}==
In SASL, the concat operator ++ is built-in
In SASL, the concat operator ++ is built-in
<lang SASL>(1 2 3) ++ (4 5 6)</lang>
<syntaxhighlight lang=SASL>(1 2 3) ++ (4 5 6)</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang Scala>val arr1 = Array( 1, 2, 3 )
<syntaxhighlight lang=Scala>val arr1 = Array( 1, 2, 3 )
val arr2 = Array( 4, 5, 6 )
val arr2 = Array( 4, 5, 6 )
val arr3 = Array( 7, 8, 9 )
val arr3 = Array( 7, 8, 9 )
Line 3,809: Line 3,809:
//or:
//or:
Array concat ( arr1, arr2, arr3 )
Array concat ( arr1, arr2, arr3 )
// res0: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9)</lang>
// res0: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9)</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
<lang scheme>; in r5rs, there is append for lists, but we'll need to define vector-append
<syntaxhighlight lang=scheme>; in r5rs, there is append for lists, but we'll need to define vector-append
(define (vector-append . arg) (list->vector (apply append (map vector->list arg))))
(define (vector-append . arg) (list->vector (apply append (map vector->list arg))))


(vector-append #(1 2 3 4) #(5 6 7) #(8 9 10))
(vector-append #(1 2 3 4) #(5 6 7) #(8 9 10))
; #(1 2 3 4 5 6 7 8 9 10)</lang>
; #(1 2 3 4 5 6 7 8 9 10)</syntaxhighlight>


''Note : vector-append is also defined in [http://srfi.schemers.org/srfi-43/srfi-43.html SRFI-43].''
''Note : vector-append is also defined in [http://srfi.schemers.org/srfi-43/srfi-43.html SRFI-43].''
Line 3,823: Line 3,823:
{{works with|Gauche Scheme}}
{{works with|Gauche Scheme}}


<lang Scheme>
<syntaxhighlight lang=Scheme>
(use gauche.array)
(use gauche.array)


Line 3,849: Line 3,849:
(print-matrix (array-concatenate a b))
(print-matrix (array-concatenate a b))
(print-matrix (array-concatenate a b 1))
(print-matrix (array-concatenate a b 1))
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 3,866: Line 3,866:


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang=seed7>$ include "seed7_05.s7i";


var array integer: a is [] (1, 2, 3, 4);
var array integer: a is [] (1, 2, 3, 4);
Line 3,881: Line 3,881:
end for;
end for;
writeln;
writeln;
end func;</lang>
end func;</syntaxhighlight>


{{out}}
{{out}}
Line 3,887: Line 3,887:


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<lang sensetalk>put (1, 2, 3) into list1
<syntaxhighlight lang=sensetalk>put (1, 2, 3) into list1
put (4, 5, 6) into list2
put (4, 5, 6) into list2
put list1 &&& list2 into list3
put list1 &&& list2 into list3
put list3</lang>
put list3</syntaxhighlight>


=={{header|SETL}}==
=={{header|SETL}}==
<lang haskell>A := [1, 2, 3];
<syntaxhighlight lang=haskell>A := [1, 2, 3];
B := [3, 4, 5];
B := [3, 4, 5];
print(A + B); -- [1 2 3 3 4 5]</lang>
print(A + B); -- [1 2 3 3 4 5]</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var arr1 = [1, 2, 3];
<syntaxhighlight lang=ruby>var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];
var arr2 = [4, 5, 6];
var arr3 = (arr1 + arr2); # => [1, 2, 3, 4, 5, 6]</lang>
var arr3 = (arr1 + arr2); # => [1, 2, 3, 4, 5, 6]</syntaxhighlight>


=={{header|Simula}}==
=={{header|Simula}}==
<lang simula>BEGIN ! Concatenate arrays - of REAL, here;
<syntaxhighlight lang=simula>BEGIN ! Concatenate arrays - of REAL, here;


CLASS REAL_ARRAY(N); INTEGER N;
CLASS REAL_ARRAY(N); INTEGER N;
Line 3,997: Line 3,997:
X.CONCAT(NEW REAL_ARRAY(4)
X.CONCAT(NEW REAL_ARRAY(4)
.linearFill(-1, -3)).out(SYSOUT);
.linearFill(-1, -3)).out(SYSOUT);
END.</lang>
END.</syntaxhighlight>
{{out}}
{{out}}
<pre> 3.00 10.00 17.00 0.00 5.00 10.00 15.00
<pre> 3.00 10.00 17.00 0.00 5.00 10.00 15.00
Line 4,006: Line 4,006:
The binary operation of concatenation is made with the <tt>;</tt> (semi-colon) from the type Sequence. It is also available for appending Sequences to WriteStreams.
The binary operation of concatenation is made with the <tt>;</tt> (semi-colon) from the type Sequence. It is also available for appending Sequences to WriteStreams.


<lang slate>
<syntaxhighlight lang=slate>
{1. 2. 3. 4. 5} ; {6. 7. 8. 9. 10}
{1. 2. 3. 4. 5} ; {6. 7. 8. 9. 10}
</syntaxhighlight>
</lang>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Concatenation (appending) is made with the method <tt>,</tt> (comma), present in classes SequenceableCollection, ArrayedCollection and their subclasses (e.g. Array, String, OrderedCollection ...)
Concatenation (appending) is made with the method <tt>,</tt> (comma), present in classes SequenceableCollection, ArrayedCollection and their subclasses (e.g. Array, String, OrderedCollection ...)


<lang smalltalk>|a b c|
<syntaxhighlight lang=smalltalk>|a b c|
a := #(1 2 3 4 5).
a := #(1 2 3 4 5).
b := #(6 7 8 9 10).
b := #(6 7 8 9 10).
c := a,b.
c := a,b.
c displayNl.</lang>
c displayNl.</syntaxhighlight>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Line 4,025: Line 4,025:
{{works with|CSnobol}}
{{works with|CSnobol}}


<lang SNOBOL4>* # Concatenate 2 arrays (vectors)
<syntaxhighlight lang=SNOBOL4>* # Concatenate 2 arrays (vectors)
define('cat(a1,a2)i,j') :(cat_end)
define('cat(a1,a2)i,j') :(cat_end)
cat cat = array(prototype(a1) + prototype(a2))
cat cat = array(prototype(a1) + prototype(a2))
Line 4,044: Line 4,044:
output = str2
output = str2
output = str3
output = str3
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 4,052: Line 4,052:


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<lang Standard ML>
<syntaxhighlight lang=Standard ML>
val l1 = [1,2,3,4];;
val l1 = [1,2,3,4];;
val l2 = [5,6,7,8];;
val l2 = [5,6,7,8];;
val l3 = l1 @ l2 (* [1,2,3,4,5,6,7,8] *)
val l3 = l1 @ l2 (* [1,2,3,4,5,6,7,8] *)
</syntaxhighlight>
</lang>


=={{header|Stata}}==
=={{header|Stata}}==
===Macro language===
===Macro language===
<lang stata>. matrix a=2,9,4\7,5,3\6,1,8
<syntaxhighlight lang=stata>. matrix a=2,9,4\7,5,3\6,1,8
. matrix list a
. matrix list a


Line 4,097: Line 4,097:
r1 1 0 0
r1 1 0 0
r2 0 1 0
r2 0 1 0
r3 0 0 1</lang>
r3 0 0 1</syntaxhighlight>
=== Mata ===
=== Mata ===
<lang stata>. mata
<syntaxhighlight lang=stata>. mata
: a=2,9,4\7,5,3\6,1,8
: a=2,9,4\7,5,3\6,1,8


Line 4,123: Line 4,123:
+-------------+
+-------------+


: end</lang>
: end</syntaxhighlight>


=={{header|Swift}}==
=={{header|Swift}}==
<lang Swift>let array1 = [1,2,3]
<syntaxhighlight lang=Swift>let array1 = [1,2,3]
let array2 = [4,5,6]
let array2 = [4,5,6]
let array3 = array1 + array2</lang>
let array3 = array1 + array2</syntaxhighlight>


=={{header|Tailspin}}==
=={{header|Tailspin}}==
<lang tailspin>
<syntaxhighlight lang=tailspin>
def a: [1, 2, 3];
def a: [1, 2, 3];
def b: [4, 5, 6];
def b: [4, 5, 6];
[$a..., $b...] -> !OUT::write
[$a..., $b...] -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 4,142: Line 4,142:


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>set a {1 2 3}
<syntaxhighlight lang=tcl>set a {1 2 3}
set b {4 5 6}
set b {4 5 6}
set ab [concat $a $b]; # 1 2 3 4 5 6</lang>
set ab [concat $a $b]; # 1 2 3 4 5 6</syntaxhighlight>
Note that in the Tcl language, “arrays” are hash maps of strings to variables, so the notion of concatenation doesn't really apply. What other languages (usually) call arrays are “lists” in Tcl.
Note that in the Tcl language, “arrays” are hash maps of strings to variables, so the notion of concatenation doesn't really apply. What other languages (usually) call arrays are “lists” in Tcl.


Line 4,177: Line 4,177:


=={{header|Trith}}==
=={{header|Trith}}==
<lang trith>[1 2 3] [4 5 6] concat</lang>
<syntaxhighlight lang=trith>[1 2 3] [4 5 6] concat</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
Line 4,185: Line 4,185:
{{works with|bash}}
{{works with|bash}}


<lang bash>array1=( 1 2 3 4 5 )
<syntaxhighlight lang=bash>array1=( 1 2 3 4 5 )
array2=( 6 7 8 9 10 )
array2=( 6 7 8 9 10 )
botharrays=( ${array1[@]} ${array2[@]} )</lang>
botharrays=( ${array1[@]} ${array2[@]} )</syntaxhighlight>


Whitespace-delimited strings work in much the same way:
Whitespace-delimited strings work in much the same way:
Line 4,193: Line 4,193:
{{works with|bash}}
{{works with|bash}}


<lang bash>array1='1 2 3 4 5'
<syntaxhighlight lang=bash>array1='1 2 3 4 5'
array2='6 7 8 9 10'
array2='6 7 8 9 10'


Line 4,200: Line 4,200:


# Concatenated to a string ...
# Concatenated to a string ...
botharrays_s="$array1 $array2"</lang>
botharrays_s="$array1 $array2"</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
<lang ursa># create two streams (the ursa equivalent of arrays)
<syntaxhighlight lang=ursa># create two streams (the ursa equivalent of arrays)
# a contains the numbers 1-10, b contains 11-20
# a contains the numbers 1-10, b contains 11-20
decl int<> a b
decl int<> a b
Line 4,218: Line 4,218:


# output a to the console
# output a to the console
out a endl console</lang>
out a endl console</syntaxhighlight>


=={{header|Vala}}==
=={{header|Vala}}==
<lang vala>int[] array_concat(int[]a,int[]b){
<syntaxhighlight lang=vala>int[] array_concat(int[]a,int[]b){
int[] c = new int[a.length + b.length];
int[] c = new int[a.length + b.length];
Memory.copy(c, a, a.length * sizeof(int));
Memory.copy(c, a, a.length * sizeof(int));
Line 4,234: Line 4,234:
stdout.printf("%d\n",i);
stdout.printf("%d\n",i);
}
}
}</lang>
}</syntaxhighlight>


=={{header|VBA}}==
=={{header|VBA}}==


<syntaxhighlight lang=vb>
<lang vb>
Option Explicit
Option Explicit


Line 4,264: Line 4,264:
Concat_Array = TmpA1
Concat_Array = TmpA1
End Function
End Function
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>With Array 1 : 1, 2, 3, 4, 5, 24/11/2017, azerty
<pre>With Array 1 : 1, 2, 3, 4, 5, 24/11/2017, azerty
Line 4,272: Line 4,272:


=={{header|VBScript}}==
=={{header|VBScript}}==
<lang vb>Function ArrayConcat(arr1, arr2)
<syntaxhighlight lang=vb>Function ArrayConcat(arr1, arr2)
ReDim ret(UBound(arr1) + UBound(arr2) + 1)
ReDim ret(UBound(arr1) + UBound(arr2) + 1)
For i = 0 To UBound(arr1)
For i = 0 To UBound(arr1)
Line 4,289: Line 4,289:
WScript.Echo "arr2 = array(" & Join(arr2,", ") & ")"
WScript.Echo "arr2 = array(" & Join(arr2,", ") & ")"
arr3 = ArrayConcat(arr1, arr2)
arr3 = ArrayConcat(arr1, arr2)
WScript.Echo "arr1 + arr2 = array(" & Join(arr3,", ") & ")"</lang>
WScript.Echo "arr1 + arr2 = array(" & Join(arr3,", ") & ")"</syntaxhighlight>


{{out}}
{{out}}
Line 4,299: Line 4,299:


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
<lang vbnet>
<syntaxhighlight lang=vbnet>
Dim iArray1() As Integer = {1, 2, 3}
Dim iArray1() As Integer = {1, 2, 3}
Dim iArray2() As Integer = {4, 5, 6}
Dim iArray2() As Integer = {4, 5, 6}
Line 4,305: Line 4,305:


iArray3 = iArray1.Concat(iArray2).ToArray
iArray3 = iArray1.Concat(iArray2).ToArray
</syntaxhighlight>
</lang>


=={{header|Vlang}}==
=={{header|Vlang}}==
V uses a '''<<''' operator for array concatenation. Destination array needs to be mutable.
V uses a '''<<''' operator for array concatenation. Destination array needs to be mutable.


<lang go>// V, array concatenation
<syntaxhighlight lang=go>// V, array concatenation
// Tectonics: v run array-concatenation.v
// Tectonics: v run array-concatenation.v
module main
module main
Line 4,321: Line 4,321:
arr1 << arr2
arr1 << arr2
println(arr1)
println(arr1)
}</lang>
}</syntaxhighlight>


{{out}}<pre>$ v run array-concatenation.v
{{out}}<pre>$ v run array-concatenation.v
Line 4,330: Line 4,330:
Wart doesn't have arrays yet, just lists.
Wart doesn't have arrays yet, just lists.


<lang wart>a <- '(1 2 3)
<syntaxhighlight lang=wart>a <- '(1 2 3)
b <- '(4 5 6)
b <- '(4 5 6)
a+b
a+b
# => (1 2 3 4 5 6)</lang>
# => (1 2 3 4 5 6)</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
<lang ecmascript>var arr1 = [1,2,3]
<syntaxhighlight lang=ecmascript>var arr1 = [1,2,3]
var arr2 = [4,5,6]
var arr2 = [4,5,6]
System.print(arr1 + arr2)</lang>
System.print(arr1 + arr2)</syntaxhighlight>
{{Out}}
{{Out}}
<pre>[1, 2, 3, 4, 5, 6]</pre>
<pre>[1, 2, 3, 4, 5, 6]</pre>


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang Yabasic>sub arrayConcatenation(a(), b())
<syntaxhighlight lang=Yabasic>sub arrayConcatenation(a(), b())
local ta, tb, nt, i
local ta, tb, nt, i
Line 4,378: Line 4,378:
if i < nt print ", ";
if i < nt print ", ";
next i
next i
print</lang>
print</syntaxhighlight>


=={{header|Yacas}}==
=={{header|Yacas}}==
<lang Yacas>Concat({1,2,3}, {4,5,6})
<syntaxhighlight lang=Yacas>Concat({1,2,3}, {4,5,6})


Out> {1, 2, 3, 4, 5, 6}</lang>
Out> {1, 2, 3, 4, 5, 6}</syntaxhighlight>


=={{header|Yorick}}==
=={{header|Yorick}}==
<lang yorick>a = [1,2,3];
<syntaxhighlight lang=yorick>a = [1,2,3];
b = [4,5,6];
b = [4,5,6];
ab = grow(a, b);</lang>
ab = grow(a, b);</syntaxhighlight>


=={{header|Z80 Assembly}}==
=={{header|Z80 Assembly}}==
Line 4,394: Line 4,394:
Credit to Keith of [https://www.chibiakumas.com ChibiAkumas] for creating it.
Credit to Keith of [https://www.chibiakumas.com ChibiAkumas] for creating it.


<lang z80> org $8000
<syntaxhighlight lang=z80> org $8000


ld hl,TestArray1 ; pointer to first array
ld hl,TestArray1 ; pointer to first array
Line 4,424: Line 4,424:
; in the reverse order.
; in the reverse order.
TestArray1:
TestArray1:
byte $aa,$bb,$cc,$dd,$ee,$ff</lang>
byte $aa,$bb,$cc,$dd,$ee,$ff</syntaxhighlight>


{{out}}
{{out}}
Line 4,434: Line 4,434:
=={{header|zkl}}==
=={{header|zkl}}==
Lists (both mutable and read only), no built in support for numeric vectors/arrays/matrices
Lists (both mutable and read only), no built in support for numeric vectors/arrays/matrices
<lang zkl>T(1,2).extend(T(4,5,6)) //-->L(1,2,4,5,6)
<syntaxhighlight lang=zkl>T(1,2).extend(T(4,5,6)) //-->L(1,2,4,5,6)
T(1,2).extend(4,5,6) //-->L(1,2,4,5,6)</lang>
T(1,2).extend(4,5,6) //-->L(1,2,4,5,6)</syntaxhighlight>


=={{header|zonnon}}==
=={{header|zonnon}}==
Line 4,513: Line 4,513:
WriteAry(Concat2(x,y));
WriteAry(Concat2(x,y));
end Main.
end Main.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 4,522: Line 4,522:
=={{header|Zsh}}==
=={{header|Zsh}}==
Concatenating arrays.
Concatenating arrays.
<lang zsh>a=(1 2 3)
<syntaxhighlight lang=zsh>a=(1 2 3)
b=(a b c)
b=(a b c)


c=($a $b)</lang>
c=($a $b)</syntaxhighlight>
Pushing a single element into an array.
Pushing a single element into an array.
<lang zsh>a+=4</lang>
<syntaxhighlight lang=zsh>a+=4</syntaxhighlight>
Pushing another array into an array.
Pushing another array into an array.
<lang zsh>a+=($b)</lang>
<syntaxhighlight lang=zsh>a+=($b)</syntaxhighlight>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
{{trans|Liberty BASIC}}
{{trans|Liberty BASIC}}
<lang zxbasic>10 LET x=10
<syntaxhighlight lang=zxbasic>10 LET x=10
20 LET y=20
20 LET y=20
30 DIM a(x)
30 DIM a(x)
Line 4,547: Line 4,547:
130 PRINT c(i);", ";
130 PRINT c(i);", ";
140 NEXT i
140 NEXT i
</syntaxhighlight>
</lang>