Array concatenation: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 1: Line 1:
{{task|Data Structures}}
[[Category:Simple]]
[[Category:Simple]]
{{task|Data Structures}}
;Task:
;Task:
Line 10: Line 10:


=={{header|11l}}==
=={{header|11l}}==
<syntaxhighlight 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)</syntaxhighlight>
print(arr1 [+] arr2)</syntaxhighlight>
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.


<syntaxhighlight 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 46: Line 46:


=={{header|8th}}==
=={{header|8th}}==
<syntaxhighlight lang=Forth>
<syntaxhighlight lang="forth">
[1,2,3] [4,5,6] a:+ .
[1,2,3] [4,5,6] a:+ .
</syntaxhighlight>
</syntaxhighlight>
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}}
<syntaxhighlight 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 163: Line 163:
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.


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


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.
<syntaxhighlight lang=Lisp>(append xs ys)</syntaxhighlight>
<syntaxhighlight lang="lisp">(append xs ys)</syntaxhighlight>


=={{header|Action!}}==
=={{header|Action!}}==
<syntaxhighlight 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 249: Line 249:


=={{header|ActionScript}}==
=={{header|ActionScript}}==
<syntaxhighlight 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]</syntaxhighlight>
var array3:Array = array1.concat(array2); //[1, 2, 3, 4, 5, 6]</syntaxhighlight>
Line 255: Line 255:
=={{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:
<syntaxhighlight 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)</syntaxhighlight>
Y : T := X & (4, 5, 6); -- Concatenate X and (4, 5, 6)</syntaxhighlight>


=={{header|Aime}}==
=={{header|Aime}}==
<syntaxhighlight lang=aime>ac(list a, b)
<syntaxhighlight lang="aime">ac(list a, b)
{
{
list o;
list o;
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:
<syntaxhighlight lang=Algol68>MODE ARGTYPE = INT;
<syntaxhighlight lang="algol68">MODE ARGTYPE = INT;
MODE ARGLIST = FLEX[0]ARGTYPE;
MODE ARGLIST = FLEX[0]ARGTYPE;


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.
<syntaxhighlight 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 373: Line 373:


=={{header|Amazing Hopper}}==
=={{header|Amazing Hopper}}==
<syntaxhighlight lang=Amazing Hopper>
<syntaxhighlight lang="amazing hopper">
#include <hbasic.h>
#include <hbasic.h>
Begin
Begin
Line 389: Line 389:


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


=={{header|Apex}}==
=={{header|Apex}}==
<syntaxhighlight 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);
Line 400: Line 400:


=={{header|APL}}==
=={{header|APL}}==
<syntaxhighlight 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
Line 406: Line 406:


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<syntaxhighlight 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}
Line 422: Line 422:
{{trans|JavaScript}}
{{trans|JavaScript}}


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


concat([["alpha", "beta", "gamma"], ¬
concat([["alpha", "beta", "gamma"], ¬
Line 448: Line 448:
=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang=ARM Assembly>
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
/* program concAreaString.s */
/* program concAreaString.s */
Line 623: Line 623:


=={{header|Arturo}}==
=={{header|Arturo}}==
<syntaxhighlight lang=rebol>arr1: [1 2 3]
<syntaxhighlight lang="rebol">arr1: [1 2 3]
arr2: ["four" "five" "six"]
arr2: ["four" "five" "six"]
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''.


<syntaxhighlight 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 772: Line 772:
=== True Arrays ===
=== True Arrays ===
{{works with|AutoHotkey_L}}
{{works with|AutoHotkey_L}}
<syntaxhighlight 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 792: Line 792:
=== 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:
<syntaxhighlight lang=AutoHotkey>List1 = 1,2,3
<syntaxhighlight lang="autohotkey">List1 = 1,2,3
List2 = 4,5,6
List2 = 4,5,6


Line 838: Line 838:


<syntaxhighlight 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 860: Line 860:


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


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight 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 884: Line 884:


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


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


=={{header|bash}}==
=={{header|bash}}==
<syntaxhighlight 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 902: Line 902:
=={{header|BASIC}}==
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<syntaxhighlight 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 910: Line 910:
70 FOR I = 1 TO X + Y: PRINT MID$ (" ",1,I > 1)C(I - 1);: NEXT</syntaxhighlight>
70 FOR I = 1 TO X + Y: PRINT MID$ (" ",1,I > 1)C(I - 1);: NEXT</syntaxhighlight>
==={{header|BaCon}}===
==={{header|BaCon}}===
<syntaxhighlight 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 922: Line 922:
==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<syntaxhighlight 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 944: Line 944:
==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
(Based on ZX Spectrum BASIC version)
(Based on ZX Spectrum BASIC version)
<syntaxhighlight 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 963: Line 963:


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


Line 1,004: Line 1,004:


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


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


<syntaxhighlight 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}
Line 1,035: Line 1,035:
=={{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)
<syntaxhighlight 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,069: Line 1,069:


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


namespace RosettaCode
namespace RosettaCode
Line 1,095: Line 1,095:


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


class Program
class Program
Line 1,109: Line 1,109:


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


Line 1,127: Line 1,127:
Similar to above but using initialization schematics.
Similar to above but using initialization schematics.


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


Line 1,143: Line 1,143:
This is another solution with function level templates and pointers.
This is another solution with function level templates and pointers.


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


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


=={{header|Ceylon}}==
=={{header|Ceylon}}==
<syntaxhighlight 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};
Line 1,203: Line 1,203:


=={{header|Clojure}}==
=={{header|Clojure}}==
<syntaxhighlight lang=clojure>(concat [1 2 3] [4 5 6])</syntaxhighlight>
<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
<syntaxhighlight lang=clojure>(into [1 2 3] [4 5 6])</syntaxhighlight>
<syntaxhighlight lang="clojure">(into [1 2 3] [4 5 6])</syntaxhighlight>


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


Line 1,273: Line 1,273:


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
<syntaxhighlight lang=coffeescript>
<syntaxhighlight lang="coffeescript">
# like in JavaScript
# like in JavaScript
a = [1, 2, 3]
a = [1, 2, 3]
Line 1,282: Line 1,282:
=={{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.
<syntaxhighlight 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)</syntaxhighlight>
=> #(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]


<syntaxhighlight 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,310: Line 1,310:
=={{header|Component Pascal}}==
=={{header|Component Pascal}}==
BlackBox Component Builder
BlackBox Component Builder
<syntaxhighlight lang=oberon2>
<syntaxhighlight lang="oberon2">
MODULE ArrayConcat;
MODULE ArrayConcat;
IMPORT StdLog;
IMPORT StdLog;
Line 1,377: Line 1,377:


=={{header|Crystal}}==
=={{header|Crystal}}==
<syntaxhighlight 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"]</syntaxhighlight>
arr1 + arr2 #=> [1, 2, 3, "foo", "bar", "baz"]</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<syntaxhighlight lang=d>import std.stdio: writeln;
<syntaxhighlight lang="d">import std.stdio: writeln;
void main() {
void main() {
Line 1,395: Line 1,395:
=={{header|Delphi}}==
=={{header|Delphi}}==
2022/07/13
2022/07/13
<syntaxhighlight 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,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.
<syntaxhighlight 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,507: Line 1,507:


=={{header|Diego}}==
=={{header|Diego}}==
<syntaxhighlight 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,519: Line 1,519:
=={{header|Dyalect}}==
=={{header|Dyalect}}==


<syntaxhighlight 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)
Line 1,530: Line 1,530:
=={{header|E}}==
=={{header|E}}==


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


=={{header|EasyLang}}==
=={{header|EasyLang}}==


<lang>a[] = [ 1 2 3 ]
<syntaxhighlight lang="text">a[] = [ 1 2 3 ]
b[] = [ 4 5 6 ]
b[] = [ 4 5 6 ]
c[] = a[]
c[] = a[]
Line 1,546: Line 1,546:
=={{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).
<syntaxhighlight 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,565: Line 1,565:
=={{header|ECL}}==
=={{header|ECL}}==


<lang>
<syntaxhighlight lang="text">
A := [1, 2, 3, 4];
A := [1, 2, 3, 4];
B := [5, 6, 7, 8];
B := [5, 6, 7, 8];
Line 1,575: Line 1,575:
using the ++ operator and the lists.append function
using the ++ operator and the lists.append function


<syntaxhighlight lang=efene>
<syntaxhighlight lang="efene">
@public
@public
run = fn () {
run = fn () {
Line 1,590: Line 1,590:
=={{header|EGL}}==
=={{header|EGL}}==
{{works with|EDT}}
{{works with|EDT}}
<syntaxhighlight lang=EGL>
<syntaxhighlight lang="egl">
program ArrayConcatenation
program ArrayConcatenation
function main()
function main()
Line 1,607: Line 1,607:


=={{header|Ela}}==
=={{header|Ela}}==
<syntaxhighlight lang=ela>xs = [1,2,3]
<syntaxhighlight lang="ela">xs = [1,2,3]
ys = [4,5,6]
ys = [4,5,6]
xs ++ ys</syntaxhighlight>
xs ++ ys</syntaxhighlight>
Line 1,614: Line 1,614:
=={{header|Elena}}==
=={{header|Elena}}==
ELENA 5.0 :
ELENA 5.0 :
<syntaxhighlight lang=elena>import extensions;
<syntaxhighlight lang="elena">import extensions;


public program()
public program()
Line 1,631: Line 1,631:


=={{header|Elixir}}==
=={{header|Elixir}}==
<syntaxhighlight 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]])
Line 1,639: Line 1,639:


=={{header|Elm}}==
=={{header|Elm}}==
<syntaxhighlight 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,662: Line 1,662:
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.


<syntaxhighlight 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]</syntaxhighlight>
=> [1 2 3 4 5 6 7 8 9]</syntaxhighlight>


Line 1,670: Line 1,670:


On the shell,
On the shell,
<syntaxhighlight 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,679: Line 1,679:


=={{header|ERRE}}==
=={{header|ERRE}}==
<lang>
<syntaxhighlight lang="text">
PROGRAM ARRAY_CONCAT
PROGRAM ARRAY_CONCAT


Line 1,714: Line 1,714:


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<syntaxhighlight 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}
Line 1,725: Line 1,725:
=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
Array concatenation.
Array concatenation.
<syntaxhighlight 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</syntaxhighlight>
let c = Array.append a b</syntaxhighlight>
List concatenation (@ and List.append are equivalent).
List concatenation (@ and List.append are equivalent).
<syntaxhighlight 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
Line 1,735: Line 1,735:


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


'''Example''':
'''Example''':
<syntaxhighlight 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 }</syntaxhighlight>
{ 1 2 3 4 }</syntaxhighlight>
Line 1,746: Line 1,746:
In fansh:
In fansh:


<syntaxhighlight lang=fantom>
<syntaxhighlight lang="fantom">
> a := [1,2,3]
> a := [1,2,3]
> b := [4,5,6]
> b := [4,5,6]
Line 1,758: Line 1,758:
=={{header|FBSL}}==
=={{header|FBSL}}==
Array concatenation:
Array concatenation:
<syntaxhighlight 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,772: Line 1,772:


=={{header|Forth}}==
=={{header|Forth}}==
<syntaxhighlight 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,789: Line 1,789:
=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
{{works with|Fortran|90 and later}}
<syntaxhighlight lang=fortran>program Concat_Arrays
<syntaxhighlight lang="fortran">program Concat_Arrays
implicit none
implicit none


Line 1,809: Line 1,809:
=={{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>).
<syntaxhighlight lang=pascal> array2 := array0 + array1</syntaxhighlight>
<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:
<syntaxhighlight lang=pascal> array2 := concat(array0, array1);</syntaxhighlight>
<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}}==
<syntaxhighlight lang=freebasic>
<syntaxhighlight lang="freebasic">
' FB 1.05.0 Win64
' FB 1.05.0 Win64


Line 1,850: Line 1,850:


=={{header|Frink}}==
=={{header|Frink}}==
<syntaxhighlight lang=frink>
<syntaxhighlight lang="frink">
a = [1,2]
a = [1,2]
b = [3,4]
b = [3,4]
Line 1,857: Line 1,857:


=={{header|FunL}}==
=={{header|FunL}}==
<syntaxhighlight 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] )
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:


