Scheme: Detecting duplicate elements in a list
Asked Answered
M

2

5

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!

Mair answered 3/3, 2010 at 18:59 Comment(0)
D
4

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.

Dihydrostreptomycin answered 3/3, 2010 at 19:2 Comment(3)
Thanks - looks like this would be a useful function. Any idea when SRFI 1 will make it into Chez Scheme? It already seems to have much of what this SRFI has to offer, but I'm not seeing delete-duplicates anywhere in v7.9.4.Mair
I use PLT and I don't know anything about Chez, but many SRFIs should be available for any popular Scheme implementation; they're basically the big standard libraries for Scheme. Google found this immediately: code.launchpad.net/~scheme-libraries-team/scheme-libraries/srfi These SLS (Scheme library source) files should be loadable via Chez, perhaps like this: scheme.com/csug8/libraries.htmlDihydrostreptomycin
Thanks. It looks like this would probably work, although I haven't had a chance to download enough source to try loading it into Chez.Mair
R
3

Kyle,

Awhile back I needed to use a few SRFIs with Chez Scheme. A few that a converted for use with Chez Scheme (including SRFI-1) are at:

http://github.com/dharmatech/chez-srfi

After you add the path to 'chez-srfi' to your CHEZSCHEMELIBDIRS, you can import SRFI-1:

(import (srfi :1))

Ed

Rider answered 4/3, 2010 at 5:50 Comment(3)
This looks really useful, but I keep getting "Exception: library (srfi :1) not found" when I try the import command in the scheme interpreter. I've tried setting CHEZSCHEMELIBDIRS, running with --libdirs, and running scheme from .../chez-srfi, but it's always the same result. I'm not sure if this is related, but git didn't seem to like the files containing '*' when I cloned the repository.Mair
Yikes, sorry for not responding earlier; I haven't checked stack overflow much lately. Are you on Windows? Unfortunately those srfi libraries use a naming convention which isn't supported on Windows (crazy I know...). I'm thinking about putting out copy of that collection which uses "portable" names.Rider
No problem. I am on Windows, so you can count at least one fan if you get a chance to release the portable version of the library :)Mair

© 2022 - 2024 — McMap. All rights reserved.