1

I have a problem with removing strings from a list of string I use this

(remove "lol" '("lol" "lol2" "lol")

but it returns the same list. What's the problem here?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Nabil Amen
  • 69
  • 1
  • 7

2 Answers2

2

You're running into the problem of trying to determine equality. I believe remove uses eql as its default equality tester. Unfortunately, two strings are not eql unless they're actually the same object.

Try:

`(remove "lol" '("lol" "lol2" "lol") :test #'equal)

Alternatively, if you know you will be testing strings, you could pass string= as your test function.

Vatine
  • 20,782
  • 4
  • 54
  • 70
  • @NabilAmen If works, you should consider accepting the answer. – Joshua Taylor Jun 21 '15 at 19:12
  • You are correct that the default comparison is `eql`, but you should not just believe it but look it up in the hyperspec. `Eql` is the standard default comparison across the whole language with very few exceptions, by the way. – Svante Jun 25 '15 at 07:39
  • @Svante I actually checked if remove said anything specific, but it didn't, so I went with "well, the default is `eql` and it doesn't say otherwise, but...". – Vatine Jun 25 '15 at 08:22
  • @Vatine: OK, sorry, you actually have to follow two links from the entry for `remove`, "satisfy the test" and "satisfying a two-argument test" to get to chapter 17.2.1, which specifies the general default. – Svante Jun 25 '15 at 22:43
0

You should close the ')' So write : (remove "lol" '("lol" "lol2" "lol"))

The Javatar
  • 695
  • 5
  • 15