<syntaxhighlight lang=Futhark>
<syntaxhighlight lang="futhark">
concat as bs cd
concat as bs cd
</syntaxhighlight>
</syntaxhighlight>
Line 1,879: Line 1,879:
=={{header|FutureBasic}}==
=={{header|FutureBasic}}==


<syntaxhighlight 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,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]'''
<syntaxhighlight 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,926: Line 1,926:


=={{header|GAP}}==
=={{header|GAP}}==
<syntaxhighlight 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,938: Line 1,938:


=={{header|Genie}}==
=={{header|Genie}}==
<syntaxhighlight lang=genie>[indent=4]
<syntaxhighlight lang="genie">[indent=4]
/*
/*
Array concatenation, in Genie
Array concatenation, in Genie
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:
<syntaxhighlight 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,990: Line 1,990:
</syntaxhighlight>
</syntaxhighlight>
The macro can be used like this:
The macro can be used like this:
<syntaxhighlight 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();
Line 1,996: Line 1,996:


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


import "fmt"
import "fmt"
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.
<syntaxhighlight lang=go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 2,103: Line 2,103:
=={{header|Gosu}}==
=={{header|Gosu}}==


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


Test:
Test:
<syntaxhighlight lang=groovy>println list</syntaxhighlight>
<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 ++:
<syntaxhighlight lang=haskell>(++) :: [a] -> [a] -> [a]</syntaxhighlight>
<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:
<syntaxhighlight lang=haskell>
<syntaxhighlight lang="haskell">
[] ++ x = x
[] ++ x = x
(h:t) ++ y = h : (t ++ y)
(h:t) ++ y = h : (t ++ y)
</syntaxhighlight>
</syntaxhighlight>
or folding
or folding
<syntaxhighlight lang=haskell>
<syntaxhighlight lang="haskell">
x ++ y = foldr (:) y x
x ++ y = foldr (:) y x
</syntaxhighlight>
</syntaxhighlight>


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


c = a
c = a
Line 2,149: Line 2,149:


=={{header|Hy}}==
=={{header|Hy}}==
<syntaxhighlight 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,166: Line 2,166:


=={{header|i}}==
=={{header|i}}==
<syntaxhighlight lang=i>main
<syntaxhighlight lang="i">main
a $= [1, 2, 3]
a $= [1, 2, 3]
b $= [4, 5, 6]
b $= [4, 5, 6]
Line 2,175: Line 2,175:
=={{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.
<syntaxhighlight lang=icon>
<syntaxhighlight lang="icon">
procedure main()
procedure main()
L1 := [1, 2, 3, 4]
L1 := [1, 2, 3, 4]
Line 2,191: Line 2,191:


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:
<syntaxhighlight lang=IDL>
<syntaxhighlight lang="idl">
> a = [1,2,3]
> a = [1,2,3]
> b = [4,5,6]
> b = [4,5,6]
Line 2,204: Line 2,204:
</syntaxhighlight>
</syntaxhighlight>
Then they can be concatenated "at the ends":
Then they can be concatenated "at the ends":
<syntaxhighlight lang=IDL>
<syntaxhighlight lang="idl">
> help,[a,b]
> help,[a,b]
<Expression> INT = Array[6]
<Expression> INT = Array[6]
Line 2,211: Line 2,211:
</syntaxhighlight>
</syntaxhighlight>
or "at the sides":
or "at the sides":
<syntaxhighlight lang=IDL>
<syntaxhighlight lang="idl">
> help,[[a],[b]]
> help,[[a],[b]]
<Expression> INT = Array[3, 2]
<Expression> INT = Array[3, 2]
Line 2,219: Line 2,219:
</syntaxhighlight>
</syntaxhighlight>
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:
<syntaxhighlight lang=IDL>
<syntaxhighlight lang="idl">
> b = transpose(b)
> b = transpose(b)
> help,b
> help,b
Line 2,245: Line 2,245:


=={{header|Inform 7}}==
=={{header|Inform 7}}==
<syntaxhighlight 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;</syntaxhighlight>
add B to A;</syntaxhighlight>


=={{header|Ioke}}==
=={{header|Ioke}}==
<syntaxhighlight 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]</syntaxhighlight>
+> [1, 2, 3, 3, 2, 1]</syntaxhighlight>
Line 2,258: Line 2,258:


'''Example''':
'''Example''':
<syntaxhighlight 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
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.


<syntaxhighlight lang=j> ]ab=: 3 3 $ 'aaabbbccc'
<syntaxhighlight lang="j"> ]ab=: 3 3 $ 'aaabbbccc'
aaa
aaa
bbb
bbb
Line 2,302: Line 2,302:


=={{header|Java}}==
=={{header|Java}}==
<syntaxhighlight 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,313: Line 2,313:
=={{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).
<syntaxhighlight 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]</syntaxhighlight>
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.


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


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 "+". <syntaxhighlight 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]
Line 2,356: Line 2,356:


=={{header|Julia}}==
=={{header|Julia}}==
<syntaxhighlight 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,367: Line 2,367:


=={{header|K}}==
=={{header|K}}==
<syntaxhighlight lang=K>
<syntaxhighlight lang="k">
a: 1 2 3
a: 1 2 3
b: 4 5 6
b: 4 5 6
Line 2,375: Line 2,375:
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>
<syntaxhighlight lang="k">
ab:3 3#"abcdefghi"
ab:3 3#"abcdefghi"
("abc"
("abc"
Line 2,410: Line 2,410:


=={{header|Klingphix}}==
=={{header|Klingphix}}==
<syntaxhighlight 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
Line 2,419: Line 2,419:


=={{header|Klong}}==
=={{header|Klong}}==
<syntaxhighlight lang=K>
<syntaxhighlight 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,432: Line 2,432:
=={{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:
<syntaxhighlight 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
Line 2,440: Line 2,440:


Alternatively, we can write our own concatenation function:
Alternatively, we can write our own concatenation function:
<syntaxhighlight 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] })
}</syntaxhighlight>
}</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:
<syntaxhighlight 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
Line 2,457: Line 2,457:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<syntaxhighlight 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]
Line 2,464: Line 2,464:


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


=={{header|langur}}==
=={{header|langur}}==
<syntaxhighlight 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
Line 2,476: Line 2,476:


=={{header|Lasso}}==
=={{header|Lasso}}==
<syntaxhighlight 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,491: Line 2,491:


=={{header|LFE}}==
=={{header|LFE}}==
<syntaxhighlight 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)
Line 2,499: Line 2,499:


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<syntaxhighlight lang=lb> x=10
<syntaxhighlight lang="lb"> x=10
y=20
y=20
dim array1(x)
dim array1(x)
Line 2,521: Line 2,521:
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.


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


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


include "sys.m";
include "sys.m";
Line 2,562: Line 2,562:


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


Line 2,573: Line 2,573:


=={{header|Little}}==
=={{header|Little}}==
<syntaxhighlight 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};
Line 2,582: Line 2,582:
=={{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.
<syntaxhighlight 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
Line 2,590: Line 2,590:


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


Line 2,604: Line 2,604:


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<syntaxhighlight 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)
Line 2,613: Line 2,613:
Adding 2 dimension arrays
Adding 2 dimension arrays


<syntaxhighlight 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,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.
<syntaxhighlight 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,665: Line 2,665:
</syntaxhighlight>
</syntaxhighlight>
Of course, the order of the arguments is important.
Of course, the order of the arguments is important.
<syntaxhighlight lang=Maple>
<syntaxhighlight lang="maple">
> ArrayTools:-Concatenate( 1, A, M );
> ArrayTools:-Concatenate( 1, A, M );
[1 2 3]
[1 2 3]
Line 2,674: Line 2,674:
</syntaxhighlight>
</syntaxhighlight>
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.
<syntaxhighlight lang=Maple>
<syntaxhighlight lang="maple">
> L1 := [ 1, 2, 3 ];
> L1 := [ 1, 2, 3 ];
L1 := [1, 2, 3]
L1 := [1, 2, 3]
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.


<syntaxhighlight 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,721: Line 2,721:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight 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}</syntaxhighlight>
-> {1, 2, 3, 4, 5, 6}</syntaxhighlight>
Line 2,727: Line 2,727:
=={{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.
<syntaxhighlight 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,738: Line 2,738:


For concatenation along higher dimensions, use cat():
For concatenation along higher dimensions, use cat():
<syntaxhighlight 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);
Line 2,746: Line 2,746:


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang>u: [1, 2, 3, 4]$
<syntaxhighlight lang="text">u: [1, 2, 3, 4]$
v: [5, 6, 7, 8, 9, 10]$
v: [5, 6, 7, 8, 9, 10]$
append(u, v);
append(u, v);
Line 2,772: Line 2,772:
=={{header|Mercury}}==
=={{header|Mercury}}==


<syntaxhighlight lang=Mercury>A `append` B = C</syntaxhighlight>
<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}}
<syntaxhighlight lang=min>(1 2 3) (4 "apple" 6) concat print</syntaxhighlight>
<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}}==
<syntaxhighlight lang=MiniScript>
<syntaxhighlight lang="miniscript">
arrOne = [1, 2, 3]
arrOne = [1, 2, 3]
arrTwo = [4, 5, 6]
arrTwo = [4, 5, 6]
Line 2,793: Line 2,793:
=={{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.
<syntaxhighlight lang=Nanoquery>a + b</syntaxhighlight>
<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}}==
<syntaxhighlight lang=ActionScript>/*
<syntaxhighlight lang="actionscript">/*
Array concatenation, in Neko
Array concatenation, in Neko
*/
*/
Line 2,820: Line 2,820:


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


Line 2,835: Line 2,835:
=={{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.
<syntaxhighlight lang=netrexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref nobinary
options replace format comments java crossref nobinary


Line 2,879: Line 2,879:


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<syntaxhighlight 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,905: Line 2,905:
Examples tested to work with Q'Nial7
Examples tested to work with Q'Nial7


<syntaxhighlight lang=Nial> a:= 1 2 3
<syntaxhighlight lang="nial"> a:= 1 2 3
+-+-+-+
+-+-+-+
|1|2|3|
|1|2|3|
Line 2,916: Line 2,916:
Table of lists:
Table of lists:


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


+-------+-------+
+-------+-------+
Line 2,926: Line 2,926:
Simple concatenation of two arrays/lists:
Simple concatenation of two arrays/lists:


<syntaxhighlight lang=Nial> link a b
<syntaxhighlight lang="nial"> link a b
+-+-+-+-+-+-+
+-+-+-+-+-+-+
|1|2|3|4|5|6|
|1|2|3|4|5|6|
Line 2,933: Line 2,933:
Convert list of lists to table:
Convert list of lists to table:


<syntaxhighlight lang=Nial> mix a b
<syntaxhighlight lang="nial"> mix a b
+-+-+-+
+-+-+-+
|1|2|3|
|1|2|3|
Line 2,941: Line 2,941:


Interchange levels of a list of lists:
Interchange levels of a list of lists:
<syntaxhighlight lang=Nial> pack a b
<syntaxhighlight lang="nial"> pack a b
+-----+-----+-----+
+-----+-----+-----+
|+-+-+|+-+-+|+-+-+|
|+-+-+|+-+-+|+-+-+|
Line 2,950: Line 2,950:
=={{header|Nim}}==
=={{header|Nim}}==
Dynamic sized Sequences can simply be concatenated:
Dynamic sized Sequences can simply be concatenated:
<syntaxhighlight 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]
Line 2,956: Line 2,956:


Static sized Arrays:
Static sized Arrays:
<syntaxhighlight 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,965: Line 2,965:


=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
<syntaxhighlight lang=oberon2>
<syntaxhighlight lang="oberon2">
MODULE ArrayConcat;
MODULE ArrayConcat;
IMPORT
IMPORT
Line 3,023: Line 3,023:


=={{header|Objeck}}==
=={{header|Objeck}}==
<syntaxhighlight lang=objeck>
<syntaxhighlight lang="objeck">
bundle Default {
bundle Default {
class Arithmetic {
class Arithmetic {
Line 3,059: Line 3,059:
=={{header|Objective-C}}==
=={{header|Objective-C}}==
with immutable arrays:
with immutable arrays:
<syntaxhighlight 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];</syntaxhighlight>
NSArray *arr3 = [arr1 arrayByAddingObjectsFromArray:arr2];</syntaxhighlight>


or adding onto a mutable array:
or adding onto a mutable array:
<syntaxhighlight 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];
Line 3,071: Line 3,071:
=={{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:
<syntaxhighlight 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];;
Line 3,079: Line 3,079:


If you want to use arrays:
If you want to use arrays:
<syntaxhighlight 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|];;
Line 3,088: Line 3,088:
=={{header|Oforth}}==
=={{header|Oforth}}==


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


[1, 2, 3 ] [ 4, 5, 6, 7 ] + </syntaxhighlight>
[1, 2, 3 ] [ 4, 5, 6, 7 ] + </syntaxhighlight>
Line 3,094: Line 3,094:
=={{header|Onyx}}==
=={{header|Onyx}}==


<syntaxhighlight 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,109: Line 3,109:


=={{header|ooRexx}}==
=={{header|ooRexx}}==
<syntaxhighlight 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)
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.
<syntaxhighlight 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,131: Line 3,131:


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


Line 3,158: Line 3,158:
=={{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.
<syntaxhighlight 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]


Line 3,165: Line 3,165:


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<syntaxhighlight lang=parigp>concat(u,v)</syntaxhighlight>
<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:
<syntaxhighlight 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);</syntaxhighlight>
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:
<syntaxhighlight 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;
Line 3,184: Line 3,184:
=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/basics}}
<!--<syntaxhighlight 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
Line 3,194: Line 3,194:


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<syntaxhighlight lang=Phixmonti>1.0 "Hello" 3 2 / 4 2.1 power 4 tolist 5 6 7 8 4 tolist chain print</syntaxhighlight>
<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
<syntaxhighlight 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</syntaxhighlight>
( 1.0 "Hello" 3 2 / 4 2.1 power ) ( 5 6 7 8 ) chain print</syntaxhighlight>


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


<syntaxhighlight 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);</syntaxhighlight>
$arr3 = array_merge($arr1, $arr2);</syntaxhighlight>
Line 3,210: Line 3,210:
and back again with to_array/1.
and back again with to_array/1.


<syntaxhighlight 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,232: Line 3,232:


There are destructive concatenations:
There are destructive concatenations:
<syntaxhighlight 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'
Line 3,239: Line 3,239:
-> (1 2 3 a b c) # Side effect: List in 'A' is modified!</syntaxhighlight>
-> (1 2 3 a b c) # Side effect: List in 'A' is modified!</syntaxhighlight>
and non-destructive concatenations:
and non-destructive concatenations:
<syntaxhighlight 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,249: Line 3,249:


=={{header|Pike}}==
=={{header|Pike}}==
<syntaxhighlight 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});
Line 3,258: Line 3,258:
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:
<syntaxhighlight 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;
Line 3,265: Line 3,265:
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.
<lang>
<syntaxhighlight lang="text">
declare x(m+n) fixed;
declare x(m+n) fixed;
declare b(m) fixed defined x;
declare b(m) fixed defined x;
Line 3,276: Line 3,276:
are used in the declarations, the bounds can be dynamic.
are used in the declarations, the bounds can be dynamic.
Matrix B is extended by placing matrix C on its diagonal:
Matrix B is extended by placing matrix C on its diagonal:
<lang>
<syntaxhighlight lang="text">
declare a(5,6) fixed;
declare a(5,6) fixed;
declare b(3,4) fixed defined a(1sub, 2sub);
declare b(3,4) fixed defined a(1sub, 2sub);
Line 3,293: Line 3,293:
</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}
<lang>
<syntaxhighlight lang="text">
Please type elements for a 3 x 4 matrix:
Please type elements for a 3 x 4 matrix:


Line 3,311: Line 3,311:


=={{header|Pony}}==
=={{header|Pony}}==
<syntaxhighlight lang=pony>
<syntaxhighlight lang="pony">
actor Main
actor Main
new create(env:Env)=>
new create(env:Env)=>
Line 3,330: Line 3,330:
=={{header|PostScript}}==
=={{header|PostScript}}==
{{libheader|initlib}}
{{libheader|initlib}}
<syntaxhighlight lang=postscript>
<syntaxhighlight lang="postscript">
[1 2 3 4] [5 6 7 8] concat
[1 2 3 4] [5 6 7 8] concat
</syntaxhighlight>
</syntaxhighlight>


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


Line 3,342: Line 3,342:


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


Line 3,349: Line 3,349:


=={{header|Prolog}}==
=={{header|Prolog}}==
<syntaxhighlight 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].
Line 3,355: Line 3,355:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<syntaxhighlight 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,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.
<syntaxhighlight 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,419: Line 3,419:


Note: list.extend is normally accomplished using the += operator like this:
Note: list.extend is normally accomplished using the += operator like this:
<syntaxhighlight 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
Line 3,425: Line 3,425:


=={{header|Q}}==
=={{header|Q}}==
<syntaxhighlight lang=q>list1:1 2 3
<syntaxhighlight lang="q">list1:1 2 3
list2:4 5 6
list2:4 5 6
list1,list2</syntaxhighlight>
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}}
<syntaxhighlight 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,465: Line 3,465:
=={{header|QB64}}==
=={{header|QB64}}==


<syntaxhighlight lang=QB64>
<syntaxhighlight lang="qb64">


Dim As Integer First, Second
Dim As Integer First, Second
Line 3,538: Line 3,538:
=={{header|R}}==
=={{header|R}}==


<syntaxhighlight lang=R>
<syntaxhighlight lang="r">
a1 <- c(1, 2, 3)
a1 <- c(1, 2, 3)
a2 <- c(3, 4, 5)
a2 <- c(3, 4, 5)
Line 3,545: Line 3,545:


=={{header|Racket}}==
=={{header|Racket}}==
<syntaxhighlight 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>
</syntaxhighlight>
Line 3,556: Line 3,556:
(formerly Perl 6)
(formerly Perl 6)
{{works with|Rakudo|2018.06}}
{{works with|Rakudo|2018.06}}
<syntaxhighlight lang=perl6>my @array1 = 1, 2, 3;
<syntaxhighlight lang="raku" line>my @array1 = 1, 2, 3;
my @array2 = 4, 5, 6;
my @array2 = 4, 5, 6;


Line 3,580: Line 3,580:


=={{header|RapidQ}}==
=={{header|RapidQ}}==
<syntaxhighlight lang=vb>
<syntaxhighlight 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,590: Line 3,590:


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


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


=={{header|Red}}==
=={{header|Red}}==
<syntaxhighlight 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,620: Line 3,620:


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


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


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


Consider:
Consider:
<syntaxhighlight lang=rexx>a.1 = 10
<syntaxhighlight lang="rexx">a.1 = 10
a.2 = 22.7
a.2 = 22.7
a.7 = -12</syntaxhighlight>
a.7 = -12</syntaxhighlight>
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:'''
<syntaxhighlight 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,654: Line 3,654:
fact.8=40320</syntaxhighlight>
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.
<syntaxhighlight 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,706: Line 3,706:


