OpenMusic Reference
remove-dup
remove-dup
(lists module) -- returns list without repetitions
Syntax
remove-dup list test depth
Inputs
name | data type(s) | comments |
---|---|---|
list | a tree or a list | |
test | a symbol or lambda function | defaults to eq |
depth | a non-zero integer | defaults to 1 |
Output
output | data type(s) | comments |
---|---|---|
first | a tree or list |
Description
This module removes repetitions of elements from lists, according to test . Pairs of elements satisfying test have the first occurence of that element removed. By default, test is set to the function eq , which will remove duplicate numbers but not duplicate sublists. However, test may be any commutative function. Using equal instead of eq causes duplicate sublists to be removed as well.
depth defaults to 1. However, you may set it higher, in which case elements of sublists up to that level of nesting are compared as well.
Examples
Removing duplicate elements
Passing (toto toto is a demigod demigod) will return
? OM->(toto is a demigod)
Note also that only the last occurence of a repeated element if preserved. Thus, the list (1 2 3 1 4) will return:
? OM->(2 3 1 4)
Removing duplicate sublists
Remember, remove-dup does not remove duplicate sublists by default. If you want to do this, set test to equal instead of eq :
The duplicate sublist (9 10) will be eliminated, returning:
? OM->((1 2 3) (4 5) (6 7 8) (9 10))
Here, we increase the depth parameter to 2, meaning that the repeated elements withing sublists will be eliminated:
? OM->((1 2 3) (4 5 6))
Prev | Home | Next |
---|---|---|
remove | Up | removetemporalbox |