Impressum/Kontaktparent nodes: implemented functions

¨ Each

testAplEach
| days data result |
"http://www.microapl.co.uk/apl_help/ch_020_020_900.htm"

"One argument form: data aplEach:anOperand"

"The aplEach: operator applies its operand, an apl function to each element of its argument. In the case of a scalar operand, or a scalar function, each has no effect."
days := #('MONDAY' 'TUESDAY') asApl.
result := (Array with: #(6) asApl with: #(7)) asApl.
self assert: result = (days aplEach:#aplShape).
"Length 4 nested vector"
data := (Array with: (4 aplInterval aplReshape:#(2 2))
               with:(10 aplInterval) 
               with:97.3 
               with: ('K' aplReshape:#(3 4))) asApl.
self assert:#(4) asApl = data aplShape.
"Shape of each element, note empty vector shape for element 3, the scalar"
result := (Array with:#(2 2) asApl self assert: (result = (data aplEach:#aplShape)).

"4 shapes returned"
self assert: #(4) asApl = (data aplEach:#aplShape) aplShape.

"The shape of each of the shapes - the ranks - of each element"
result := (Array with: #(2) asApl self assert:result = ((data aplEach:#aplShape) aplEach:#aplShape).

"Two-argument form: dataA aplEach:anOperand with: dataB"

"The two-argument form of each applies dataA and its operand to each element of dataB argument. Again, for empty dataA or dataB arguments, a fill function is applied."

"Joining successive pairs of elements in the dataA and dataB arguments"
result := (Array with:#(1 4) asApl with:#(2 5) asApl with: #(3 6) asApl) asApl.
self assert: result = (#(1 2 3) asApl aplEach:#, with:#(4 5 6) asApl).


"aplTake: 2 of first element of data argument aplTake:3 of the second"
data := (Array with:'MONDAY'asApl with:'TUESDAY' asApl) asApl.
result := (Array with:'MO'asApl with:'TUE' asApl) asApl.
self assert: result = (data aplEach:#aplTake: with:#(2 3) asApl).

"Scalar extension results in aplTake: 2 of each element of the data argument"
result := (Array with:'MO'asApl with:'TU' asApl) asApl.
self assert: result = (data aplEach:#aplTake: with:2 asApl).


"aplReshape:2 on first element, aplReshape:3 on second"
result := (Array with:#(1 1) asApl with:#(2 2 2) asApl) asApl.
self assert: result = (#(1 2) asApl aplEach:#aplReshape: with:#(2 3) asApl).


data := (Array with:'THE'asApl with:'CAT' asApl) asApl.
result := (Array with:'THET'asApl with:'CATCA' asApl) asApl.
self assert: result = (data aplEach:#aplReshape: with:#(4 5) asApl).