=={{header|Ring}}==
=={{header|Ring}}==
<syntaxhighlight lang=ring>
<syntaxhighlight lang="ring">
arr1 = [1, 2, 3]
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr2 = [4, 5, 6]
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:
<syntaxhighlight lang=RLaB>
<syntaxhighlight lang="rlab">
>> x = [1, 2, 3]
>> x = [1, 2, 3]
>> y = [4, 5, 6]
>> y = [4, 5, 6]
Line 3,739: Line 3,739:
=={{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.
<syntaxhighlight 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]
Line 3,746: Line 3,746:


Or use flatten(1):
Or use flatten(1):
<syntaxhighlight lang=ruby>
<syntaxhighlight lang="ruby">
# concat multiple arrays:
# concat multiple arrays:
[arr1,arr2,arr3].flatten(1)
[arr1,arr2,arr3].flatten(1)
Line 3,754: Line 3,754:


=={{header|Rust}}==
=={{header|Rust}}==
<syntaxhighlight 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,773: Line 3,773:
Or, with iterators:
Or, with iterators:


<syntaxhighlight 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()
}
}
Line 3,779: Line 3,779:


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


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:
<syntaxhighlight lang=S-lang>c = [a, b];</syntaxhighlight>
<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:
<syntaxhighlight 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);</syntaxhighlight>
c = list_concat(a, b);</syntaxhighlight>


