This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
append

View file

@ -0,0 +1,3 @@
( scratchpad ) USE: sequences
( scratchpad ) { 1 2 } { 3 4 } append .
{ 1 2 3 4 }

View file

@ -0,0 +1,5 @@
> a := [1,2,3]
> b := [4,5,6]
> a.addAll(b)
> a
[1,2,3,4,5,6]

View file

@ -0,0 +1,10 @@
# Concatenate arrays
Concatenation([1, 2, 3], [4, 5, 6], [7, 8, 9]);
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
# Append to a variable
a := [1, 2, 3];
Append(a, [4, 5, 6);
Append(a, [7, 8, 9]);
a;
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

View file

@ -0,0 +1,6 @@
var listA = { 1, 2, 3 }
var listB = { 4, 5, 6 }
var listC = listA.concat( listB )
print( listC ) // prints [1, 2, 3, 4, 5, 6]

View file

@ -0,0 +1 @@
def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"]

View file

@ -0,0 +1 @@
println list

View file

@ -0,0 +1,6 @@
REAL :: a(7), b(3), c(10)
c = a
DO i = 1, LEN(b)
c(i + LEN(a)) = b(i)
ENDDO

View file

@ -0,0 +1,10 @@
> a = [1,2,3]
> b = [4,5,6]
> help,a
A INT = Array[3]
> help,b
B INT = Array[3]
> print,a
1 2 3
> print,b
4 5 6

View file

@ -0,0 +1,4 @@
> help,[a,b]
<Expression> INT = Array[6]
> print,[a,b]
1 2 3 4 5 6

View file

@ -0,0 +1,5 @@
> help,[[a],[b]]
<Expression> INT = Array[3, 2]
> print,[[a],[b]]
1 2 3
4 5 6

View file

@ -0,0 +1,13 @@
> b = transpose(b)
> help,b
B INT = Array[1, 3]
> print,b
4
5
6
> print,[a,b]
Unable to concatenate variables because the dimensions do not agree: B.
Execution halted at: $MAIN$
> print,[[a],[b]]
Unable to concatenate variables because the dimensions do not agree: B.
Execution halted at: $MAIN$

View file

@ -0,0 +1,10 @@
procedure main()
L1 := [1, 2, 3, 4]
L2 := [11, 12, 13, 14]
L3 := L1 ||| L2
sep := ""
every writes(sep, !L3) do
sep := ", "
write()
end

View file

@ -0,0 +1,3 @@
let A be {1, 2, 3};
let B be {4, 5, 6};
add B to A;

View file

@ -0,0 +1,3 @@
iik> [1,2,3] + [3,2,1]
[1,2,3] + [3,2,1]
+> [1, 2, 3, 3, 2, 1]

View file

@ -0,0 +1,4 @@
array1 =: 1 2 3
array2 =: 4 5 6
array1 , array2
1 2 3 4 5 6

View file

@ -0,0 +1,33 @@
]ab=: 3 3 $ 'aaabbbccc'
aaa
bbb
ccc
]wx=: 3 3 $ 'wxyz'
wxy
zwx
yzw
ab , wx
aaa
bbb
ccc
wxy
zwx
yzw
ab ,. wx
aaawxy
bbbzwx
cccyzw
ab ,: wx
aaa
bbb
ccc
wxy
zwx
yzw
$ ab , wx NB. applies to first (highest) axis
6 3
$ ab ,. wx NB. applies to last (atomic) axis
3 6
$ ab ,: wx NB. applies to new (higher) axis
2 3 3

View file

@ -0,0 +1,5 @@
a = [1,2,3]
b = [4,5,6]
ab = [a,b]
#alternative
ab = vcat(a,b)

View file

@ -0,0 +1,4 @@
a: 1 2 3
b: 4 5 6
a,b
1 2 3 4 5 6

View file

@ -0,0 +1,32 @@
ab:3 3#"abcdefghi"
("abc"
"def"
"ghi")
dd:3 3#"012345678"
("012"
"345"
"678")
ab,dd
("abc"
"def"
"ghi"
"012"
"345"
"678")
+ab,dd / flip (transpose) join
("adg036"
"beh147"
"cfi258")
ab,'dd / eachpair join
("abc012"
"def345"
"ghi678")
+(+ab),dd
("abc036"
"def147"
"ghi258")

View file

@ -0,0 +1 @@
[1 2] [3 4] append

View file

@ -0,0 +1,18 @@
x=10
y=20
dim array1(x)
dim array2(y)
[concatenate]
dim array3(x + y)
for i = 1 to x
array3(i) = array1(i)
next
for i = 1 to y
array3(i + x) = array2(i)
next
[print]
for i = 1 to x + y
print array3(i)
next

View file

@ -0,0 +1,4 @@
to combine-arrays :a1 :a2
output listtoarray sentence arraytolist :a1 arraytolist :a2
end
show combine-arrays {1 2 3} {4 5 6} ; {1 2 3 4 5 6}

View file

@ -0,0 +1,25 @@
> A := Array( [ 1, 2, 3 ] );
A := [1, 2, 3]
> B := Vector['row']( [ sin( x ), cos( x ), tan( x ) ] );
B := [sin(x), cos(x), tan(x)]
> ArrayTools:-Concatenate( 1, A, B ); # stack vertically
[ 1 2 3 ]
[ ]
[sin(x) cos(x) tan(x)]
> ArrayTools:-Concatenate( 2, A, B ); # stack horizontally
[1, 2, 3, sin(x), cos(x), tan(x)]
> M := << a, b, c ; d, e, f >>; # a matrix
[a b c]
M := [ ]
[d e f]
> ArrayTools:-Concatenate( 1, M, A );
[a b c]
[ ]
[d e f]
[ ]
[1 2 3]

View file

@ -0,0 +1,6 @@
> ArrayTools:-Concatenate( 1, A, M );
[1 2 3]
[ ]
[a b c]
[ ]
[d e f]

View file

@ -0,0 +1,11 @@
> L1 := [ 1, 2, 3 ];
L1 := [1, 2, 3]
> L2 := [ a, b, c ];
L2 := [a, b, c]
> [ op( L1 ), op( L2 ) ];
[1, 2, 3, a, b, c]
> [ L1[], L2[] ]; # equivalent, just different syntax
[1, 2, 3, a, b, c]

View file

@ -0,0 +1,3 @@
Join[{1,2,3}, {4,5,6}]
-> {1, 2, 3, 4, 5, 6}

View file

@ -0,0 +1,23 @@
u: [1, 2, 3, 4]$
v: [5, 6, 7, 8, 9, 10]$
append(u, v);
/* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] */
/* There are also functions for matrices */
a: matrix([6, 1, 8],
[7, 5, 3],
[2, 9, 4])$
addcol(a, ident(3));
/* matrix([6, 1, 8, 1, 0, 0],
[7, 5, 3, 0, 1, 0],
[2, 9, 4, 0, 0, 1]) */
addrow(a, ident(3));
/* matrix([6, 1, 8],
[7, 5, 3],
[2, 9, 4],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]) */

View file

@ -0,0 +1 @@
A `append` B = C