< Back to IRCAM Forum

Remove-dup question

Why does
(remove-dup '(1 2 3 2 2 4) '= 1) give (1 3 2 4)

and not (1 2 3 4)

What is the logic behind the order of numbers produced?

It removes from the beginning of the list, rather than from the end… I think you can modify that with some keywords inlet (should look into the doc), or a more manual approach is the reverse the list beforehand, and reverse again at the output.

Dear Peter,

Yes Jimmie’s right. Most of primitive lisp functions do the same. The reason is too long to explain . However if you need to do the inverse, ie remove from the beginning, you should use remove-duplicates which is a lisp function (so not in the menu of om, but available if you type it) and which remove-dup is based on.

so you just use the :key of this function like so:
(remove-duplicates '(1 2 3 2 2 4) :test '= :from-end 't)
OM => (1 2 3 4)

graphically its like that (to open the keys type k and choose the two options tthrough the popup menu.

Screenshot_2021-02-09_20-03-31

Best
K

Thank you both, that’s very helpful!