or list_join():
or list_join():
<syntaxhighlight lang=S-lang>list_join(a, b);</syntaxhighlight>
<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
<syntaxhighlight lang=SASL>(1 2 3) ++ (4 5 6)</syntaxhighlight>
<syntaxhighlight lang="sasl">(1 2 3) ++ (4 5 6)</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<syntaxhighlight 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,812: Line 3,812:


=={{header|Scheme}}==
=={{header|Scheme}}==
<syntaxhighlight 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))))


Line 3,823: Line 3,823:
{{works with|Gauche Scheme}}
{{works with|Gauche Scheme}}


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


Line 3,866: Line 3,866:


=={{header|Seed7}}==
=={{header|Seed7}}==
<syntaxhighlight 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,887: Line 3,887:


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<syntaxhighlight 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
Line 3,893: Line 3,893:


=={{header|SETL}}==
=={{header|SETL}}==
<syntaxhighlight 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]</syntaxhighlight>
print(A + B); -- [1 2 3 3 4 5]</syntaxhighlight>


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


=={{header|Simula}}==
=={{header|Simula}}==
<syntaxhighlight 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 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.


<syntaxhighlight 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>
</syntaxhighlight>
Line 4,013: Line 4,013:
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 ...)


<syntaxhighlight 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).
Line 4,025: Line 4,025:
{{works with|CSnobol}}
{{works with|CSnobol}}


