OpenMusic Reference
x-intersect
x-intersect
(sets module) -- returns the common elements of several lists
Syntax
x-intersect l1? l2? &optional test key &rest list
Inputs
name | data type(s) | comments |
---|---|---|
l1? | a list or tree | |
l2? | a list or tree | |
test | a function name or lambda function | optional; the function with which to compare the two lists. Defaults to ‘equal’ |
key | a function name or lambda function | optional; a function to apply to the lists before comparison. Defaults to ‘identity’ |
list | list | optional, extensible; additional lists to be compared. |
Output
output| data type(s)| comments
—|—|—
first| a list| a single list, containing the intersection of l1? and
l2? (and any list s, if present)
Description
Normally, this box returns the elements common to two sets, l1? and l2? , in a single list, with no repetitions.
If the optional test argument is added, the lists can be compared according to any predicate. The default value of test is ‘equal. Only elements in the first list that return t in comparison with at least one of the elements in the second list (according to the predicate) are returned in the result list. Since the default comparison returns t if the elements are equal, only elements in the first list which also occur in the second list are passed.
If the key argument is included (the default function is identity ), the function at key is first evaluated using each of l1? ‘s elements as input, and then the lists are compared according to the test on the results of the function. test and key may be either the name of a predicate function or a connected function or subpatch icon in lambda mode.
Additional lists can be compared by adding list inputs.
![]() |
This function is not commutative; repeated elements in the first list which pass the test will be passed. See below. If you need to be sure that the resulting list contains no duplicates, use remove-dup .
—|—
Examples
Finding the intersection of two sets
This finds the intersection of the two sets and returns: ? OM->(2 4) . The following, however:
will return
? OM->(2 4 4)
since the 4 is compared twice, because it apppears twice in the first set.
Prev | Home | Next |
---|---|---|
x->dx | Up | x-union |