0

I am trying to remove an element of the list removeTest that is a list itself. Below is an example.

(setq removeTest '((3.0 4.0) (5.0 6.0) (7.0 8.0)))
(remove '(5.0 6.0) removeTest))

I was directed here in my last post about it, but it doesn't really answer my question. It tells me how to ensure that the internal list is there (by using equalp to return true), but it doesn't solve the problem of removing it, due to remove and delete seemingly not working for lists of lists.

How would I remove that data element?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
kra361
  • 11
  • Does this answer your question? [Remove list from list](https://stackoverflow.com/questions/19503177/remove-list-from-list) – Vatine Nov 13 '20 at 11:20

1 Answers1

4

The default :test argument for remove is #'eql, which can not compare lists. You need to specify a test that can compare lists, e.g. #'equal:

CL-USER> (defvar *remove-test*)
*REMOVE-TEST*

CL-USER> (setf *remove-test* '((3.0 4.0) (5.0 6.0) (7.0 8.0)))
((3.0 4.0) (5.0 6.0) (7.0 8.0))

CL-USER> (remove '(5.0 6.0) *remove-test* :test #'equal)
((3.0 4.0) (7.0 8.0))
ad absurdum
  • 19,498
  • 5
  • 37
  • 60
  • Ah, I get it, that makes perfect sense. I knew there was more than one equality, but I didn't know you had to add a test for it like that. – kra361 Nov 11 '20 at 01:09
  • @kra361 -- [there are a lot of functions in Common Lisp](http://www.lispworks.com/documentation/HyperSpec/Body/17_ba.htm) that need to do some sort of comparison within a sequence; those comparisons use `#'eql` unless `:test` is used to specify another comparison function. These functions are very flexible; another keyword argument worth reading up on in this context is `:key`. – ad absurdum Nov 11 '20 at 01:42