<syntaxhighlight 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,052: Line 4,052:


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<syntaxhighlight 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];;
Line 4,060: Line 4,060:
=={{header|Stata}}==
=={{header|Stata}}==
===Macro language===
===Macro language===
<syntaxhighlight 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,099: Line 4,099:
r3 0 0 1</syntaxhighlight>
r3 0 0 1</syntaxhighlight>
=== Mata ===
=== Mata ===
<syntaxhighlight 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,126: Line 4,126:


=={{header|Swift}}==
=={{header|Swift}}==
<syntaxhighlight 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</syntaxhighlight>
let array3 = array1 + array2</syntaxhighlight>


=={{header|Tailspin}}==
=={{header|Tailspin}}==
<syntaxhighlight 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];
Line 4,142: Line 4,142:


=={{header|Tcl}}==
=={{header|Tcl}}==
<syntaxhighlight 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</syntaxhighlight>
set ab [concat $a $b]; # 1 2 3 4 5 6</syntaxhighlight>
Line 4,177: Line 4,177:


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


<syntaxhighlight 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[@]} )</syntaxhighlight>
botharrays=( ${array1[@]} ${array2[@]} )</syntaxhighlight>
Line 4,193: Line 4,193:
{{works with|bash}}
{{works with|bash}}


<syntaxhighlight 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,203: Line 4,203:


