Dears, I would like to ask you for one detail/possibility of solution: is there any possibility to “remove duplicates” from the tree list when a repetitive element is a list (that means not number)? Treelist in question: ((1 2) (1 2 3) (1 2)), repetitive element is list: (1 2), requested output without duplicates: ((1 2) (1 2 3)). Thank you, Petrh
Hi petrh.
Yes, you can use the &key argument ‘:test’, and set it to the function #'equal (default is #'eql)
-anders
Hi PErth,
You can use this:
Best
K
…in order to have what you want i suggest also to reverse your list first, since remove-dup removes the first occurrences.
best
Hi Anders, Hi Karim, thank you for your quick answers! Function Remove dup - > test: equal; yes, it runs. But with that function I miss removal direction/order from the left to the right (I should have mentioned it, I am sorry). I always need to remove the SECOND and then the next / third / fourth, etc. duplicate /occurrence. Treelist: ((A B ) (x y) (A B) (g h)), requested result: ((A B) (x y) (g h)), result with remove-dup/test: equal: ((x y) (A B) (g h)). Is there any similar simple solution as with remove-dup? I am a little afraid to work with the order of the original treelist, so I’m not sure about using REVERSE. Thank you, Petrh
As stated before, use reverse:
In code it will be:
(remove-duplicates '((a b) (x y) (a b) (g h))
:from-end t
:test 'equal)
Best
K
Hi Karim, thank you, can I ask you for basic description how function remove-dup works ? I have to be sure that the removed duplicates are really second/third/etc occurrence in the original treelist. More precisely: I have to be sure that the results are only FIRST occurence, FIRST in the order of reading original list from the left to the right.
and the last question: function LISP_remove-duplicates, the second input/pop up menu:: test ? and second:: from-end?
Thank you, Petrh
Dear petrh,
The remove-dup removes all occurrences leaving the last one. Now if you use remove-duplicates with the keyword :from-end t it is what you expect, meaning it removes all following occurrences.
Now the method uses keywords, and the order of the keywords is not important. In my example (patch above), the first keyword is :from-end which has a value of t and the second keyword which is :test has the value equal.
Hope this helps.
Best
K
Dear Karim, thank you very much for explanation. It works perfectly. Have a nice evening, Petrh