OpenMusic Reference
reduce-tree
reduce-tree
(arithmetic module) -- applies a commutative binary function throughout a tree
Syntax
reduce-tree self function &optional accum
Inputs
name | data type(s) | comments |
---|---|---|
self | a list | |
function | a function or patch in lambda mode | the operation to perform across self . Defaults to ‘+’ |
accum | a number | optional; the identity element for the function function |
Output
output | data type(s) | comments |
---|---|---|
first | a number | returns the result of function performed throughouut the tree |
Description
Applies a function across all the elements of a tree. A pair of elements of the tree is passed to function ; the result is paired with the next element and they are passed again to function until the tree has been totally ‘reduced.’ For example, the tree (1 8 2) passed with the function + will yield 11 since 1+8+2=11. The same list passed with * will yield 16 since 182=16.
function can be any commutative function with two inputs. The optional input is the identity element for the operation being performed. reduce-tree is smart enough to figure it out for the basic functions * , + , min , max .
![]() |
Commutative functions are functions which yield the same result regardless of the order of the inputs. Addition is a commutative function since 3+2 and 2+3 both equal 5. Subtraction is not a commutative function. Using reduce-tree with non-commutative functions will produce unpredictable results
—|—
Prev | Home | Next |
---|---|---|
range-filter | Up | remove |