=={{header|Ursa}}==
=={{header|Ursa}}==
<syntaxhighlight 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,221: Line 4,221:


=={{header|Vala}}==
=={{header|Vala}}==
<syntaxhighlight 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,238: Line 4,238:
=={{header|VBA}}==
=={{header|VBA}}==


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


Line 4,272: Line 4,272:


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight 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,299: Line 4,299:


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
<syntaxhighlight 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,310: Line 4,310:
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.


<syntaxhighlight 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,330: Line 4,330:
Wart doesn't have arrays yet, just lists.
Wart doesn't have arrays yet, just lists.


<syntaxhighlight 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
Line 4,336: Line 4,336:


=={{header|Wren}}==
=={{header|Wren}}==
<syntaxhighlight 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)</syntaxhighlight>
System.print(arr1 + arr2)</syntaxhighlight>
Line 4,343: Line 4,343:


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<syntaxhighlight 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,381: Line 4,381:


=={{header|Yacas}}==
=={{header|Yacas}}==
<syntaxhighlight 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}</syntaxhighlight>
Out> {1, 2, 3, 4, 5, 6}</syntaxhighlight>


=={{header|Yorick}}==
=={{header|Yorick}}==
<syntaxhighlight 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);</syntaxhighlight>
ab = grow(a, b);</syntaxhighlight>
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.


<syntaxhighlight 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,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
<syntaxhighlight 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)</syntaxhighlight>
T(1,2).extend(4,5,6) //-->L(1,2,4,5,6)</syntaxhighlight>


=={{header|zonnon}}==
=={{header|zonnon}}==
<lang>
<syntaxhighlight lang="text">
module Main;
module Main;
import
import
Line 4,522: Line 4,522:
=={{header|Zsh}}==
=={{header|Zsh}}==
Concatenating arrays.
Concatenating arrays.
<syntaxhighlight lang=zsh>a=(1 2 3)
<syntaxhighlight lang="zsh">a=(1 2 3)
b=(a b c)
b=(a b c)


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


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
{{trans|Liberty BASIC}}
{{trans|Liberty BASIC}}
<syntaxhighlight 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)