Array concatenation: Difference between revisions

PascalABC.NET
m (syntax highlighting fixup automation)
(PascalABC.NET)
(39 intermediate revisions by 29 users not shown)
Line 1:
{{task|Data Structures}}
[[Category:Simple]]
{{task|Data Structures}}
;Task:
Line 10:
 
=={{header|11l}}==
<syntaxhighlight lang="11l">V arr1 = [1, 2, 3]
V arr2 = [4, 5, 6]
print(arr1 [+] arr2)</syntaxhighlight>
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.
 
<syntaxhighlight lang="68000devpac">ArrayRam equ $00FF2000 ;this label points to 4k of free space.
 
;concatenate Array1 + Array2
Line 46:
 
=={{header|8th}}==
<syntaxhighlight lang=Forth"forth">
[1,2,3] [4,5,6] a:+ .
</syntaxhighlight>
Line 56:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program concAreaString.s */
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.
 
<syntaxhighlight lang=ABAP"abap">
report z_array_concatenation.
 
Line 184:
=={{header|ACL2}}==
This is for lists, not arrays; ACL2's array support is limited.
<syntaxhighlight lang=Lisp"lisp">(append xs ys)</syntaxhighlight>
 
=={{header|Action!}}==
<syntaxhighlight lang=Action"action!">BYTE FUNC Concat(INT ARRAY src1,src2,dst BYTE size1,size2)
BYTE i
 
Line 249:
 
=={{header|ActionScript}}==
<syntaxhighlight lang=ActionScript"actionscript">var array1:Array = new Array(1, 2, 3);
var array2:Array = new Array(4, 5, 6);
var array3:Array = array1.concat(array2); //[1, 2, 3, 4, 5, 6]</syntaxhighlight>
Line 255:
=={{header|Ada}}==
In [[Ada]] arrays are concatenated using the operation &. It works with any one dimensioned array:
<syntaxhighlight lang=Ada"ada">type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6); -- Concatenate X and (4, 5, 6)</syntaxhighlight>
 
=={{header|Aime}}==
<syntaxhighlight lang="aime">ac(list a, b)
{
list o;
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]}} -->
Includes operators for ''appending'' and ''prefixing'' an array to an existing flexible array:
<syntaxhighlight lang=Algol68"algol68">MODE ARGTYPE = INT;
MODE ARGLIST = FLEX[0]ARGTYPE;
 
