Impressum/Kontaktparent nodes: implemented functions

Add

testAdd
|a b table result|
"http://www.microapl.co.uk/apl_help/ch_020_020_020.htm"

"Adds two scalars"
self assert: 15 asApl = (12 asApl + 3).
self assert: 15 asApl = (12 asApl + 3 asApl).
self assert: 15 asApl = (12 asApl aplPerform:#+ with: 3).

"Adds the corresponding numbers in vectors of equal size"
a := #(3 7 2) asApl.
b := #(0 1 -4) asApl.
self assert: #(3 8 -2) asApl = (a + b).

"Adds 11 to each number in a vector"
self assert: #(76 34 109 14) asApl = (11 asApl + #(65 23 98 3) asApl).
self assert: #(76 34 109 14) asApl = (#(65 23 98 3) asApl + 11).

"Adds 10 to each number in table"
table := 6 aplInterval aplReshape: #(2 3).
result := #( 11 12 13 14 15 16) aplReshape: #(2 3).
self assert: result = (10 asApl + table).

"Adds corresponding numbers in matrices of equal size and dimensions"
result := #(2 4 6 8 10 12) aplReshape: #(2 3).
self assert: result = (table + table).


"Scalar left argument added to all elements of right argument"
a:= (Array with:5 with:(4 aplInterval aplReshape:#(2 2)) with:(5 aplInterval))asApl.
result := (Array with:6 with:(#(2 3 4 5) aplReshape:#(2 2)) with:(#(2 3 4 5 6)asApl)) asApl.
self assert: result = (1 asApl + a).

"Arguments must be the same length"
a :=#(2 3) asApl.
b:= (Array with:5 with:(4 aplInterval aplReshape:#(2 2)) with:(5 aplInterval))asApl.
self should:[a+b] raise:AplLengthError.


"Corresponding elements added"
a:= (Array with:(4 aplInterval aplReshape:#(2 2)) with:10 with:(3 aplReshape:#(5)))asApl.
b:= (Array with:5 with:(4 aplInterval aplReshape:#(2 2)) with:(5 aplInterval))asApl.
result := (Array with:(#(6 7 8 9) aplReshape:#(2 2)) with:(#(11 12 13 14) aplReshape:#(2 2)) with:(#(4 5 6 7 8) asApl))asApl.
self assert: result = (a + b).