Impressum/Kontaktparent nodes: implemented functions

, Catenate

testAplConcat
|a result matA matB matD matC |
"http://www.microapl.co.uk/apl_help/ch_020_020_490.htm"

"dataA aplConcat: dataB"

"joins data items together. Short form: ,"

"With single-element items and vectors, aplConcat: works very simply."

"2 numbers are joined to form a 2-element vector"
self assert: #(10 66) asApl = (10 asApl aplConcat:66).
self assert: #(10 66) asApl = (10 asApl, 66).

"3 vectors of characters are joined to form an 11-element vector"
self assert: '10 MAY 1985' asApl = (('10 ' asApl aplConcat:'MAY ') aplConcat:'1985').
self assert: '10 MAY 1985' asApl = ('10 ' asApl,'MAY ', '1985').

"With matrices and other multi-dimensional arrays, aplConcat: expects the dimension at which the join is made to be specified. If no dimension is specified, the last dimension is assumed. aplConcat1 (comma-bar) is a shortcut for aplConcat: onAxis:1 Again, if an axis is specified aplCatenate will use that axis."

"The dimension at which items are joined must be the same length. Thus if two matrices are joined 'at' the columns dimension, the columns must be the same length. If a scalar is joined to a matrix, it's repeated along the dimension at which the join takes place."

"Given the following three matrices called A, B, and D"

matA :=#(1 2 3 4 7 8 9 10) aplReshape:#(2 4).
matB :=#(5 6 11 12) aplReshape:#(2 2).
matD :=#(13 14 15 16 17 18 19 20 21 22 23 24) aplReshape:#(2 6).

"A and B are joined to form C, Since no dimension is specified, the join is at the last dimension ie the columns. Note that A and B have the same number of rows."
matC :=#(1 2 3 4 5 6 7 8 9 10 11 12) aplReshape:#(2 6).

self assert: matC = (matA aplConcat: matB).
self assert: matC = (matA, matB).

result := 24 aplInterval aplReshape:#(4 6).

"C and D are joined at the first dimension, ie at the rows. Note that C and D have the same number of columns."
self assert: result = (matC aplConcat: matD onAxis:1).


"A single number is joined to A. The join is at the row dimension. The number is repeated along that dimension."
result := #(1 2 3 4 7 8 9 10 0 0 0 0) aplReshape:#(3 4).
self assert: result = (matA aplConcat:0 onAxis:1).