Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6762817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:24:14+00:00 2026-05-26T14:24:14+00:00

I have a dead simple Common Lisp question: what is the idiomatic way of

  • 0

I have a dead simple Common Lisp question: what is the idiomatic way of removing duplicates from a list of strings?

remove-duplicates works as I’d expect for numbers, but not for strings:

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

(1 2 3)

* (remove-duplicates '("one" "two" "two" "three"))

("one" "two" "two" "three")

I’m guessing there’s some sense in which the strings aren’t equal, most likely because although “foo” and “foo” are apparently identical, they’re actually pointers to different structures in memory. I think my expectation here may just be a C hangover.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:24:15+00:00Added an answer on May 26, 2026 at 2:24 pm

    You have to tell remove-duplicates how it should compare the values. By default, it uses eql, which is not sufficient for strings. Pass the :test function as in:

    (remove-duplicates your-sequence :test #'equal). 
    

    (Edit to address the question from the comments): As an alternative to equal, you could use string= in this example. This predicate is (in a way) less generic than equal and it might (could, probably, possibly, eventually…) thus be faster. A real benefit might be, that string= can tell you, if you pass a wrong value:

    (equal 1 "foo")
    

    happily yields nil, whereas

    (string= 1 "foo")
    

    gives a type-error condition. Note, though, that

    (string= "FOO" :FOO)
    

    is perfectly well defined (string= and its friend are defined in terms of “string designators” not strings), so type safety would go only so far here.

    The standard eql predicate, on the other hand, is almost never the right way to compare strings. If you are familiar with the Java language, think of eql as using == while equal (or string=, etc.) calling the equals(Object) method. Though eql does some type introspection (as opposed to eq, which does not), for most (non-numeric) lisp types, eql boils down to something like a pointer comparison, which is not sufficient, if you want to discriminate values based on what they actually contain, and not merely on where in memory they are located.

    For the more Pythonic inclined, eq (and eql for non-numeric types) is more like the is operator, whereas equal is more like == which calls __eq__.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dead-simple question. How to use any SQLite library with nodejs under
Probably a dead simple and idiotic question (I'm totally new to javascript): I have
I have the following dead simple elisp functions; the first removes the fill breaks
I have a dead simple progress bar using something like the following: import sys
I want a dead simple generic $_GET-vars validator, and don't have any desire to
I have a very general question and have prepared a simple test case. When
I run an online magazine and would like a dead-simple way to track 3
Perhaps it's a syntax error, but I never assume that. I have a -dead-
How would you go about dead code detection in C/C++ code? I have a
I have a very simple query that only returns one record. When I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.