Remove empty list from list of list in Scheme

3.2k views Asked by At

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?

1

There are 1 answers

1
Sylwester On BEST ANSWER

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