Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheme: Detecting duplicate elements in a list

Does R6RS or Chez Scheme v7.9.4 have a library function to check if a list contains duplicate elements?

Alternatively, do either have any built in functionality for sets (which dis-allow duplicate elements)? So far, I've only been able to find an example here.

The problem with that is that it doesn't appear to actually be part of the Chez Scheme library. Although I could write my own version of this, I'd much rather use a well known, tested, and maintained library function - especially given how basic an operation this is.

So a simple "use these built-in functions" or a "no built-in library implements this" will suffice. Thanks!

like image 370
Kyle Krull Avatar asked Mar 03 '10 18:03

Kyle Krull


People also ask

Can there be duplicate elements in a list?

What are duplicates in a list? If an integer or string or any items in a list are repeated more than one time, they are duplicates.

How do you find duplicates in Java?

One of the most common ways to find duplicates is by using the brute force method, which compares each element of the array to every other element. This solution has the time complexity of O(n^2) and only exists for academic purposes.


1 Answers

SRFI 1 on list processing has a delete-duplicates function (so you could use that and check the length afterward) and may well have other functions you might find useful.

like image 190
mqp Avatar answered Oct 04 '22 08:10

mqp