kra361
kra361

Reputation: 11

How do I remove sublist from a list in common lisp?

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?

Upvotes: 0

Views: 416

Answers (1)

ad absurdum
ad absurdum

Reputation: 21359

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))

Upvotes: 4

Related Questions