Impressum/Kontaktparent nodes: implemented functions

∊ Membership

testAplMembership
| table result names names2 |
"http://www.microapl.co.uk/apl_help/ch_020_020_380.htm"

"element aplMemebership:list"

"Checks on whether an element exists in the list argument. It returns 1 (true) for each element found in the list argument and 0 (false) for each element not found in the list argument."

"The arguments compared need not have the same number of elements, nor need they have the same number of dimensions. The result has the same shape as the element argument. See aplMatch for a discussion of the criteria which determine whether two data elements are considered the same."

"true asApl = 1 and 1/true means 4 is found in 4 4 5"

self assert: true asApl = (4 asApl aplMembership: #(4 4 5) ).

"A is in ABRACADABRA; remember $A is a character A, 'A' is a string/vector in smalltalk"
self assert: true asApl =( $A asApl aplMembership: 'ABRACADABRA' ).

"Elements 1 4 6 8 and 11 of the ele,emt argument occur in the list argument."
self assert: (#(true false false true false true false true false false true) asApl) = ('ABRACADABRA' asApl aplMembership: 'A' ) .

"The 0s represent spaces in 'A B C' which don't occur in 'ABCDE'"
self assert: #(true false true false true) asApl = ('A B C' asApl aplMembership: 'ABCDE' ).


"Vectors don't need to have the same number of elements"
self assert:#(true true true) asApl = ( #(12 24 36) asApl aplMembership: #( 6 12 18 24 30 36) ).

"Notice that the result always has the same shape as the element argument"
table := 9 aplInterval aplReshape:#(3 3).
self assert:#(true true true) asApl = (#(3 6 9) asApl aplMembership: table).

result := #(false false true false false true false false true) aplReshape:#(3 3).
self assert: result = ( table aplMembership: #(3 6 9) ).


"The character $4 does not appear in the numeric vector 1..10"
self assert: false asApl = ( $4 asApl aplMembership: 10 aplInterval ).

"3 element vector"
names := (Array with:'JOHN' with:'MARY' with:'HARRY') asApl.
self assert: #(3) asApl = names aplShape.

"None of the 4 characters 'MARY' are elements in names"
self assert:#(false false false false) asApl = ('MARY' asApl aplMembership: names ).

"The scalar containing 'MARY' does exist in names"
self assert: true asApl = ( ('MARY' asApl aplEnclose) aplMembership: names ).

"Those elements of names which contain the scalar 'MARY'"
self assert: #(false true false) asApl = (names aplMembership: 'MARY' asApl aplEnclose ).

"'JIM' not found in names"
names2 := (Array with:'MARY' with:'JIM' with:'JOHN') asApl.
self assert: #(true false true) asApl = (names2 aplMembership: names).