Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove duplicated lists inside list in lisp [duplicate]

How do i remove duplicated lists inside a list in common-lisp? I tried this:

(remove-duplicates '( (1 2 3) (1 2 3)))                           

But it evaluates to ((1 2 3) (1 2 3)), not ((1 2 3)).

Thanks.

like image 374
BufBills Avatar asked Jan 22 '26 22:01

BufBills


2 Answers

Use the keyword argument :test to specify the function that defines whether or not two items are duplicates of each other. Most lisp functions, including remove-duplicates, use eql to test for equality by default. eql is much stricter than equal, which is what you probably want to be using.

 (remove-duplicates '((1 2 3) (1 2 3)) :test #'equal)

This evaluates to '((1 2 3)).

See this post for more detail about the difference between eql and equal.

like image 66
ApproachingDarknessFish Avatar answered Jan 27 '26 00:01

ApproachingDarknessFish


Try:

(remove-duplicates '((1 2 3) (1 2 3)) :test #'equal)
like image 41
uselpa Avatar answered Jan 26 '26 23:01

uselpa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!