OpenMusic Reference
table-filter
table-filter
(lists module) -- Filters sublists from a tree using the predicate test .
Syntax
table-filter test list numcol mode
Inputs
name| data type(s)| comments
—|—|—
test | a symbol or function name or lambda function| The predicate to apply. Defaults to numberp
list | a tree| the tree to filter
numcol | a non-negative integer| the element of each sublist to pass to
test
mode | menu| two options: pass and reject
Output
output | data type(s) | comments |
---|---|---|
first | a tree |
Description
table-filter takes each sublist of the tree list and applies the function test to the element at position numcol . test may be any predicate, either a function name or a patch in lambda mode. If mode is set to reject then sublists whose numcol th element return t when passed to test are rejected. If mode is set to pass then only those sublists are kept.
![]() |
table-filter is the sister function to list-filter , which processes flat lists.
—|—
Examples
Filtering a tree
Here, the tree is tested using oddp , a predicate which returns t only when its object is an odd number. Since numcol is set to 0, oddp will be applied to the first element in each sublist. The function is in reject mode, so only sublists whose first element is not an odd number will pass. There is only one:
? OM->((4 5 6))
Reversing the mode will cause only sublists whose first element is an odd number to pass:
? OM->((1 2 3) (7 8 9))
Prev | Home | Next |
---|---|---|
sysex | Up | tan |