Question

I have a list of list and I want to remove all the empty list from it.

My list is (("O") ("O") ()).

If I do

(remove '() '(("O") ("O") ()))

I get the right output (("O") ("O"))

but with remove* (which from the documentation remove all the occurence) I get the same input list, i.e.:

(remove* '() '(("O") ("O") ())) 

gives me back

(("O") ("O") ())

What am I doing wrong?

Was it helpful?

Solution

First off, remove* doesn't exist in Scheme (R5RS, R6RS, R7RS). remove does exist in R6RS and does what you want:

#!r6rs
(import (rnrs))
(remove '() '(() (1) (2) () ())) ;==> ((1) (2))

In the scheme dialect Racket you have both remove and remove*and it seems you are using racket since it does work in the way you are describing. remove* takes a list of items to remove. Thus (remove '() lst) in #!R6RS is the same as (remove* '(()) lst) in #!racket. remove* seems to be made to remove all of the matching elements:

(remove* '(() (2)) '(() (1) (2) () ())) ; ==> ((1))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top