Line 331:
=={{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.
<syntaxhighlight lang="algolw">begin
integer array a ( 1 :: 5 );
integer array b ( 2 :: 4 );
Line 373:
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang=Amazing"amazing Hopperhopper">
#include <hbasic.h>
Begin
Line 389:
 
=={{header|AntLang}}==
<syntaxhighlight lang=AntLang"antlang">a:<1; <2; 3>>
b: <"Hello"; 42>
c: a,b</syntaxhighlight>
 
=={{header|Apex}}==
<syntaxhighlight lang="apex">List<String> listA = new List<String> { 'apple' };
List<String> listB = new List<String> { 'banana' };
listA.addAll(listB);
Line 400:
 
=={{header|APL}}==
<syntaxhighlight lang="apl">
1 2 3 , 4 5 6
1 2 3 4 5 6
Line 406:
 
=={{header|AppleScript}}==
<syntaxhighlight lang=AppleScript"applescript">
set listA to {1, 2, 3}
set listB to {4, 5, 6}
Line 422:
{{trans|JavaScript}}
 
<syntaxhighlight lang="applescript">on run
 
concat([["alpha", "beta", "gamma"], ¬
Line 448:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang=ARM"arm Assemblyassembly">
/* ARM assembly Raspberry PI */
/* program concAreaString.s */
Line 623:
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">arr1: [1 2 3]
arr2: ["four" "five" "six"]
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''.
 
<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
Line 772:
=== True Arrays ===
{{works with|AutoHotkey_L}}
<syntaxhighlight lang=AHK"ahk">List1 := [1, 2, 3]
List2 := [4, 5, 6]
cList := Arr_concatenate(List1, List2)
Line 792:
=== Legacy versions ===
[[AutoHotkey_Basic]] does not have real Arrays, but the user can implement them quite easily. For example:
<syntaxhighlight lang=AutoHotkey"autohotkey">List1 = 1,2,3
List2 = 4,5,6
 
Line 838:
 
<syntaxhighlight lang=AutoIt"autoit">
_ArrayConcatenate($avArray, $avArray2)
Func _ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource, $iStart = 0)
Line 860:
 
=={{header|Avail}}==
<syntaxhighlight lang=Avail"avail"><1, 2, 3> ++ <¢a, ¢b, ¢c></syntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">#!/usr/bin/awk -f
BEGIN {
split("cul-de-sac",a,"-")
Line 884:
 
=={{header|Babel}}==
<syntaxhighlight lang="babel">[1 2 3] [4 5 6] cat ;</syntaxhighlight>
 
{{Out}}
Line 890:
 
=={{header|bash}}==
<syntaxhighlight lang="bash">x=("1 2" "3 4")
y=(5 6)
sum=( "${x[@]}" "${y[@]}" )
Line 902:
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{works with|Chipmunk 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)
30 FOR I = 1 TO X:A(I - 1) = I: NEXT
Line 909 ⟶ 910:
60 FOR I = 1 TO Y:C(X + I - 1) = B(I - 1): NEXT
70 FOR I = 1 TO X + Y: PRINT MID$ (" ",1,I > 1)C(I - 1);: NEXT</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">100 U1 = 3: U2 = 4
110 DIM A$(3)
120 DATA "The","quick","brown","fox"
130 FOR I = 0 TO U1 : READ A$(I) : NEXT I
140 DIM B$(4)
150 DATA "jumped","over","the","lazy","dog"
160 FOR I = 0 TO U2 : READ B$(I) : NEXT I
170 'SU2 ConcatArrays
180 X = U1 + 1
190 Y = U2 + 1
200 Z = X + Y
210 DIM C$(Z-1)
220 FOR I = 0 TO X-1
230 C$(I) = A$(I)
240 NEXT I
250 FOR I = 0 TO Y-1
260 C$(U1+I+1) = B$(I)
270 NEXT I
280 '
290 FOR I = 0 TO Z-1
300 PRINT C$(I); " ";
310 NEXT I
320 END</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{trans|Applesoft BASIC}}
{{works with|GW-BASIC}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">10 LET X = 4
20 LET Y = 5
30 DIM A(3)
40 DIM B(4)
50 DIM C(8)
60 FOR I = 1 TO X
70 LET A(I-1) = I
80 NEXT I
90 FOR I = 1 TO Y
100 LET B(I-1) = I*10
110 NEXT I
120 FOR I = 1 TO X
130 LET C(I-1) = A(I-1)
140 NEXT I
150 FOR I = 1 TO Y
160 LET C(X+I-1) = B(I-1)
170 NEXT I
180 FOR I = 1 TO X+Y
190 PRINT C(I-1);
200 NEXT I
210 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Quite BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">100 LET U1 = 3
105 LET U2 = 4
110 ARRAY A$
120 DATA "The","quick","brown","fox"
130 FOR I = 0 TO U1 : READ A$(I) : NEXT I
140 ARRAY B$
150 DATA "jumped","over","the","lazy","dog"
160 FOR I = 0 TO U2 : READ B$(I) : NEXT I
170 rem Sub ConcatArrays
180 LET X = U1 + 1
190 LET Y = U2 + 1
200 LET Z = X + Y
210 ARRAY C
220 FOR I = 0 TO X-1
230 LET C$(I) = A$(I)
240 NEXT I
250 FOR I = 0 TO Y-1
260 LET C$(U1 + I + 1) = B$(I)
270 NEXT I
280 rem
290 FOR I = 0 TO Z-1
300 PRINT C$(I);" ";
310 NEXT I
320 END</syntaxhighlight>
 
==={{header|BaCon}}===
<syntaxhighlight lang="bacon">DECLARE a[] = { 1, 2, 3, 4, 5 }
DECLARE b[] = { 6, 7, 8, 9, 10 }
 
Line 922 ⟶ 1,018:
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> DIM a(3), b(4)
a() = 1, 2, 3, 4
b() = 5, 6, 7, 8, 9
Line 944 ⟶ 1,040:
==={{header|Commodore BASIC}}===
(Based on ZX Spectrum BASIC version)
<syntaxhighlight lang="basic">10 X=4 : Y=5
20 DIM A(X) : DIM B(Y) : DIM C(X+Y)
30 FOR I=1 TO X
Line 961 ⟶ 1,057:
160 : PRINT C(I);
170 NEXT</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
The [[#Liberty BASIC|Liberty BASIC]] solution works without any changes.
 
=={{header|BASIC256}}==
<syntaxhighlight lang="basic256">arraybase 1
global c
 
Line 1,002 ⟶ 1,103:
<pre>1, 2, 3, 4, 5, 6, 7, 8, 9, 10</pre>
 
=={{header|Binary Lambda Calculus}}==
 
BLC uses lists instead of arrays. List concatenation is (see also https://github.com/tromp/AIT/blob/master/lists/cat.lam)
 
<pre>00011001000110100000000000010110111100101111001111110111110110</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">1‿2‿3 ∾ 4‿5‿6</syntaxhighlight>
 
=={{header|Bracmat}}==
Line 1,028 ⟶ 1,134:
=={{header|Burlesque}}==
 
<syntaxhighlight lang="burlesque">
blsq ) {1 2 3}{4 5 6}_+
{1 2 3 4 5 6}
Line 1,035 ⟶ 1,141:
=={{header|C}}==
A way to concatenate two C arrays when you know their size (and usually so it is)
<syntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Line 1,069 ⟶ 1,175:
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System;
 
namespace RosettaCode
Line 1,095 ⟶ 1,201:
 
{{works with|C sharp|C#|3}}
<syntaxhighlight lang="csharp">using System.Linq;
 
class Program
Line 1,109 ⟶ 1,215:
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <vector>
#include <iostream>
 
Line 1,127 ⟶ 1,233:
Similar to above but using initialization schematics.
 
<syntaxhighlight lang="cpp">#include <vector>
#include <iostream>
 
Line 1,143 ⟶ 1,249:
This is another solution with function level templates and pointers.
 
<syntaxhighlight lang="cpp">#include <iostream>
 
using namespace std;
Line 1,195 ⟶ 1,301:
 
=={{header|Ceylon}}==
<syntaxhighlight lang="ceylon">shared void arrayConcatenation() {
value a = Array {1, 2, 3};
value b = Array {4, 5, 6};
Line 1,203 ⟶ 1,309:
 
=={{header|Clojure}}==
<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.
 
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>
 
=={{header|COBOL}}==
{{works with|COBOL 2014}}
<syntaxhighlight lang=COBOL> identification division.
<syntaxhighlight lang="cobolfree">IDENTIFICATION DIVISION.
program-id. array-concat.
PROGRAM-ID. array-concat.
 
DATA DIVISION.
environment division.
WORKING-STORAGE SECTION.
configuration section.
01 table-one.
repository.
05 int-field PIC 999 OCCURS 0 TO 5 TIMES DEPENDING ON t1.
function all intrinsic.
01 table-two.
05 int-field PIC 9(4) OCCURS 0 TO 10 TIMES DEPENDING ON t2.
77 tally USAGE IS INDEX.
77 t1 PIC 99.
77 t2 PIC 99.
77 show PIC Z(4) USAGE IS DISPLAY.
 
PROCEDURE DIVISION.
data division.
array-concat-main.
working-storage section.
PERFORM 01 tableinitialize-one.tables
PERFORM concatenate-tables
05 int-field pic 999 occurs 0 to 5 depending on t1.
PERFORM 01 tabledisplay-two.result
GOBACK.
05 int-field pic 9(4) occurs 0 to 10 depending on t2.
 
initialize-tables.
77 t1 pic 99.
MOVE 4 TO t1
77 t2 pic 99.
PERFORM VARYING tally FROM 1 BY 1 UNTIL tally > t1
COMPUTE int-field OF table-one(tally) = tally * 3
END-PERFORM
MOVE 3 TO t2
PERFORM VARYING tally FROM 1 BY 1 UNTIL tally > t2
COMPUTE int-field OF table-two(tally) = tally * 6
END-PERFORM.
 
concatenate-tables.
77 show pic z(4).
PERFORM VARYING tally FROM 1 BY 1 UNTIL tally > t1
ADD 1 TO t2
MOVE int-field OF table-one(tally)
TO int-field OF table-two(t2)
END-PERFORM.
 
display-result.
procedure division.
PERFORM VARYING tally FROM 1 BY 1 UNTIL tally = t2
array-concat-main.
MOVE int-field OF table-two(tally) TO show
perform initialize-tables
DISPLAY FUNCTION TRIM(show) ", " WITH NO ADVANCING
perform concatenate-tables
END-PERFORM
perform display-result
MOVE int-field OF table-two(tally) TO show
goback.
DISPLAY FUNCTION TRIM(show).
 
END PROGRAM array-concat.</syntaxhighlight>
initialize-tables.
move 4 to t1
perform varying tally from 1 by 1 until tally > t1
compute int-field of table-one(tally) = tally * 3
end-perform
 
move 3 to t2
perform varying tally from 1 by 1 until tally > t2
compute int-field of table-two(tally) = tally * 6
end-perform
.
 
concatenate-tables.
perform varying tally from 1 by 1 until tally > t1
add 1 to t2
move int-field of table-one(tally)
to int-field of table-two(t2)
end-perform
.
 
display-result.
perform varying tally from 1 by 1 until tally = t2
move int-field of table-two(tally) to show
display trim(show) ", " with no advancing
end-perform
move int-field of table-two(tally) to show
display trim(show)
.
 
end program array-concat.</syntaxhighlight>
{{out}}
<pre>prompt$ cobc -xjd array-concatenation.cob --std=cobol2014 # COBOL 2014 needed for FUNCTION TRIM
6, 12, 18, 3, 6, 9, 12
</pre>
 
=={{header|CoffeeScript}}==
<syntaxhighlight lang="coffeescript">
# like in JavaScript
a = [1, 2, 3]
Line 1,282 ⟶ 1,379:
=={{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.
<syntaxhighlight lang="lisp">(concatenate 'vector #(0 1 2 3) #(4 5 6 7))
=> #(0 1 2 3 4 5 6 7)</syntaxhighlight>
===Alternate solution===
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]
 
<syntaxhighlight lang="lisp">
(setf arr1 (make-array '(3) :initial-contents '(1 2 3)))
(setf arr2 (make-array '(3) :initial-contents '(4 5 6)))
Line 1,310 ⟶ 1,407:
=={{header|Component Pascal}}==
BlackBox Component Builder
<syntaxhighlight lang="oberon2">
MODULE ArrayConcat;
IMPORT StdLog;
Line 1,377 ⟶ 1,474:
 
=={{header|Crystal}}==
<syntaxhighlight lang="ruby">arr1 = [1, 2, 3]
arr2 = ["foo", "bar", "baz"]
arr1 + arr2 #=> [1, 2, 3, "foo", "bar", "baz"]</syntaxhighlight>
 
=={{header|D}}==
<syntaxhighlight lang="d">import std.stdio: writeln;
void main() {
Line 1,395 ⟶ 1,492:
=={{header|Delphi}}==
2022/07/13
<syntaxhighlight lang="delphi">
// This example works on stuff as old as Delphi 5 (maybe older)
// Modern Delphi / Object Pascal has both
Line 1,467 ⟶ 1,564:
It has running commentary about memory management that isn’t exactly correct.<br>
Delphi handles dynamic array memory very well.
<syntaxhighlight lang="delphi">type
TReturnArray = array of integer; //you need to define a type to be able to return it
 
Line 1,507 ⟶ 1,604:
 
=={{header|Diego}}==
<syntaxhighlight lang="diego">set_namespace(rosettacode)_me();
 
add_ary(a)_values(1,2,3);
Line 1,519 ⟶ 1,616:
=={{header|Dyalect}}==
 
<syntaxhighlight lang="dyalect">var xs = [1,2,3]
var ys = [4,5,6]
var alls = Array.Concat(xs, ys)
Line 1,530 ⟶ 1,627:
=={{header|E}}==
 
<syntaxhighlight lang="e">? [1,2] + [3,4]
# value: [1, 2, 3, 4]</syntaxhighlight>
 
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">a[] = [ 1 2 3 ]
b[] = [ 4 5 6 ]
c[] = a[]
whilefor ih < lenin b[]
c[] &= b[i]h
i += 1
.
print c[]</syntaxhighlight>
Line 1,546 ⟶ 1,642:
=={{header|EchoLisp}}==
The native operators are '''append''' for lists, and '''vector-append''' for vectors (1-dim arrays).
<syntaxhighlight lang="scheme">
;;;; VECTORS
(vector-append (make-vector 6 42) (make-vector 4 666))
Line 1,565 ⟶ 1,661:
=={{header|ECL}}==
 
<syntaxhighlight lang="text">
A := [1, 2, 3, 4];
B := [5, 6, 7, 8];
 
C := A + B;</syntaxhighlight>
 
=={{header|Ecstasy}}==
It is as simple as <code><var>array1</var> + <var>array2</var></code>:
<syntaxhighlight lang="java">String[] fruits = ["apples", "oranges"];
String[] grains = ["wheat", "corn"];
String[] all = fruits + grains;</syntaxhighlight>
 
=={{header|Efene}}==
Line 1,575 ⟶ 1,677:
using the ++ operator and the lists.append function
 
<syntaxhighlight lang="efene">
@public
run = fn () {
Line 1,590 ⟶ 1,692:
=={{header|EGL}}==
{{works with|EDT}}
<syntaxhighlight lang=EGL"egl">
program ArrayConcatenation
function main()
Line 1,607 ⟶ 1,709:
 
=={{header|Ela}}==
<syntaxhighlight lang="ela">xs = [1,2,3]
ys = [4,5,6]
xs ++ ys</syntaxhighlight>
Line 1,614 ⟶ 1,716:
=={{header|Elena}}==
ELENA 5.0 :
<syntaxhighlight lang="elena">import extensions;
 
public program()
Line 1,631 ⟶ 1,733:
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">iex(1)> [1, 2, 3] ++ [4, 5, 6]
[1, 2, 3, 4, 5, 6]
iex(2)> Enum.concat([[1, [2], 3], [4], [5, 6]])
Line 1,639 ⟶ 1,741:
 
=={{header|Elm}}==
<syntaxhighlight lang="elm">import Element exposing (show, toHtml) -- elm-package install evancz/elm-graphics
import Html.App exposing (beginnerProgram)
import Array exposing (Array, append, initialize)
Line 1,662 ⟶ 1,764:
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])
=> [1 2 3 4 5 6 7 8 9]</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
^|EMal has the concept of list expansion,
|you can expand a list to function arguments
|by prefixing it with the unary plus.
|^
List a = int[1,2,3]
List b = int[4,5,6]
List c = int[+a, +b]
writeLine(c)
</syntaxhighlight>
{{out}}
<pre>
[1,2,3,4,5,6]
</pre>
 
=={{header|Erlang}}==
Line 1,670 ⟶ 1,788:
 
On the shell,
<syntaxhighlight lang="erlang">
1> [1, 2, 3] ++ [4, 5, 6].
[1,2,3,4,5,6]
Line 1,679 ⟶ 1,797:
 
=={{header|ERRE}}==
<syntaxhighlight lang="text">
PROGRAM ARRAY_CONCAT
 
Line 1,714 ⟶ 1,832:
 
=={{header|Euphoria}}==
<syntaxhighlight lang=Euphoria"euphoria">sequence s1,s2,s3
s1 = {1,2,3}
s2 = {4,5,6}
Line 1,725 ⟶ 1,843:
=={{header|F Sharp|F#}}==
Array concatenation.
<syntaxhighlight lang="fsharp">let a = [|1; 2; 3|]
let b = [|4; 5; 6;|]
let c = Array.append a b</syntaxhighlight>
List concatenation (@ and List.append are equivalent).
<syntaxhighlight lang="fsharp">let x = [1; 2; 3]
let y = [4; 5; 6]
let z1 = x @ y
Line 1,735 ⟶ 1,853:
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">append</syntaxhighlight>
 
'''Example''':
<syntaxhighlight lang="factor">( scratchpad ) USE: sequences
( scratchpad ) { 1 2 } { 3 4 } append .
{ 1 2 3 4 }</syntaxhighlight>
Line 1,746 ⟶ 1,864:
In fansh:
 
<syntaxhighlight lang="fantom">
> a := [1,2,3]
> b := [4,5,6]
Line 1,758 ⟶ 1,876:
=={{header|FBSL}}==
Array concatenation:
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE
 
DIM aint[] ={1, 2, 3}, astr[] ={"one", "two", "three"}, asng[] ={!1, !2, !3}
Line 1,772 ⟶ 1,890:
 
=={{header|Forth}}==
<syntaxhighlight lang=Forth"forth">: $!+ ( a u a' -- a'+u )
2dup + >r swap move r> ;
: cat ( a2 u2 a1 u1 -- a3 u1+u2 )
Line 1,789 ⟶ 1,907:
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<syntaxhighlight lang="fortran">program Concat_Arrays
implicit none
 
Line 1,809 ⟶ 1,927:
=={{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>).
<syntaxhighlight lang="pascal"> array2 := array0 + array1</syntaxhighlight>
Alternatively, one could use <code>concat()</code> which is independent of above modeswitch and mode. Neither option requires the use of any libraries.:
<syntaxhighlight lang="pascal"> array2 := concat(array0, array1);</syntaxhighlight>
 
Both options do not require any libraries.
A more complete example:
<syntaxhighlight lang="pascal">
Program arrayConcat;
 
{$mode delphi}
 
type
TDynArr = array of integer;
 
var
i: integer;
arr1, arr2, arrSum : TDynArr;
 
begin
arr1 := [1, 2, 3];
arr2 := [4, 5, 6];
 
arrSum := arr1 + arr2;
for i in arrSum do
write(i, ' ');
writeln;
end.
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
' FB 1.05.0 Win64
 
Line 1,850 ⟶ 1,996:
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">
a = [1,2]
b = [3,4]
Line 1,857 ⟶ 2,003:
 
=={{header|FunL}}==
<syntaxhighlight lang="funl">arr1 = array( [1, 2, 3] )
arr2 = array( [4, 5, 6] )
arr3 = array( [7, 8, 9] )
Line 1,873 ⟶ 2,019:
Array concatenation is done with the built-in function <code>concat</code>, which can take any number of arguments:
 
<syntaxhighlight lang=Futhark"futhark">
concat as bs cd
</syntaxhighlight>
Line 1,879 ⟶ 2,025:
=={{header|FutureBasic}}==
 
<syntaxhighlight lang=FutureBasic"futurebasic">void local fn DoIt
CFArrayRef array = @[@"Alpha",@"Bravo",@"Charlie"]
print array
Line 1,911 ⟶ 2,057:
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=314bea6fba7f177a1cfaec8a7a8b5ccb Click this link to run this code]'''
<syntaxhighlight lang="gambas">Public Sub Main()
Dim sString1 As String[] = ["The", "quick", "brown", "fox"]
Dim sString2 As String[] = ["jumped", "over", "the", "lazy", "dog"]
Line 1,926 ⟶ 2,072:
 
=={{header|GAP}}==
<syntaxhighlight lang="gap"># Concatenate arrays
Concatenation([1, 2, 3], [4, 5, 6], [7, 8, 9]);
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
Line 1,938 ⟶ 2,084:
 
=={{header|Genie}}==
<syntaxhighlight lang="genie">[indent=4]
/*
Array concatenation, in Genie
Line 1,977 ⟶ 2,123:
=={{header|GLSL}}==
This macro concatenates two arrays to form a new array. The first parameter is the type of the array:
<syntaxhighlight lang="glsl">
#define array_concat(T,a1,a2,returned) \
T[a1.length()+a2.length()] returned; \
Line 1,990 ⟶ 2,136:
</syntaxhighlight>
The macro can be used like this:
<syntaxhighlight lang="glsl">
array_concat(float,float[](1.,2.,3.),float[](4.,5.,6.),returned);
int i = returned.length();
Line 1,996 ⟶ 2,142:
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
 
import "fmt"
Line 2,038 ⟶ 2,184:
</pre>
Array concatenation needs can vary. Here is another set of examples that illustrate different techniques.
<syntaxhighlight lang="go">package main
 
import (
Line 2,103 ⟶ 2,249:
=={{header|Gosu}}==
 
<syntaxhighlight lang="gosu">
var listA = { 1, 2, 3 }
var listB = { 4, 5, 6 }
Line 2,114 ⟶ 2,260:
=={{header|Groovy}}==
Solution:
<syntaxhighlight lang="groovy">def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"]</syntaxhighlight>
 
Test:
<syntaxhighlight lang="groovy">println list</syntaxhighlight>
 
{{out}}
Line 2,124 ⟶ 2,270:
=={{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 ++:
<syntaxhighlight lang="haskell">(++) :: [a] -> [a] -> [a]</syntaxhighlight>
Append two lists, i.e.:<pre>
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
Line 2,131 ⟶ 2,277:
 
This operator could be defined from the scratch using explicit recursion:
<syntaxhighlight lang="haskell">
[] ++ x = x
(h:t) ++ y = h : (t ++ y)
</syntaxhighlight>
or folding
<syntaxhighlight lang="haskell">
x ++ y = foldr (:) y x
</syntaxhighlight>
 
=={{header|HicEst}}==
<syntaxhighlight lang=HicEst"hicest">REAL :: a(7), b(3), c(10)
 
c = a
Line 2,149 ⟶ 2,295:
 
=={{header|Hy}}==
<syntaxhighlight lang="hy">=> (setv a [1 2 3])
=> a
[1, 2, 3]
Line 2,166 ⟶ 2,312:
 
=={{header|i}}==
<syntaxhighlight lang="i">main
a $= [1, 2, 3]
b $= [4, 5, 6]
Line 2,175 ⟶ 2,321:
=={{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.
<syntaxhighlight lang="icon">
procedure main()
L1 := [1, 2, 3, 4]
Line 2,191 ⟶ 2,337:
 
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"idl">
> a = [1,2,3]
> b = [4,5,6]
Line 2,204 ⟶ 2,350:
</syntaxhighlight>
Then they can be concatenated "at the ends":
<syntaxhighlight lang=IDL"idl">
> help,[a,b]
<Expression> INT = Array[6]
Line 2,211 ⟶ 2,357:
</syntaxhighlight>
or "at the sides":
<syntaxhighlight lang=IDL"idl">
> help,[[a],[b]]
<Expression> INT = Array[3, 2]
Line 2,219 ⟶ 2,365:
</syntaxhighlight>
Note that this requires that the arrays have the same size at the side at which they are concatenated:
<syntaxhighlight lang=IDL"idl">
> b = transpose(b)
> help,b
Line 2,245 ⟶ 2,391:
 
=={{header|Inform 7}}==
<syntaxhighlight lang="inform7">let A be {1, 2, 3};
let B be {4, 5, 6};
add B to A;</syntaxhighlight>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(into [1 2 3] [4 5 6])</syntaxhighlight>
 
<syntaxhighlight lang="insitux">(.. vec [1 2 3] [4 5 6])</syntaxhighlight>
 
=={{header|Ioke}}==
<syntaxhighlight lang="ioke">iik> [1,2,3] + [3,2,1]
[1,2,3] + [3,2,1]
+> [1, 2, 3, 3, 2, 1]</syntaxhighlight>
Line 2,258 ⟶ 2,409:
 
'''Example''':
<syntaxhighlight lang="j"> array1 =: 1 2 3
array2 =: 4 5 6
array1 , array2
Line 2,267 ⟶ 2,418:
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'
aaa
bbb
Line 2,301 ⟶ 2,452:
2 3 3</syntaxhighlight>
 
=={{header|JavaJakt}}==
<syntaxhighlight lang=java5"jakt">public static Object[] concat(Object[] arr1, Object[] arr2) {
fn main() {
Object[] res = new Object[arr1.length + arr2.length];
let a = ["Apple", "Banana"]
let b = ["Cherry", "Durian"]
mut c: [String] = []
c.push_values(&a)
c.push_values(&b)
println("{}", c)
}
</syntaxhighlight>
 
{{out}}
System.arraycopy(arr1, 0, res, 0, arr1.length);
<pre>
System.arraycopy(arr2, 0, res, arr1.length, arr2.length);
["Apple", "Banana", "Cherry", "Durian"]
</pre>
 
=={{header|Java}}==
return res;
In Java, arrays are immutable, so you'll have to create a new array, and copy the contents of the two arrays into it.<br />
}</syntaxhighlight>
Luckily, Java offers the ''System.arraycopy'' method, which will save you the effort of creating the for-loops.<br />
<syntaxhighlight lang="java">
int[] concat(int[] arrayA, int[] arrayB) {
int[] array = new int[arrayA.length + arrayB.length];
System.arraycopy(arrayA, 0, array, 0, arrayA.length);
System.arraycopy(arrayB, 0, array, arrayA.length, arrayB.length);
return array;
}
</syntaxhighlight>
If you wanted to use for-loops, possibly to mutate the data as it's concatenated, you can use the following.
<syntaxhighlight lang="java">
int[] concat(int[] arrayA, int[] arrayB) {
int[] array = new int[arrayA.length + arrayB.length];
for (int index = 0; index < arrayA.length; index++)
array[index] = arrayA[index];
for (int index = 0; index < arrayB.length; index++)
array[index + arrayA.length] = arrayB[index];
return array;
}
</syntaxhighlight>
A less idiomatic approach would be to use a ''List'', which is a mutable array, similar to a "vector" in other languages.<br />
I have used both arrays and ''List''s extensively and have not noticed any sort of performance degradation, they appear to work equally as fast.<br />
It's worth noting that the Java Collections Framework, which contains the ''List'' class, is built specifically for Objects and not necessarily primitive data-types. Despite this, it's still worth using for primitives, although the conversion to and from arrays is somewhat abstruse.
<syntaxhighlight lang="java">
int[] concat(int[] arrayA, int[] arrayB) {
List<Integer> list = new ArrayList<>();
for (int value : arrayA) list.add(value);
for (int value : arrayB) list.add(value);
int[] array = new int[list.size()];
for (int index = 0; index < list.size(); index++)
array[index] = list.get(index);
return array;
}
</syntaxhighlight>
 
=={{header|JavaScript}}==
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],
b = [4,5,6],
c = a.concat(b); //=> [1,2,3,4,5,6]</syntaxhighlight>
Line 2,323 ⟶ 2,518:
See, for a function with an analogous type signature, '''concat''' in the Haskell Prelude.
 
<syntaxhighlight lang="javascript">(function () {
'use strict';
 
Line 2,343 ⟶ 2,538:
 
<pre>["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota"]</pre>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">[1 2 3] [4 5 6] concat.</syntaxhighlight>
 
=={{header|jq}}==
Line 2,350 ⟶ 2,548:
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]
 
[range(1;3), 3, null] # => [1,2,3,null]
Line 2,356 ⟶ 2,554:
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">a = [1,2,3]
b = [4,5,6]
ab = [a;b]
Line 2,367 ⟶ 2,565:
 
=={{header|K}}==
<syntaxhighlight lang=K"k">
a: 1 2 3
b: 4 5 6
Line 2,375 ⟶ 2,573:
Concatenations on larger dimensions also use ",", often combined with other operations.
 
<syntaxhighlight lang=K"k">
ab:3 3#"abcdefghi"
("abc"
Line 2,410 ⟶ 2,608:
 
=={{header|Klingphix}}==
<syntaxhighlight lang=Klingphix"klingphix">include ..\Utilitys.tlhy
 
( 1.0 "Hello" 3 2 / 4 2.1 power ) ( 5 6 7 8 ) chain print
Line 2,419 ⟶ 2,617:
 
=={{header|Klong}}==
<syntaxhighlight lang=K"k">
[1 2 3],[4 5 6] :" join "
[1 2 3 4 5 6]
Line 2,431 ⟶ 2,629:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">fun main() {
There is no operator or standard library function for concatenating <code>Array</code> types. One option is to convert to <code>Collection</code>s, concatenate, and convert back:
val a = intArrayOf(1, 2, 3)
<syntaxhighlight lang=kotlin>fun main(args: Array<String>) {
val a: Array<Int>b = arrayOfintArrayOf(14, 25, 36) // initialise a
val c = a + b: Array<Int>// =[1, 2, 3, arrayOf(4, 5, 6) // initialise b]
println(c.contentToString())
val c: Array<Int> = (a.toList() + b.toList()).toTypedArray()
println(c)
}</syntaxhighlight>
 
Alternatively, we can write our own concatenation function:
<syntaxhighlight lang=kotlin>fun arrayConcat(a: Array<Any>, b: Array<Any>): Array<Any> {
return Array(a.size + b.size, { if (it in a.indices) a[it] else b[it - a.size] })
}</syntaxhighlight>
 
When working directly with <code>Collection</code>s, we can simply use the <code>+</code> operator:
<syntaxhighlight lang=kotlin>fun main(args: Array<String>) {
val a: Collection<Int> = listOf(1, 2, 3) // initialise a
val b: Collection<Int> = listOf(4, 5, 6) // initialise b
val c: Collection<Int> = a + b
println(c)
}</syntaxhighlight>
 
Line 2,457 ⟶ 2,641:
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{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]
{A.concat {A} {B}} -> [1,2,3,4,5,6,7,8,9]
</syntaxhighlight>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
&a $= [1, 2, 3]
&b $= [4, 5, 6]
&c $= &a ||| &b
fn.println(&c)
</syntaxhighlight>
 
=={{header|Lang5}}==
<syntaxhighlight lang=Lang5"lang5">[1 2] [3 4] append collapse .</syntaxhighlight>
 
=={{header|langur}}==
<syntaxhighlight lang="langur">val .a = [1, 2, 3]
val .b = [7, 8, 9]
val .c = .a ~ .b
Line 2,476 ⟶ 2,668:
 
=={{header|Lasso}}==
<syntaxhighlight lang=Lasso"lasso">
local(arr1 = array(1, 2, 3))
local(arr2 = array(4, 5, 6))
Line 2,489 ⟶ 2,681:
arr3 = array(4, 5, 6)
arr3 = array(1, 2, 3, 4, 5, 6)</syntaxhighlight>
 
=={{header|LDPL}}==
{{libheader|ldpl-std}}
<syntaxhighlight lang="ldpl">include "std-list.ldpl"
 
data:
arr1 is number list
arr2 is number list
 
procedure:
push 1 to arr1
push 2 to arr1
push 3 to arr2
push 4 to arr2
append list arr2 to list arr1
display list arr1
</syntaxhighlight>
{{out}}
<pre>
[1, 2, 3, 4]
</pre>
 
=={{header|LFE}}==
<syntaxhighlight lang="lisp">
> (++ '(1 2 3) '(4 5 6))
(1 2 3 4 5 6)
Line 2,499 ⟶ 2,712:
 
=={{header|Liberty BASIC}}==
{{works with|Just BASIC}}
<syntaxhighlight lang=lb> x=10
{{works with|Run BASIC}}
<syntaxhighlight lang="lb"> x=10
y=20
dim array1(x)
Line 2,521 ⟶ 2,736:
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">##
Array concatenation in LIL
##
Line 2,537 ⟶ 2,752:
 
=={{header|Limbo}}==
<syntaxhighlight lang="limbo">implement Command;
 
include "sys.m";
Line 2,562 ⟶ 2,777:
 
=={{header|Lingo}}==
<syntaxhighlight lang="lingo">a = [1,2]
b = [3,4,5]
 
Line 2,573 ⟶ 2,788:
 
=={{header|Little}}==
<syntaxhighlight lang=C"c">void main() {
int a[] = {0, 1, 2, 3, 4};
int b[] = {5, 6, 7, 8, 9};
Line 2,582 ⟶ 2,797:
=={{header|Logo}}==
COMBINE is used to combine lists or words. SENTENCE is used to combine lists and words into a single list.
<syntaxhighlight lang="logo">
to combine-arrays :a1 :a2
output listtoarray sentence arraytolist :a1 arraytolist :a2
Line 2,590 ⟶ 2,805:
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">a = {1, 2, 3}
b = {4, 5, 6}
 
Line 2,604 ⟶ 2,819:
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
a=(1,2,3,4,5)
b=Cons(a, (6,7,8),a)
Line 2,613 ⟶ 2,828:
Adding 2 dimension arrays
 
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
Dim Base 0, A(2,2)=1, B(1,2)=6
A()=Cons(A(), B(), A(), B())
Line 2,632 ⟶ 2,847:
1 1
1 1
6 6
</pre >
 
Adding 2 dimension arrays using OLE clause
 
<syntaxhighlight lang="m2000 interpreter">
Dim OLE Base 0, A(2,2)=1, B(1,2)=6
A()=Cons(A(), B(), A(), B())
\\ Restore the dimensions (without erasing items)
Dim A(Dimension(A(),1)/2, 2)
For I=0 to Dimension(A(),1)-1 {
For j=0 to Dimension(A(),2)-1 {
Print A(i, j),
}
Print
}
</syntaxhighlight>
{{out}}
<pre>
1 1
1 1
1 1
1 1
6 6
6 6
</pre >
Line 2,637 ⟶ 2,876:
=={{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.
<syntaxhighlight lang=Maple"maple">
> A := Array( [ 1, 2, 3 ] );
A := [1, 2, 3]
Line 2,665 ⟶ 2,904:
</syntaxhighlight>
Of course, the order of the arguments is important.
<syntaxhighlight lang=Maple"maple">
> ArrayTools:-Concatenate( 1, A, M );
[1 2 3]
Line 2,674 ⟶ 2,913:
</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.
<syntaxhighlight lang=Maple"maple">
> L1 := [ 1, 2, 3 ];
L1 := [1, 2, 3]
Line 2,702 ⟶ 2,941:
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"mathcad">
create a pair of arbitrary array:
a:=matrix(2,2,max) b:=a+3
Line 2,721 ⟶ 2,960:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">Join[{1,2,3}, {4,5,6}]
 
-> {1, 2, 3, 4, 5, 6}</syntaxhighlight>
Line 2,727 ⟶ 2,966:
=={{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.
<syntaxhighlight lang=MATLAB"matlab">>> a = [1 2 3];
>> b = [4 5 6];
>> c = [a b]
Line 2,738 ⟶ 2,977:
 
For concatenation along higher dimensions, use cat():
<syntaxhighlight lang=MATLAB"matlab">>> a = randn([3 4 5]);
>> b = randn([3 4 7]);
>> c = cat(3,a,b);
Line 2,746 ⟶ 2,985:
 
=={{header|Maxima}}==
<syntaxhighlight lang="text">u: [1, 2, 3, 4]$
v: [5, 6, 7, 8, 9, 10]$
append(u, v);
Line 2,772 ⟶ 3,011:
=={{header|Mercury}}==
 
<syntaxhighlight lang=Mercury"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?
Line 2,778 ⟶ 3,017:
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">(1 2 3) (4 "apple" 6) concat print</syntaxhighlight>
{{out}}
<pre>
Line 2,785 ⟶ 3,024:
 
=={{header|MiniScript}}==
<syntaxhighlight lang=MiniScript"miniscript">
arrOne = [1, 2, 3]
arrTwo = [4, 5, 6]
Line 2,793 ⟶ 3,032:
=={{header|Nanoquery}}==
Assuming a and b are array or list objects, they may concatenated using the '+' operator.
<syntaxhighlight lang=Nanoquery"nanoquery">a + b</syntaxhighlight>
The '*' operator may also be used to create a specific number of copies of a list or array.
<pre>% a = list()
Line 2,803 ⟶ 3,042:
 
=={{header|Neko}}==
<syntaxhighlight lang=ActionScript"actionscript">/*
Array concatenation, in Neko
*/
Line 2,820 ⟶ 3,059:
 
=={{header|Nemerle}}==
<syntaxhighlight lang=Nemerle"nemerle">using System.Console;
using Nemerle.Collections;
 
Line 2,835 ⟶ 3,074:
=={{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.
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref nobinary
 
Line 2,879 ⟶ 3,118:
 
=={{header|NewLISP}}==
<syntaxhighlight lang=NewLISP"newlisp">; file: arraycon.lsp
; url: http://rosettacode.org/wiki/Array_concatenation
; author: oofoe 2012-01-28
Line 2,905 ⟶ 3,144:
Examples tested to work with Q'Nial7
 
<syntaxhighlight lang=Nial"nial"> a:= 1 2 3
+-+-+-+
|1|2|3|
Line 2,916 ⟶ 3,155:
Table of lists:
 
<syntaxhighlight lang=Nial"nial"> a b
 
+-------+-------+
Line 2,926 ⟶ 3,165:
Simple concatenation of two arrays/lists:
 
<syntaxhighlight lang=Nial"nial"> link a b
+-+-+-+-+-+-+
|1|2|3|4|5|6|
Line 2,933 ⟶ 3,172:
Convert list of lists to table:
 
<syntaxhighlight lang=Nial"nial"> mix a b
+-+-+-+
|1|2|3|
Line 2,941 ⟶ 3,180:
 
Interchange levels of a list of lists:
<syntaxhighlight lang=Nial"nial"> pack a b
+-----+-----+-----+
|+-+-+|+-+-+|+-+-+|
Line 2,950 ⟶ 3,189:
=={{header|Nim}}==
Dynamic sized Sequences can simply be concatenated:
<syntaxhighlight lang="nim">var
x = @[1,2,3,4,5,6]
y = @[7,8,9,10,11]
Line 2,956 ⟶ 3,195:
 
Static sized Arrays:
<syntaxhighlight lang="nim">var
a = [1,2,3,4,5,6]
b = [7,8,9,10,11]
Line 2,963 ⟶ 3,202:
c[0..5] = a
c[6..10] = b</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
let a = [1 2 3]
let b = [4 5 6]
[$a $b] | flatten
</syntaxhighlight>
{{out}}
<pre>
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
│ 4 │ 5 │
│ 5 │ 6 │
╰───┴───╯
</pre>
 
=={{header|Oberon-2}}==
<syntaxhighlight lang="oberon2">
MODULE ArrayConcat;
IMPORT
Line 3,023 ⟶ 3,280:
 
=={{header|Objeck}}==
<syntaxhighlight lang="objeck">
bundle Default {
class Arithmetic {
Line 3,059 ⟶ 3,316:
=={{header|Objective-C}}==
with immutable arrays:
<syntaxhighlight lang="objc">NSArray *arr1 = @[@1, @2, @3];
NSArray *arr2 = @[@4, @5, @6];
NSArray *arr3 = [arr1 arrayByAddingObjectsFromArray:arr2];</syntaxhighlight>
 
or adding onto a mutable array:
<syntaxhighlight lang="objc">NSArray *arr1 = @[@1, @2, @3];
NSArray *arr2 = @[@4, @5, @6];
NSMutableArray *arr3 = [NSMutableArray arrayWithArray:arr1];
Line 3,071 ⟶ 3,328:
=={{header|OCaml}}==
It is more natural in OCaml to use lists instead of arrays:
<syntaxhighlight lang="ocaml"># let list1 = [1; 2; 3];;
val list1 : int list = [1; 2; 3]
# let list2 = [4; 5; 6];;
Line 3,079 ⟶ 3,336:
 
If you want to use arrays:
<syntaxhighlight lang="ocaml"># let array1 = [|1; 2; 3|];;
val array1 : int array = [|1; 2; 3|]
# let array2 = [|4; 5; 6|];;
Line 3,085 ⟶ 3,342:
# let array1and2 = Array.append array1 array2;;
val array1and2 : int array = [|1; 2; 3; 4; 5; 6|]</syntaxhighlight>
 
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
 
import "core:fmt"
import "core:slice"
 
main :: proc() {
x: [3]int = {1, 2, 3}
y: [3]int = {4, 5, 6}
 
xy: [len(x) + len(y)]int
copy(xy[:], x[:])
copy(xy[len(x):], y[:])
 
fmt.println(xy)
}</syntaxhighlight>
===Using slices===
<syntaxhighlight lang="odin">package main
 
import "core:fmt"
import "core:slice"
 
main :: proc() {
x: [3]int = {1, 2, 3}
y: [3]int = {4, 5, 6}
 
xy := slice.concatenate([][]int{x[:], y[:]})
defer delete(xy)
 
fmt.println(xy)
}</syntaxhighlight>
 
=={{header|Oforth}}==
 
<syntaxhighlight lang=Oforth"oforth">import: mapping
 
[1, 2, 3 ] [ 4, 5, 6, 7 ] + </syntaxhighlight>
Line 3,094 ⟶ 3,383:
=={{header|Onyx}}==
 
<syntaxhighlight lang="onyx"># With two arrays on the stack, cat pops
# them, concatenates them, and pushes the result back
# on the stack. This works with arrays of integers,
Line 3,109 ⟶ 3,398:
 
=={{header|ooRexx}}==
<syntaxhighlight lang=ooRexx"oorexx">a = .array~of(1,2,3)
say "Array a has " a~items "items"
b = .array~of(4,5,6)
Line 3,122 ⟶ 3,411:
=={{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.
<syntaxhighlight lang="c">#include <order/interpreter.h>
 
ORDER_PP( 8tuple_append(8tuple(1, 2, 3), 8tuple(4, 5, 6), 8pair(7, 8)) )
Line 3,131 ⟶ 3,420:
 
=={{header|OxygenBasic}}==
<syntaxhighlight lang="oxygenbasic">
'CREATE DYNAMIC ARRAY SPACES USING STRINGS
 
Line 3,158 ⟶ 3,447:
=={{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.
<syntaxhighlight lang="oz">%% concatenating 2 lists
{Append [a b] [c d]} = [a b c d]
 
Line 3,165 ⟶ 3,454:
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="parigp">concat(u,v)</syntaxhighlight>
 
=={{header|Pascal}}==
''See [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]]''
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="perl">
##
var a := |1,2,3,4|;
var b := Arr(5..8);
var c := a + b;
c.Println;
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8
</pre>
 
=={{header|Perl}}==
In Perl, arrays placed into list context are flattened:
<syntaxhighlight lang="perl">my @arr1 = (1, 2, 3);
my @arr2 = (4, 5, 6);
my @arr3 = (@arr1, @arr2);</syntaxhighlight>
 
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);
my @arr2 = (4, 5, 6);
push @arr1, @arr2;
Line 3,184 ⟶ 3,486:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<syntaxhighlight lang=Phix"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: #0000FF;">?</span> <span style="color: #000000;">s1</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">s2
Line 3,194 ⟶ 3,496:
 
=={{header|Phixmonti}}==
<syntaxhighlight lang=Phixmonti"phixmonti">1.0 "Hello" 3 2 / 4 2.1 power 4 tolist 5 6 7 8 4 tolist chain print</syntaxhighlight>
With syntactic sugar
<syntaxhighlight lang=Phixmonti"phixmonti">include ..\Utilitys.pmt
( 1.0 "Hello" 3 2 / 4 2.1 power ) ( 5 6 7 8 ) chain print</syntaxhighlight>
 
=={{header|PHP}}==
 
<syntaxhighlight lang="php">$arr1 = array(1, 2, 3);
$arr2 = array(4, 5, 6);
$arr3 = array_merge($arr1, $arr2);</syntaxhighlight>
Line 3,210 ⟶ 3,512:
and back again with to_array/1.
 
<syntaxhighlight lang=Picat"picat">go =>
L1 = {1,2,3,4,5}, % define an array with {}
L2 = {6,7,8,9},
Line 3,232 ⟶ 3,534:
 
There are destructive concatenations:
<syntaxhighlight lang=PicoLisp"picolisp">: (setq A (1 2 3) B '(a b c))
-> (a b c)
: (conc A B) # Concatenate lists in 'A' and 'B'
Line 3,239 ⟶ 3,541:
-> (1 2 3 a b c) # Side effect: List in 'A' is modified!</syntaxhighlight>
and non-destructive concatenations:
<syntaxhighlight lang=PicoLisp"picolisp">: (setq A (1 2 3) B '(a b c))
-> (a b c)
: (append A B) # Append lists in 'A' and 'B'
Line 3,249 ⟶ 3,551:
 
=={{header|Pike}}==
<syntaxhighlight lang=Pike"pike">int main() {
array arr1 = ({1, 2, 3});
array arr2 = ({4, 5, 6});
Line 3,258 ⟶ 3,560:
Trivial example requires no computational statement.
Note that the arrays are not in static storage:
<syntaxhighlight lang=PL"pl/Ii">
declare x(12) fixed;
declare b(5) fixed defined x;
Line 3,265 ⟶ 3,567:
A more general example using dynamic bounds.
Again, no computation statement is required.
<syntaxhighlight lang="text">
declare x(m+n) fixed;
declare b(m) fixed defined x;
Line 3,276 ⟶ 3,578:
are used in the declarations, the bounds can be dynamic.
Matrix B is extended by placing matrix C on its diagonal:
<syntaxhighlight lang="text">
declare a(5,6) fixed;
declare b(3,4) fixed defined a(1sub, 2sub);
Line 3,293 ⟶ 3,595:
</syntaxhighlight>
{{out}}
<syntaxhighlight lang="text">
Please type elements for a 3 x 4 matrix:
 
Line 3,308 ⟶ 3,610:
0 0 0 0 15 16
 
</syntaxhighlight>
 
=={{header|Plain English}}==
Plain English has these functions for concatenating two sets of things:
<syntaxhighlight lang="text">
To append some things to some other things:
Put the things' first into a thing.
If the thing is nil, exit.
Remove the thing from the things.
Append the thing to the other things.
Repeat.
 
To prepend some things to some other things:
Get a thing from the things (backwards).
If the thing is nil, exit.
Remove the thing from the things.
Prepend the thing to the other things.
Repeat.
</syntaxhighlight>
 
=={{header|Pony}}==
<syntaxhighlight lang="pony">
actor Main
new create(env:Env)=>
Line 3,330 ⟶ 3,650:
=={{header|PostScript}}==
{{libheader|initlib}}
<syntaxhighlight lang="postscript">
[1 2 3 4] [5 6 7 8] concat
</syntaxhighlight>
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">$a = 1,2,3
$b = 4,5,6
 
Line 3,342 ⟶ 3,662:
 
=={{header|Processing}}==
<syntaxhighlight lang="processing">
int[] a = {1, 2, 3}, b = {4, 5, 6};
 
Line 3,349 ⟶ 3,669:
 
=={{header|Prolog}}==
<syntaxhighlight lang="prolog">
?- append([1,2,3],[4,5,6],R).
R = [1, 2, 3, 4, 5, 6].
Line 3,355 ⟶ 3,675:
 
=={{header|PureBasic}}==
<syntaxhighlight lang=PureBasic"purebasic">Procedure displayArray(Array a(1), msg.s)
Protected i
Print(msg + " [")
Line 3,410 ⟶ 3,730:
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.
<syntaxhighlight lang="python">arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
Line 3,419 ⟶ 3,739:
 
Note: list.extend is normally accomplished using the += operator like this:
<syntaxhighlight lang="python">arr5 = [4, 5, 6]
arr6 = [7, 8, 9]
arr6 += arr5
Line 3,425 ⟶ 3,745:
 
=={{header|Q}}==
<syntaxhighlight lang="q">list1:1 2 3
list2:4 5 6
list1,list2</syntaxhighlight>
Line 3,433 ⟶ 3,753:
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">FUNCTION ConcatArrays(a(), b())
ta = UBOUND(a)
tb = UBOUND(b)
Line 3,465 ⟶ 3,785:
=={{header|QB64}}==
 
<syntaxhighlight lang=QB64"qb64">
 
Dim As Integer First, Second
Line 3,538 ⟶ 3,858:
=={{header|R}}==
 
<syntaxhighlight lang=R"r">
a1 <- c(1, 2, 3)
a2 <- c(3, 4, 5)
Line 3,545 ⟶ 3,865:
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">
(vector-append #(1 2 3 4) #(5 6 7) #(8 9 10))
</syntaxhighlight>
Line 3,556 ⟶ 3,876:
(formerly Perl 6)
{{works with|Rakudo|2018.06}}
<syntaxhighlight lang=perl6"raku" line>my @array1 = 1, 2, 3;
my @array2 = 4, 5, 6;
 
Line 3,580 ⟶ 3,900:
 
=={{header|RapidQ}}==
<syntaxhighlight lang="vb">
DEFINT A(1 to 4) = {1, 2, 3, 4}
DEFINT B(1 to 4) = {10, 20, 30, 40}
Line 3,590 ⟶ 3,910:
 
=={{header|Rapira}}==
<syntaxhighlight lang=Rapira"rapira">arr1 := <* 1, 2, 3 *>
arr2 := <* 4, 5, 6 *>
output: arr1 + arr2</syntaxhighlight>
 
=={{header|REBOL}}==
<syntaxhighlight lang=REBOL"rebol">
a1: [1 2 3]
a2: [4 5 6]
Line 3,606 ⟶ 3,926:
 
=={{header|Red}}==
<syntaxhighlight lang=Red"red">>> arr1: ["a" "b" "c"]
>> arr2: ["d" "e" "f"]
>> append arr1 arr2
Line 3,620 ⟶ 3,940:
 
=={{header|ReScript}}==
<syntaxhighlight lang=ReScript"rescript">Js.Array2.concat(["a", "b"], ["c", "d", "e"]) == ["a", "b", "c", "d", "e"]</syntaxhighlight>
 
=={{header|Retro}}==
<syntaxhighlight lang=Retro"retro">{ #1 #2 #3 } { #4 #5 #6 } a:append</syntaxhighlight>
 
=={{header|REXX}}==
Line 3,636 ⟶ 3,956:
 
Consider:
<syntaxhighlight lang="rexx">a.1 = 10
a.2 = 22.7
a.7 = -12</syntaxhighlight>
Line 3,644 ⟶ 3,964:
<br>assuming that the stemmed variables are sequential.
<br><br>'''example:'''
<syntaxhighlight lang="rexx">fact.0=8
fact.1= 1
fact.2= 2
Line 3,654 ⟶ 3,974:
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.
<syntaxhighlight lang="rexx">/*REXX program to demonstrates how to perform array concatenation.*/
 
p.= /*(below) a short list of primes.*/
Line 3,706 ⟶ 4,026:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
Line 3,721 ⟶ 4,041:
In RLaB the matrices can be appended (column-wise) or stacked (row-wise).
Consider few examples:
<syntaxhighlight lang=RLaB"rlab">
>> x = [1, 2, 3]
>> y = [4, 5, 6]
Line 3,736 ⟶ 4,056:
>>
</syntaxhighlight>
 
=={{header|RPL}}==
In RPL, what is called arrays are actually vectors. Sets of numbers can be stored either in such data structures or in lists, depending on the planned use. Vectors are great for arithmetics, but lists are more versatile.
{{works with|Halcyon Calc|4.2.7}}
=== Vector concatenation===
≪ SWAP ARRY→ LIST→ DROP → n
≪ n 1 + ROLL ARRY→ LIST→ DROP
n + 1 →LIST →ARRY
≫ ≫ 'CONCAT' STO
 
 
[1 2 3] [4 5] CONCAT
{{out}}
<pre>
1: [1 2 3 4 5]
</pre>
A shorter version, without any local variable:
≪ SWAP ARRY→ 1 GET →LIST
SWAP ARRY→ 1 GET →LIST
+ LIST→ { } + →ARRY
≫ 'CONCAT' STO
 
=== List concatenation===
No need for a program to do that:
{1 2 3} {4 5} +
{{out}}
<pre>
1: {1 2 3 4 5}
</pre>
 
=={{header|Ruby}}==
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]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
Line 3,746 ⟶ 4,095:
 
Or use flatten(1):
<syntaxhighlight lang="ruby">
# concat multiple arrays:
[arr1,arr2,arr3].flatten(1)
Line 3,754 ⟶ 4,103:
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn main() {
let a_vec = vec![1, 2, 3, 4, 5];
let b_vec = vec![6; 5];
Line 3,773 ⟶ 4,122:
Or, with iterators:
 
<syntaxhighlight lang="rust">fn concatenate_arrays<T: Clone>(x: &[T], y: &[T]) -> Vec<T> {
x.iter().chain(y).cloned().collect()
}
Line 3,779 ⟶ 4,128:
 
=={{header|S-lang}}==
<syntaxhighlight lang=S"s-lang">variable a = [1, 2, 3];
variable b = [4, 5, 6], c;</syntaxhighlight>
 
Line 3,786 ⟶ 4,135:
But because arrays automatically 'flatten' when defined, concatenation is as
simple as:
<syntaxhighlight lang=S"s-lang">c = [a, b];</syntaxhighlight>
Use of lists is more traditional; lists don't 'flatten', so we use either
list_concat() to create a new concatenated array:
<syntaxhighlight lang=S"s-lang">a = {1, 2, 3};
b = {4, 5, 6};
c = list_concat(a, b);</syntaxhighlight>
 
or list_join():
<syntaxhighlight lang=S"s-lang">list_join(a, b);</syntaxhighlight>
which adds the elements of b onto a.
 
=={{header|SASL}}==
In SASL, the concat operator ++ is built-in
<syntaxhighlight lang=SASL"sasl">(1 2 3) ++ (4 5 6)</syntaxhighlight>
 
=={{header|Scala}}==
<syntaxhighlight lang=Scala"scala">val arr1 = Array( 1, 2, 3 )
val arr2 = Array( 4, 5, 6 )
val arr3 = Array( 7, 8, 9 )
Line 3,812 ⟶ 4,161:
 
=={{header|Scheme}}==
<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))))
 
Line 3,823 ⟶ 4,172:
{{works with|Gauche Scheme}}
 
<syntaxhighlight lang=Scheme"scheme">
(use gauche.array)
 
Line 3,866 ⟶ 4,215:
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
var array integer: a is [] (1, 2, 3, 4);
Line 3,887 ⟶ 4,236:
 
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">put (1, 2, 3) into list1
put (4, 5, 6) into list2
put list1 &&& list2 into list3
Line 3,893 ⟶ 4,242:
 
=={{header|SETL}}==
<syntaxhighlight lang="haskell">A := [1, 2, 3];
B := [3, 4, 5];
print(A + B); -- [1 2 3 3 4 5]</syntaxhighlight>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];
var arr3 = (arr1 + arr2); # => [1, 2, 3, 4, 5, 6]</syntaxhighlight>
 
=={{header|Simula}}==
<syntaxhighlight lang="simula">BEGIN ! Concatenate arrays - of REAL, here;
 
CLASS REAL_ARRAY(N); INTEGER N;
Line 4,006 ⟶ 4,355:
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">
{1. 2. 3. 4. 5} ; {6. 7. 8. 9. 10}
</syntaxhighlight>
 
=={{header|Slope}}==
 
<syntaxhighlight lang="slope">(list-join [1 2 3] [4 5 6])</syntaxhighlight>
 
=={{header|SmallBASIC}}==
<syntaxhighlight lang="SmallBASIC">
A = [1,2,3]
B = [4,5,6]
 
for i in B do A << i
 
print A
</syntaxhighlight>
 
Line 4,013 ⟶ 4,376:
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|
a := #(1 2 3 4 5).
b := #(6 7 8 9 10).
Line 4,025 ⟶ 4,388:
{{works with|CSnobol}}
 
<syntaxhighlight lang=SNOBOL4"snobol4">* # Concatenate 2 arrays (vectors)
define('cat(a1,a2)i,j') :(cat_end)
cat cat = array(prototype(a1) + prototype(a2))
Line 4,050 ⟶ 4,413:
6 7 8 9 10
1 2 3 4 5 6 7 8 9 10</pre>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "arraycat" )
@( description, "Show how to concatenate two arrays in your language." )
@( category, "tutorials" )
@( author, "Ken O. Burtch" )
@( see_also, "http://rosettacode.org/wiki/Array_concatenation" );
pragma license( unrestricted );
 
pragma software_model( nonstandard );
pragma restriction( no_external_commands );
 
procedure arraycat is
type arrayOf3 is array(1..3) of integer;
a1 : constant arrayOf3 := (1, 2, 3);
a2 : constant arrayOf3 := (4, 5, 6);
type arrayOf6 is array(1..6) of integer;
a3 : arrayOf6;
p : natural := arrays.first(a3);
begin
-- In SparForte, & only works on strings and there's no indefinite ranges
-- or array slicing. We have to do this the hard way, one element at a
-- time.
for i in arrays.first(a1)..arrays.last(a1) loop
a3(p) := a1(i);
p := @+1;
end loop;
for i in arrays.first(a2)..arrays.last(a2) loop
a3(p) := a2(i);
p := @+1;
end loop;
-- show the array
for i in arrays.first(a3)..arrays.last(a3) loop
put( a3(i) );
end loop;
new_line;
end arraycat;</syntaxhighlight>
 
=={{header|Standard ML}}==
<syntaxhighlight lang=Standard"standard MLml">
val l1 = [1,2,3,4];;
val l2 = [5,6,7,8];;
Line 4,060 ⟶ 4,462:
=={{header|Stata}}==
===Macro language===
<syntaxhighlight lang="stata">. matrix a=2,9,4\7,5,3\6,1,8
. matrix list a
 
Line 4,099 ⟶ 4,501:
r3 0 0 1</syntaxhighlight>
=== Mata ===
<syntaxhighlight lang="stata">. mata
: a=2,9,4\7,5,3\6,1,8
 
Line 4,126 ⟶ 4,528:
 
=={{header|Swift}}==
<syntaxhighlight lang=Swift"swift">let array1 = [1,2,3]
let array2 = [4,5,6]
let array3 = array1 + array2</syntaxhighlight>
 
=={{header|Tailspin}}==
<syntaxhighlight lang="tailspin">
def a: [1, 2, 3];
def b: [4, 5, 6];
Line 4,142 ⟶ 4,544:
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">set a {1 2 3}
set b {4 5 6}
set ab [concat $a $b]; # 1 2 3 4 5 6</syntaxhighlight>
Line 4,177 ⟶ 4,579:
 
=={{header|Trith}}==
<syntaxhighlight lang="trith">[1 2 3] [4 5 6] concat</syntaxhighlight>
 
=={{header|UNIX Shell}}==
Line 4,185 ⟶ 4,587:
{{works with|bash}}
 
<syntaxhighlight lang="bash">array1=( 1 2 3 4 5 )
array2=( 6 7 8 9 10 )
botharrays=( ${array1[@]} ${array2[@]} )</syntaxhighlight>
Line 4,193 ⟶ 4,595:
{{works with|bash}}
 
<syntaxhighlight lang="bash">array1='1 2 3 4 5'
array2='6 7 8 9 10'
 
Line 4,203 ⟶ 4,605:
 
=={{header|Ursa}}==
<syntaxhighlight lang="ursa"># create two streams (the ursa equivalent of arrays)
# a contains the numbers 1-10, b contains 11-20
decl int<> a b
Line 4,221 ⟶ 4,623:
 
=={{header|Vala}}==
<syntaxhighlight lang="vala">int[] array_concat(int[]a,int[]b){
int[] c = new int[a.length + b.length];
Memory.copy(c, a, a.length * sizeof(int));
Line 4,238 ⟶ 4,640:
=={{header|VBA}}==
 
<syntaxhighlight lang="vb">
Option Explicit
 
Line 4,272 ⟶ 4,674:
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">Function ArrayConcat(arr1, arr2)
ReDim ret(UBound(arr1) + UBound(arr2) + 1)
For i = 0 To UBound(arr1)
Line 4,299 ⟶ 4,701:
 
=={{header|Visual Basic .NET}}==
<syntaxhighlight lang="vbnet">
Dim iArray1() As Integer = {1, 2, 3}
Dim iArray2() As Integer = {4, 5, 6}
Line 4,307 ⟶ 4,709:
</syntaxhighlight>
 
=={{header|V (Vlang)}}==
V (Vlang) uses a '''<<''' operator for array concatenation. Destination array needs to be mutable.
 
<syntaxhighlight lang="go">// V, array concatenation
// Tectonics: v run array-concatenation.v
module main
Line 4,330 ⟶ 4,732:
Wart doesn't have arrays yet, just lists.
 
<syntaxhighlight lang="wart">a <- '(1 2 3)
b <- '(4 5 6)
a+b
Line 4,336 ⟶ 4,738:
 
=={{header|Wren}}==
<syntaxhighlight lang=ecmascript"wren">var arr1 = [1,2,3]
var arr2 = [4,5,6]
System.print(arr1 + arr2)</syntaxhighlight>
{{Out}}
<pre>[1, 2, 3, 4, 5, 6]</pre>
 
=={{header|XPL0}}==
{{trans|C}}
A way to concatenate two XPL0 arrays when you know their size (and usually it is so).
Works on Raspberry Pi. MAlloc works differently in other versions.
<syntaxhighlight lang "XPL0">func Array_concat(A, AN, B, BN, S);
int A, AN, B, BN, S;
int P;
[
P:= MAlloc(S * (AN + BN));
CopyMem(P, A, AN*S);
CopyMem(P + AN*S, B, BN*S);
return P;
];
 
\ testing
int A, B, C, I, SizeOf;
[
A:= [ 1, 2, 3, 4, 5 ];
B:= [ 6, 7, 8, 9, 0 ];
 
SizeOf:= @B - @A;
 
C:= Array_concat(A, 5, B, 5, SizeOf);
 
for I:= 0 to 10-1 do
[IntOut(0, C(I)); ChOut(0, ^ )];
 
Release(C);
]</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 0 </pre>
 
=={{header|Yabasic}}==
<syntaxhighlight lang=Yabasic"yabasic">sub arrayConcatenation(a(), b())
local ta, tb, nt, i
Line 4,381 ⟶ 4,816:
 
=={{header|Yacas}}==
<syntaxhighlight lang=Yacas"yacas">Concat({1,2,3}, {4,5,6})
 
Out> {1, 2, 3, 4, 5, 6}</syntaxhighlight>
 
=={{header|Yorick}}==
<syntaxhighlight lang="yorick">a = [1,2,3];
b = [4,5,6];
ab = grow(a, b);</syntaxhighlight>
Line 4,394 ⟶ 4,829:
Credit to Keith of [https://www.chibiakumas.com ChibiAkumas] for creating it.
 
<syntaxhighlight lang="z80"> org $8000
 
ld hl,TestArray1 ; pointer to first array
Line 4,430 ⟶ 4,865:
801D:
AA BB CC DD EE FF 23 45 67 89
</pre>
 
=={{header|Zig}}==
There are no hidden memory allocations in Zig.
<syntaxhighlight lang="zig">
const std = @import("std");
 
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
 
const allocator = gpa.allocator();
 
var array1 = [_]u32{ 1, 2, 3, 4, 5 };
var array2 = [_]u32{ 6, 7, 8, 9, 10, 11, 12 };
 
const slice3 = try std.mem.concat(allocator, u32, &[_][]const u32{ &array1, &array2 });
defer allocator.free(slice3);
 
// Same result, alternative syntax
const slice4 = try std.mem.concat(allocator, u32, &[_][]const u32{ array1[0..], array2[0..] });
defer allocator.free(slice4);
 
std.debug.print(
"Array 1: {any}\nArray 2: {any}\nSlice 3: {any}\nSlice 4: {any}\n",
.{ array1, array2, slice3, slice4 },
);
}
</syntaxhighlight>
{{out}}
<pre>
Array 1: { 1, 2, 3, 4, 5 }
Array 2: { 6, 7, 8, 9, 10, 11, 12 }
Slice 3: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
Slice 4: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
</pre>
 
=={{header|zkl}}==
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)
T(1,2).extend(4,5,6) //-->L(1,2,4,5,6)</syntaxhighlight>
 
=={{header|zonnon}}==
<syntaxhighlight lang="text">
module Main;
import
Line 4,522 ⟶ 4,992:
=={{header|Zsh}}==
Concatenating arrays.
<syntaxhighlight lang="zsh">a=(1 2 3)
b=(a b c)
 
c=($a $b)</syntaxhighlight>
Pushing a single element into an array.
<syntaxhighlight lang="zsh">a+=4</syntaxhighlight>
Pushing another array into an array.
<syntaxhighlight lang="zsh">a+=($b)</syntaxhighlight>
 
=={{header|ZX Spectrum Basic}}==
{{trans|Liberty BASIC}}
<syntaxhighlight lang="zxbasic">10 LET x=10
20 LET y=20
30 DIM a(x)
161

edits